From 055e7cbe9941282d0286bf44983de30515cddef7 Mon Sep 17 00:00:00 2001 From: jaby Date: Thu, 24 Nov 2022 02:03:11 +0100 Subject: [PATCH] Test and support hidden files and directories --- src/Tools/Tests/ISO_Planschbecken.xml | 6 +++++- src/Tools/psxcdgen_ex/src/config_reader/mod.rs | 11 ++++++----- src/Tools/psxcdgen_ex/src/config_reader/xml.rs | 15 ++++++++------- src/Tools/psxcdgen_ex/src/encoder/psx.rs | 17 ++++++++++++++--- src/Tools/psxcdgen_ex/src/lib.rs | 8 +++----- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/Tools/Tests/ISO_Planschbecken.xml b/src/Tools/Tests/ISO_Planschbecken.xml index 1b80d00b..975c0552 100644 --- a/src/Tools/Tests/ISO_Planschbecken.xml +++ b/src/Tools/Tests/ISO_Planschbecken.xml @@ -4,10 +4,14 @@ - + ../Tests/Test.mk + ../Tests/Test.mk ../Tests/ISO_Planschbecken.xml ../Tests/ISO_Planschbecken.xml + \ No newline at end of file diff --git a/src/Tools/psxcdgen_ex/src/config_reader/mod.rs b/src/Tools/psxcdgen_ex/src/config_reader/mod.rs index 638487a8..2eff102a 100644 --- a/src/Tools/psxcdgen_ex/src/config_reader/mod.rs +++ b/src/Tools/psxcdgen_ex/src/config_reader/mod.rs @@ -10,7 +10,7 @@ pub struct Configuration { impl Configuration { pub fn new() -> Configuration { - Configuration{publisher: None, license_path: None, root: Directory::new("root")} + Configuration{publisher: None, license_path: None, root: Directory::new("root", false)} } } @@ -27,13 +27,14 @@ impl File { } pub struct Directory { - pub name: String, - member: Vec, + pub name: String, + pub is_hidden: bool, + member: Vec, } impl Directory { - pub fn new(name: &str) -> Directory { - Directory{name: String::from(name), member: Vec::new()} + pub fn new(name: &str, is_hidden: bool) -> Directory { + Directory{name: String::from(name), is_hidden, member: Vec::new()} } pub fn add_file(&mut self, file: File) { diff --git a/src/Tools/psxcdgen_ex/src/config_reader/xml.rs b/src/Tools/psxcdgen_ex/src/config_reader/xml.rs index 181c2ddf..cbfcea8a 100644 --- a/src/Tools/psxcdgen_ex/src/config_reader/xml.rs +++ b/src/Tools/psxcdgen_ex/src/config_reader/xml.rs @@ -44,23 +44,24 @@ fn parse_description(description: roxmltree::Node, config: &mut Configuration) { } fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(), Error> { - fn parse_file(file: roxmltree::Node) -> Result { + fn parse_file(file: roxmltree::Node, is_hidden: bool) -> Result { Ok(File{ name: String::from(file.attribute("name").unwrap_or_default()), path: PathBuf::from(file.text().unwrap_or_default()), - is_hidden: parse_boolean_attribute(&file, "hidden")? + is_hidden: is_hidden | parse_boolean_attribute(&file, "hidden")? }) } - fn parse_file_system(cur_node: roxmltree::Node, root: &mut Directory) -> Result<(), Error> { + fn parse_file_system(cur_node: roxmltree::Node, root: &mut Directory, mut is_hidden: bool) -> Result<(), Error> { for node in cur_node.children() { if node.is_element() { match node.tag_name().name() { - "File" => root.add_file(parse_file(node)?), + "File" => root.add_file(parse_file(node, is_hidden)?), "Directory" => { - let mut new_dir = Directory::new(node.attribute("name").unwrap_or_default()); + is_hidden |= parse_boolean_attribute(&node, "hidden")?; + let mut new_dir = Directory::new(node.attribute("name").unwrap_or_default(), is_hidden); - parse_file_system(node, &mut new_dir)?; + parse_file_system(node, &mut new_dir, is_hidden)?; root.add_dir(new_dir); }, _ => (), @@ -71,7 +72,7 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(), Ok(()) } - parse_file_system(track, &mut config.root) + parse_file_system(track, &mut config.root, false) } fn parse_boolean_attribute(xml: &roxmltree::Node, attribute_name: &str) -> Result { diff --git a/src/Tools/psxcdgen_ex/src/encoder/psx.rs b/src/Tools/psxcdgen_ex/src/encoder/psx.rs index 884bd89f..72ee0daa 100644 --- a/src/Tools/psxcdgen_ex/src/encoder/psx.rs +++ b/src/Tools/psxcdgen_ex/src/encoder/psx.rs @@ -47,11 +47,18 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) { }, Layout::Directory(dir) => { - let sector_count = sector_count_mode2_form1(dir.borrow().properties.borrow().get_extended_size()); - let dir = dir.borrow_mut(); + let dir = dir.borrow_mut(); + let mut properties = dir.properties.borrow_mut(); + let sector_count = sector_count_mode2_form1(properties.get_extended_size()); cd_desc.vol_sector_count += sector_count; - cur_lba = update_lba(&mut dir.properties.borrow_mut(), cur_lba, sector_count); + if properties.is_hidden { + properties.track_rel_lba = 0; + } + + else { + cur_lba = update_lba(&mut properties, cur_lba, sector_count); + } }, Layout::File(file) => { @@ -259,6 +266,10 @@ fn process_path_table(path_table: &PathTable, root_dir: SharedPtr, se } fn process_directory_record(dir: &Directory, sec_writer: &mut dyn SectorWriter) -> Result<(), Error> { + if dir.properties.borrow().is_hidden { + return Ok(()); + } + let mut dir_record = vec![0u8; dir.properties.borrow().get_real_size()]; let dir_length = dir_record.len(); let mut raw_data = &mut dir_record[0..dir_length]; diff --git a/src/Tools/psxcdgen_ex/src/lib.rs b/src/Tools/psxcdgen_ex/src/lib.rs index cf368208..c67da7c9 100644 --- a/src/Tools/psxcdgen_ex/src/lib.rs +++ b/src/Tools/psxcdgen_ex/src/lib.rs @@ -81,17 +81,15 @@ fn parse_configuration(config: config_reader::Configuration) -> Result { let mut new_dir = types::Directory::new(dir.name.as_str())?; + new_dir.properties.borrow_mut().is_hidden = dir.is_hidden; parse_dir(&mut new_dir, dir)?; dst_dir.add_dir(new_dir); }, config_reader::DirMember::File(file) => { - let desc_file = types::File::new_regular(file.name.as_str(), read_file(file.path)?)?; + let mut desc_file = types::File::new_regular(file.name.as_str(), read_file(file.path)?)?; - if file.is_hidden { - println!("Hidding not supported yet"); - } - //desc_file.properties.is_hidden = file.is_hidden; + desc_file.properties.is_hidden = file.is_hidden; dst_dir.add_file(desc_file); }, }