Test and support hidden files and directories
This commit is contained in:
parent
31de80ac3b
commit
055e7cbe99
|
@ -4,10 +4,14 @@
|
|||
<!--<License>../Tests/ISO_Planschbecken.xml</License>-->
|
||||
</Description>
|
||||
<Track>
|
||||
<File name="Miau.txt" hidden="true">../Tests/Test.mk</File>
|
||||
<File name="Miau.txt">../Tests/Test.mk</File>
|
||||
<File name="Miau2.txt">../Tests/Test.mk</File>
|
||||
<Audiofile>../Tests/ISO_Planschbecken.xml</Audiofile>
|
||||
<Directory name="Wuff">
|
||||
<File name="Miau.txt" type="file">../Tests/ISO_Planschbecken.xml</File>
|
||||
<Directory name="Sub" hidden="true">
|
||||
<File name="SubM.txt" type="file">../Tests/ISO_Planschbecken.xml</File>
|
||||
</Directory>
|
||||
</Directory>
|
||||
</Track>
|
||||
</ISO_Project>
|
|
@ -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<DirMember>,
|
||||
pub name: String,
|
||||
pub is_hidden: bool,
|
||||
member: Vec<DirMember>,
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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<File, Error> {
|
||||
fn parse_file(file: roxmltree::Node, is_hidden: bool) -> Result<File, Error> {
|
||||
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<bool, Error> {
|
||||
|
|
|
@ -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<Directory>, 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];
|
||||
|
|
|
@ -81,17 +81,15 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
|
|||
config_reader::DirMember::Directory(dir) => {
|
||||
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);
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue