From 02e4c70dfca13f5cb1a7d728874896c9ec0f17d7 Mon Sep 17 00:00:00 2001 From: Jaby Date: Fri, 27 Jan 2023 08:10:05 +0100 Subject: [PATCH] Add 'Main' file type to support lba for them --- .../psxcdgen_ex/src/config_reader/mod.rs | 2 +- .../psxcdgen_ex/src/config_reader/xml.rs | 27 +++++++++++-------- src/Tools/psxcdgen_ex/src/encoder/psx.rs | 8 +++--- src/Tools/psxcdgen_ex/src/lib.rs | 10 +++---- src/Tools/psxcdgen_ex/src/types/mod.rs | 6 ++--- .../psxcdgen_ex/src/types/overlay/mod.rs | 4 +-- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/Tools/psxcdgen_ex/src/config_reader/mod.rs b/src/Tools/psxcdgen_ex/src/config_reader/mod.rs index 91e8971c..e497e2a7 100644 --- a/src/Tools/psxcdgen_ex/src/config_reader/mod.rs +++ b/src/Tools/psxcdgen_ex/src/config_reader/mod.rs @@ -22,7 +22,7 @@ pub struct CommonProperties { pub enum FileKind { Regular, - RegularLBA(PathBuf), + Main(PathBuf), Overlay(PathBuf) } diff --git a/src/Tools/psxcdgen_ex/src/config_reader/xml.rs b/src/Tools/psxcdgen_ex/src/config_reader/xml.rs index 27c59b9e..2646efdf 100644 --- a/src/Tools/psxcdgen_ex/src/config_reader/xml.rs +++ b/src/Tools/psxcdgen_ex/src/config_reader/xml.rs @@ -53,23 +53,27 @@ fn parse_description(description: roxmltree::Node, config: &mut Configuration) { fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(), Error> { fn parse_regular_file(file: roxmltree::Node, is_hidden: bool) -> Result { - let kind = { - if let Some(path) = file.attribute(attribute_names::LBA_SOURCE) { - FileKind::RegularLBA(PathBuf::from(path)) - } - - else { - FileKind::Regular - } - }; - Ok(File{ common: read_common_properties(&file, is_hidden)?, path: PathBuf::from(file.text().unwrap_or_default()), - kind + kind: FileKind::Regular }) } + fn parse_main_file(file: roxmltree::Node, is_hidden: bool) -> Result { + if let Some(lba_path) = file.attribute(attribute_names::LBA_SOURCE) { + Ok(File{ + common: read_common_properties(&file, is_hidden)?, + path: PathBuf::from(file.text().unwrap_or_default()), + kind: FileKind::Main(PathBuf::from(lba_path)) + }) + } + + else { + parse_regular_file(file, is_hidden) + } + } + fn parse_overlay_file(file: roxmltree::Node, is_hidden: bool) -> Result { Ok(File{ common: read_common_properties(&file, is_hidden)?, @@ -83,6 +87,7 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(), if node.is_element() { match node.tag_name().name() { "File" => root.add_file(parse_regular_file(node, is_hidden)?), + "Main" => root.add_file(parse_main_file(node, is_hidden)?), "Overlay" => root.add_file(parse_overlay_file(node, is_hidden)?), "Directory" => { is_hidden |= parse_boolean_attribute(&node, attribute_names::HIDDEN)?; diff --git a/src/Tools/psxcdgen_ex/src/encoder/psx.rs b/src/Tools/psxcdgen_ex/src/encoder/psx.rs index abb824ce..a5302642 100644 --- a/src/Tools/psxcdgen_ex/src/encoder/psx.rs +++ b/src/Tools/psxcdgen_ex/src/encoder/psx.rs @@ -328,11 +328,11 @@ fn process_file(file: &File, sec_writer: &mut dyn SectorWriter) -> Result<(), Er let content_sectors = { match &file.content { - FileType::Regular(raw) => builder::create_xa_data_for_vec(None, raw), - FileType::RegularOverlay(_, _) => { - return Err(Error::from_str("Trying to encode an unprocssed regular overlay file")); + FileType::Regular(raw) => builder::create_xa_data_for_vec(None, raw), + FileType::Main(_, _) => { + return Err(Error::from_str("Trying to encode an unprocssed main file")); }, - FileType::Overlay(_, _) => { + FileType::Overlay(_, _) => { return Err(Error::from_str("Trying to encode an unprocessed overlay file")); }, } diff --git a/src/Tools/psxcdgen_ex/src/lib.rs b/src/Tools/psxcdgen_ex/src/lib.rs index 04492596..68205d2d 100644 --- a/src/Tools/psxcdgen_ex/src/lib.rs +++ b/src/Tools/psxcdgen_ex/src/lib.rs @@ -38,8 +38,8 @@ pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFil Some(new_content) }, - FileType::RegularOverlay(_, _) => { - return Err(Error::not_implemented("process_files => RegularOverlay")); + FileType::Main(_, _) => { + return Err(Error::not_implemented("process_files => FileType::Main")); }, _ => None } @@ -158,9 +158,9 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<(CDDesc, config_reader::DirMember::File(file) => { let (mut desc_file, needs_treatment) = { match file.kind { - config_reader::FileKind::Regular => (types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?, false), - config_reader::FileKind::RegularLBA(lba_source) => (types::overlay::dino_wuff(file.common.name.as_str(), read_file(&file.path)?, lba_source)?, true), - config_reader::FileKind::Overlay(lba_source) => (types::overlay::load_from(file.common.name.as_str(), file.path, lba_source)?, true), + config_reader::FileKind::Regular => (types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?, false), + config_reader::FileKind::Main(lba_source) => (types::overlay::load_for_main(file.common.name.as_str(), read_file(&file.path)?, lba_source)?, true), + config_reader::FileKind::Overlay(lba_source) => (types::overlay::load_from(file.common.name.as_str(), file.path, lba_source)?, true), } }; diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index 8f2b702e..f9552a63 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -177,7 +177,7 @@ impl std::fmt::Display for Directory { pub(super) enum FileType { Regular(Vec), - RegularOverlay(Vec, overlay::LBANameVec), + Main(Vec, overlay::LBANameVec), Overlay(Vec, overlay::LBANameVec), } @@ -195,10 +195,10 @@ impl File { Self::new_from_content(file_name, FileType::Regular(content), content_size) } - pub fn new_regular_overlay(file_name: &str, content: Vec, lba_names: overlay::LBANameVec) -> Result { + pub fn new_main(file_name: &str, content: Vec, lba_names: overlay::LBANameVec) -> Result { let content_size = content.len(); - Self::new_from_content(file_name, FileType::RegularOverlay(content, lba_names), content_size) + Self::new_from_content(file_name, FileType::Main(content, lba_names), content_size) } pub fn new_overlay(file_name: &str, content: Vec, lba_names: overlay::LBANameVec, content_size: usize) -> Result { diff --git a/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs b/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs index c59cbe0f..a1e8cddf 100644 --- a/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs @@ -52,8 +52,8 @@ pub fn load_from(file_name: &str, file_path: PathBuf, lba_source: PathBuf) -> Re Ok(File::new_overlay(file_name, content, lba_names, content_size)?) } -pub fn dino_wuff(file_name: &str, content: Vec, lba_source: PathBuf) -> Result { - File::new_regular_overlay(file_name, content, load_lba_names(lba_source)?) +pub fn load_for_main(file_name: &str, content: Vec, lba_source: PathBuf) -> Result { + File::new_main(file_name, content, load_lba_names(lba_source)?) } pub fn update_content(content: &mut Vec, lba_names: &LBANameVec, file_map: &FileSystemMap, length_func: LengthCalculatorFunction) -> Result, Error> {