Parse AltLicense

This commit is contained in:
Jaby 2024-08-10 16:44:03 -05:00 committed by Jaby
parent 93efd596ab
commit a25d8d05f0
5 changed files with 15 additions and 9 deletions

View File

@ -22,7 +22,7 @@ impl CDAudioFile {
pub struct Configuration { pub struct Configuration {
pub publisher: Option<String>, pub publisher: Option<String>,
pub license_path: LicenseFile, pub license_file: 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>,
@ -30,7 +30,7 @@ pub struct Configuration {
impl Configuration { impl Configuration {
pub fn new() -> Configuration { pub fn new() -> Configuration {
Configuration{publisher: None, license_path: LicenseFile::None, root: Directory::new("root", false), cd_audio_files: Vec::new(), lead_out_sectors: None} Configuration{publisher: None, license_file: LicenseFile::None, root: Directory::new("root", false), cd_audio_files: Vec::new(), lead_out_sectors: None}
} }
} }

View File

@ -20,6 +20,7 @@ mod tag_names {
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 const LICENSE: &'static str = "License";
pub const ALTLICENSE: &'static str = "AltLicense";
} }
pub fn parse(xml: String) -> Result<Configuration, Error> { pub fn parse(xml: String) -> Result<Configuration, Error> {
@ -66,11 +67,16 @@ fn parse_description(description: roxmltree::Node, config: &mut Configuration) -
LicenseFile::from_option(path_from_node(&license, tag_names::LICENSE).ok()) LicenseFile::from_option(path_from_node(&license, tag_names::LICENSE).ok())
} }
fn parse_altlicense_path(license: roxmltree::Node) -> LicenseFile {
LicenseFile::from_option(path_from_node(&license, tag_names::ALTLICENSE).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())),
tag_names::LICENSE => config.license_path = parse_license_path(node), tag_names::LICENSE => config.license_file = parse_license_path(node),
tag_names::ALTLICENSE => config.license_file = parse_altlicense_path(node),
_ => () _ => ()
} }
} }

View File

@ -238,7 +238,7 @@ 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)));
} }
match &system_area.license_file_path { match &system_area.license_file {
LicenseFile::Authentic(license_path) => { LicenseFile::Authentic(license_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())?; 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) write_license_file(sec_writer, license_file)

View File

@ -256,7 +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);
} }
cd_desc.system_area.borrow_mut().license_file_path = config.license_path; cd_desc.system_area.borrow_mut().license_file = config.license_file;
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)?;

View File

@ -125,12 +125,12 @@ impl LicenseFile {
pub struct SystemArea { pub struct SystemArea {
pub(in super) lba: LBA, pub(in super) lba: LBA,
pub(in super) license_file_path: LicenseFile, pub(in super) license_file: LicenseFile,
} }
impl SystemArea { impl SystemArea {
pub fn new() -> SystemArea { pub fn new() -> SystemArea {
SystemArea{lba: LBA::default(), license_file_path: LicenseFile::None} SystemArea{lba: LBA::default(), license_file: LicenseFile::None}
} }
} }