Fix content size issue ignoring normal files

This commit is contained in:
Jaby 2024-05-06 18:59:05 +02:00
parent 7877cb5b2d
commit 4d5a7814f7
4 changed files with 27 additions and 8 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "psxcdgen_ex" name = "psxcdgen_ex"
version = "0.3.0" version = "0.3.1"
edition = "2021" edition = "2021"
[profile.release] [profile.release]

View File

@ -30,9 +30,7 @@ pub fn process(config: config_reader::Configuration, calculate_lba: LbaCalculato
Ok((cd_desc, lba_embedded_files)) Ok((cd_desc, lba_embedded_files))
} }
pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFiles, length_func: LengthCalculatorFunction) -> Result<usize, Error> { pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFiles, length_func: LengthCalculatorFunction) -> Result<(), Error> {
let mut size_bytes = 0;
for lba_embedded_file_raw in lba_embedded_files { for lba_embedded_file_raw in lba_embedded_files {
let new_content_info = { let new_content_info = {
let mut lba_embedded_file = lba_embedded_file_raw.borrow_mut(); 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> { pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {

View File

@ -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 (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 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 { if content_size < PKG_MINIMUM_CONTENT_SIZE {
let missing_size = PKG_MINIMUM_CONTENT_SIZE - 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); 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)); 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));
} }

View File

@ -60,6 +60,19 @@ impl CDDesc {
file_map::new_file_map(&self.root.borrow()) 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<T: Fn(&mut Directory)>(dir: SharedPtr<Directory>, function: &T) { pub(super) fn for_each_dir_mut<T: Fn(&mut Directory)>(dir: SharedPtr<Directory>, function: &T) {
let mut dir = dir.borrow_mut(); let mut dir = dir.borrow_mut();
@ -68,6 +81,15 @@ impl CDDesc {
Self::for_each_dir_mut(sub_dir.clone(), function); Self::for_each_dir_mut(sub_dir.clone(), function);
} }
} }
fn for_each_dir<T: FnMut(&Directory)>(dir: &SharedPtr<Directory>, 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 { pub struct SystemArea {