Integrate new license type system
This commit is contained in:
parent
5ebee334fd
commit
bba6f72ff1
|
@ -1,3 +1,4 @@
|
||||||
|
use super::types::LicenseFile;
|
||||||
use super::Error;
|
use super::Error;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
mod xml;
|
mod xml;
|
||||||
|
@ -21,7 +22,7 @@ impl CDAudioFile {
|
||||||
|
|
||||||
pub struct Configuration {
|
pub struct Configuration {
|
||||||
pub publisher: Option<String>,
|
pub publisher: Option<String>,
|
||||||
pub license_path: Option<PathBuf>,
|
pub license_path: LicenseFile,
|
||||||
pub root: Directory,
|
pub root: Directory,
|
||||||
pub cd_audio_files: Vec<CDAudioFile>,
|
pub cd_audio_files: Vec<CDAudioFile>,
|
||||||
pub lead_out_sectors: Option<usize>,
|
pub lead_out_sectors: Option<usize>,
|
||||||
|
@ -29,7 +30,7 @@ pub struct Configuration {
|
||||||
|
|
||||||
impl Configuration {
|
impl Configuration {
|
||||||
pub fn new() -> Configuration {
|
pub fn new() -> Configuration {
|
||||||
Configuration{publisher: None, license_path: None, root: Directory::new("root", false), cd_audio_files: Vec::new(), lead_out_sectors: None}
|
Configuration{publisher: None, license_path: LicenseFile::None, root: Directory::new("root", false), cd_audio_files: Vec::new(), lead_out_sectors: None}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use attribute_names::LBA_SOURCE;
|
||||||
use cdtypes::types::time::Time;
|
use cdtypes::types::time::Time;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tool_helper::{format_if_error, path_with_env_from, string_with_env_from};
|
use tool_helper::{format_if_error, path_with_env_from, string_with_env_from};
|
||||||
use crate::config_reader::Directory;
|
use crate::{config_reader::Directory, types::LicenseFile};
|
||||||
|
|
||||||
use super::{CDAudioFile, CommonProperties, Configuration, Error, File, FileKind, LZ4State};
|
use super::{CDAudioFile, CommonProperties, Configuration, Error, File, FileKind, LZ4State};
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ mod tag_names {
|
||||||
pub const TRACK: &'static str = "Filesystem";
|
pub const TRACK: &'static str = "Filesystem";
|
||||||
pub const INTERLEAVED: &'static str = "InterleavedFile";
|
pub const INTERLEAVED: &'static str = "InterleavedFile";
|
||||||
pub const CDDA: &'static str = "AudioTrack";
|
pub const CDDA: &'static str = "AudioTrack";
|
||||||
|
pub const LICENSE: &'static str = "License";
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(xml: String) -> Result<Configuration, Error> {
|
pub fn parse(xml: String) -> Result<Configuration, Error> {
|
||||||
|
@ -61,18 +62,19 @@ fn parse_root(root: roxmltree::Node, config: &mut Configuration) -> Result<(), E
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_description(description: roxmltree::Node, config: &mut Configuration) -> Result<(), Error> {
|
fn parse_description(description: roxmltree::Node, config: &mut Configuration) -> Result<(), Error> {
|
||||||
const LICENSE_STR:&str = "License";
|
fn parse_license_path(license: roxmltree::Node) -> LicenseFile {
|
||||||
|
LicenseFile::from_option(path_from_node(&license, tag_names::LICENSE).ok())
|
||||||
|
}
|
||||||
|
|
||||||
for node in description.descendants() {
|
for node in description.descendants() {
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
match node.tag_name().name() {
|
match node.tag_name().name() {
|
||||||
"Publisher" => config.publisher = Some(String::from(node.text().unwrap_or_default())),
|
"Publisher" => config.publisher = Some(String::from(node.text().unwrap_or_default())),
|
||||||
LICENSE_STR => config.license_path = Some(path_from_node(&node, LICENSE_STR)?),
|
tag_names::LICENSE => config.license_path = parse_license_path(node),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,15 +238,19 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
|
||||||
return Err(Error::from_text(format!("System Area required to start at sector 0 of Track - found LBA: {}", system_area_lba)));
|
return Err(Error::from_text(format!("System Area required to start at sector 0 of Track - found LBA: {}", system_area_lba)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(license_path) = &system_area.license_file_path {
|
match &system_area.license_file_path {
|
||||||
let license_file = format_if_error!(open_input_file_buffered(license_path), "Loading license file from {} failed with: {error_text}", license_path.to_string_lossy())?;
|
LicenseFile::Authentic(license_path) => {
|
||||||
write_license_file(sec_writer, license_file)
|
let license_file = format_if_error!(open_input_file_buffered(license_path), "Loading license file from {} failed with: {error_text}", license_path.to_string_lossy())?;
|
||||||
}
|
write_license_file(sec_writer, license_file)
|
||||||
|
},
|
||||||
else {
|
LicenseFile::TMD(_) => {
|
||||||
// No license specified - filling it with zeros
|
Err(Error::from_str("Support of TMD not supported yet"))
|
||||||
print_warning("WARNING: No license file provided. Some emulators (like No$PSX) will not boot this CD.".to_owned());
|
},
|
||||||
write_dummy(sec_writer, size_of::SYSTEM_AREA_SECTOR_COUNT)
|
LicenseFile::None => {
|
||||||
|
// No license specified - filling it with zeros
|
||||||
|
print_warning("WARNING: No license file provided. Some emulators (like No$PSX) will not boot this CD.".to_owned());
|
||||||
|
write_dummy(sec_writer, size_of::SYSTEM_AREA_SECTOR_COUNT)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -256,9 +256,7 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<(CDDesc,
|
||||||
cd_desc.pvd.borrow_mut().set_publisher(publisher);
|
cd_desc.pvd.borrow_mut().set_publisher(publisher);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(license_path) = config.license_path {
|
cd_desc.system_area.borrow_mut().license_file_path = config.license_path;
|
||||||
cd_desc.system_area.borrow_mut().license_file_path = Some(license_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_dir(&mut cd_desc.root.borrow_mut(), config.root, &mut lba_embedded_files)?;
|
parse_dir(&mut cd_desc.root.borrow_mut(), config.root, &mut lba_embedded_files)?;
|
||||||
parse_cd_da(&mut cd_desc.cd_da_tracks, config.cd_audio_files)?;
|
parse_cd_da(&mut cd_desc.cd_da_tracks, config.cd_audio_files)?;
|
||||||
|
|
|
@ -105,14 +105,32 @@ impl CDDesc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum LicenseFile {
|
||||||
|
None,
|
||||||
|
Authentic(PathBuf),
|
||||||
|
TMD(PathBuf)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LicenseFile {
|
||||||
|
pub fn from_option(option: Option<PathBuf>) -> LicenseFile {
|
||||||
|
if let Some(path) = option {
|
||||||
|
LicenseFile::Authentic(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
LicenseFile::None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct SystemArea {
|
pub struct SystemArea {
|
||||||
pub(in super) lba: LBA,
|
pub(in super) lba: LBA,
|
||||||
pub(in super) license_file_path: Option<PathBuf>,
|
pub(in super) license_file_path: LicenseFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemArea {
|
impl SystemArea {
|
||||||
pub fn new() -> SystemArea {
|
pub fn new() -> SystemArea {
|
||||||
SystemArea{lba: LBA::default(), license_file_path: None}
|
SystemArea{lba: LBA::default(), license_file_path: LicenseFile::None}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue