Test and support hidden files and directories
This commit is contained in:
parent
39a315a674
commit
c88549bf9b
|
@ -4,10 +4,14 @@
|
||||||
<!--<License>../Tests/ISO_Planschbecken.xml</License>-->
|
<!--<License>../Tests/ISO_Planschbecken.xml</License>-->
|
||||||
</Description>
|
</Description>
|
||||||
<Track>
|
<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>
|
<Audiofile>../Tests/ISO_Planschbecken.xml</Audiofile>
|
||||||
<Directory name="Wuff">
|
<Directory name="Wuff">
|
||||||
<File name="Miau.txt" type="file">../Tests/ISO_Planschbecken.xml</File>
|
<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>
|
</Directory>
|
||||||
</Track>
|
</Track>
|
||||||
</ISO_Project>
|
</ISO_Project>
|
|
@ -10,7 +10,7 @@ pub struct Configuration {
|
||||||
|
|
||||||
impl Configuration {
|
impl Configuration {
|
||||||
pub fn new() -> 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)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,12 +28,13 @@ impl File {
|
||||||
|
|
||||||
pub struct Directory {
|
pub struct Directory {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub is_hidden: bool,
|
||||||
member: Vec<DirMember>,
|
member: Vec<DirMember>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Directory {
|
impl Directory {
|
||||||
pub fn new(name: &str) -> Directory {
|
pub fn new(name: &str, is_hidden: bool) -> Directory {
|
||||||
Directory{name: String::from(name), member: Vec::new()}
|
Directory{name: String::from(name), is_hidden, member: Vec::new()}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_file(&mut self, file: File) {
|
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_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{
|
Ok(File{
|
||||||
name: String::from(file.attribute("name").unwrap_or_default()),
|
name: String::from(file.attribute("name").unwrap_or_default()),
|
||||||
path: PathBuf::from(file.text().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() {
|
for node in cur_node.children() {
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
match node.tag_name().name() {
|
match node.tag_name().name() {
|
||||||
"File" => root.add_file(parse_file(node)?),
|
"File" => root.add_file(parse_file(node, is_hidden)?),
|
||||||
"Directory" => {
|
"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);
|
root.add_dir(new_dir);
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
|
@ -71,7 +72,7 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(),
|
||||||
Ok(())
|
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> {
|
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) => {
|
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;
|
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) => {
|
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> {
|
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 mut dir_record = vec![0u8; dir.properties.borrow().get_real_size()];
|
||||||
let dir_length = dir_record.len();
|
let dir_length = dir_record.len();
|
||||||
let mut raw_data = &mut dir_record[0..dir_length];
|
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) => {
|
config_reader::DirMember::Directory(dir) => {
|
||||||
let mut new_dir = types::Directory::new(dir.name.as_str())?;
|
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)?;
|
parse_dir(&mut new_dir, dir)?;
|
||||||
dst_dir.add_dir(new_dir);
|
dst_dir.add_dir(new_dir);
|
||||||
},
|
},
|
||||||
|
|
||||||
config_reader::DirMember::File(file) => {
|
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 {
|
desc_file.properties.is_hidden = file.is_hidden;
|
||||||
println!("Hidding not supported yet");
|
|
||||||
}
|
|
||||||
//desc_file.properties.is_hidden = file.is_hidden;
|
|
||||||
dst_dir.add_file(desc_file);
|
dst_dir.add_file(desc_file);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue