diff --git a/src/Tools/psxcdgen_ex/Cargo.toml b/src/Tools/psxcdgen_ex/Cargo.toml index 8ecceb95..8c43c0ad 100644 --- a/src/Tools/psxcdgen_ex/Cargo.toml +++ b/src/Tools/psxcdgen_ex/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "psxcdgen_ex" -version = "0.3.0" +version = "0.3.1" edition = "2021" [profile.release] diff --git a/src/Tools/psxcdgen_ex/src/lib.rs b/src/Tools/psxcdgen_ex/src/lib.rs index bb872865..708e02a8 100644 --- a/src/Tools/psxcdgen_ex/src/lib.rs +++ b/src/Tools/psxcdgen_ex/src/lib.rs @@ -30,9 +30,7 @@ pub fn process(config: config_reader::Configuration, calculate_lba: LbaCalculato Ok((cd_desc, lba_embedded_files)) } -pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFiles, length_func: LengthCalculatorFunction) -> Result { - let mut size_bytes = 0; - +pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFiles, length_func: LengthCalculatorFunction) -> Result<(), Error> { for lba_embedded_file_raw in lba_embedded_files { let new_content_info = { let mut lba_embedded_file = lba_embedded_file_raw.borrow_mut(); @@ -62,10 +60,9 @@ pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFil } } } - size_bytes += lba_embedded_file_raw.borrow().get_extended_size(); } - Ok(size_bytes) + Ok(()) } pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> { diff --git a/src/Tools/psxcdgen_ex/src/main.rs b/src/Tools/psxcdgen_ex/src/main.rs index 65d74ab0..3293166c 100644 --- a/src/Tools/psxcdgen_ex/src/main.rs +++ b/src/Tools/psxcdgen_ex/src/main.rs @@ -42,10 +42,10 @@ fn run_main(cmd_line: CommandLine) -> Result<(), Error> { let (mut desc, lba_embedded_files) = psxcdgen_ex::process(config_reader::parse_xml(read_file_to_string(&cmd_line.input_file)?)?, encoding_functions.lba_calculator)?; let file_map = desc.create_file_map(); - let content_size = psxcdgen_ex::process_files(file_map, lba_embedded_files, encoding_functions.length_calculator)?; + psxcdgen_ex::process_files(file_map, lba_embedded_files, encoding_functions.length_calculator)?; + let content_size = desc.get_content_size(); if content_size < PKG_MINIMUM_CONTENT_SIZE { let missing_size = PKG_MINIMUM_CONTENT_SIZE - content_size; - // TODO: How does this matter when we have CD tracks? desc.set_end_padding(missing_size); tool_helper::print_warning(format!("Content size {}b smaller then {}b.\nCD will be padded with {}b to work as a .pkg", content_size, PKG_MINIMUM_CONTENT_SIZE, missing_size)); } diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index 247e471c..5a911ae1 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -60,6 +60,19 @@ impl CDDesc { file_map::new_file_map(&self.root.borrow()) } + pub fn get_content_size(&self) -> usize { + let mut size = 0; + + Self::for_each_dir(&self.root, &mut |dir| { + size += dir.get_extended_size(); + for file in &dir.files { + size += file.borrow().get_extended_size(); + } + }); + + size + } + pub(super) fn for_each_dir_mut(dir: SharedPtr, function: &T) { let mut dir = dir.borrow_mut(); @@ -68,6 +81,15 @@ impl CDDesc { Self::for_each_dir_mut(sub_dir.clone(), function); } } + + fn for_each_dir(dir: &SharedPtr, function: &mut T) { + let dir = dir.borrow(); + + function(&dir); + for sub_dir in &dir.dirs { + Self::for_each_dir(&sub_dir, function); + } + } } pub struct SystemArea {