Merge common attributes
This commit is contained in:
parent
1307ededda
commit
fd61ca2ecc
|
@ -13,8 +13,8 @@
|
|||
<File name="SubM.txt">../Tests/ISO_Planschbecken.xml</File>
|
||||
</Directory>
|
||||
</Directory>
|
||||
<Directory name="Test" header-out="LBAs.h">
|
||||
<LBA-File name="New.lba">
|
||||
<Directory name="Test">
|
||||
<LBA-File name="New.lba" header-out="LBAs.h">
|
||||
<Entry name="FirstFile">Miau.txt</Entry>
|
||||
<Entry name="SecondFile">Wuff/Miau.txt</Entry>
|
||||
</LBA-File>
|
||||
|
|
|
@ -14,11 +14,21 @@ impl Configuration {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct File {
|
||||
pub struct CommonProperties {
|
||||
pub name: String,
|
||||
pub path: PathBuf,
|
||||
pub is_hidden: bool,
|
||||
pub padded_size: Option<usize>,
|
||||
pub padded_size: Option<usize>,
|
||||
}
|
||||
|
||||
pub struct File {
|
||||
pub common: CommonProperties,
|
||||
pub path: PathBuf,
|
||||
}
|
||||
|
||||
pub struct LbaFile {
|
||||
pub common: CommonProperties,
|
||||
pub header: Option<PathBuf>,
|
||||
pub entries: Vec<String>
|
||||
}
|
||||
|
||||
pub struct Directory {
|
||||
|
|
|
@ -2,7 +2,13 @@ use std::path::PathBuf;
|
|||
use tool_helper::format_if_error;
|
||||
use crate::config_reader::Directory;
|
||||
|
||||
use super::{Configuration, Error, File};
|
||||
use super::{CommonProperties, Configuration, Error, File};
|
||||
|
||||
mod attribute_names {
|
||||
pub const NAME: &'static str = "name";
|
||||
pub const HIDDEN: &'static str = "hidden";
|
||||
pub const PADDED_SIZE: &'static str = "padded_size";
|
||||
}
|
||||
|
||||
pub fn parse(xml: String) -> Result<Configuration, Error> {
|
||||
let mut config = Configuration::new();
|
||||
|
@ -47,10 +53,8 @@ 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, 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: is_hidden | parse_boolean_attribute(&file, "hidden")?,
|
||||
padded_size: read_padded_size(&file)?,
|
||||
common: read_common_properties(&file, is_hidden)?,
|
||||
path: PathBuf::from(file.text().unwrap_or_default()),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -60,8 +64,8 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(),
|
|||
match node.tag_name().name() {
|
||||
"File" => root.add_file(parse_file(node, is_hidden)?),
|
||||
"Directory" => {
|
||||
is_hidden |= parse_boolean_attribute(&node, "hidden")?;
|
||||
let mut new_dir = Directory::new(node.attribute("name").unwrap_or_default(), is_hidden);
|
||||
is_hidden |= parse_boolean_attribute(&node, attribute_names::HIDDEN)?;
|
||||
let mut new_dir = Directory::new(node.attribute(attribute_names::NAME).unwrap_or_default(), is_hidden);
|
||||
|
||||
parse_file_system(node, &mut new_dir, is_hidden)?;
|
||||
root.add_dir(new_dir);
|
||||
|
@ -77,8 +81,16 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(),
|
|||
parse_file_system(track, &mut config.root, false)
|
||||
}
|
||||
|
||||
fn read_common_properties(xml: &roxmltree::Node, is_hidden: bool) -> Result<CommonProperties, Error> {
|
||||
Ok(CommonProperties{
|
||||
name: String::from(xml.attribute(attribute_names::NAME).unwrap_or_default()),
|
||||
is_hidden: is_hidden | parse_boolean_attribute(&xml, attribute_names::HIDDEN)?,
|
||||
padded_size: read_padded_size(&xml)?
|
||||
})
|
||||
}
|
||||
|
||||
fn read_padded_size(xml: &roxmltree::Node) -> Result<Option<usize>, Error> {
|
||||
if let Some(padded_attr) = xml.attribute("padded_size") {
|
||||
if let Some(padded_attr) = xml.attribute(attribute_names::PADDED_SIZE) {
|
||||
let padded_size = format_if_error!(padded_attr.parse::<usize>(), "Failed reading \"{}\" as padded size: {error_text}", padded_attr)?;
|
||||
Ok(Some(padded_size))
|
||||
}
|
||||
|
|
|
@ -114,10 +114,10 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
|
|||
},
|
||||
|
||||
config_reader::DirMember::File(file) => {
|
||||
let mut desc_file = types::File::new_regular(file.name.as_str(), read_file(file.path)?)?;
|
||||
let mut desc_file = types::File::new_regular(file.common.name.as_str(), read_file(file.path)?)?;
|
||||
|
||||
desc_file.properties.padded_size_bytes = file.padded_size;
|
||||
desc_file.properties.is_hidden = file.is_hidden;
|
||||
desc_file.properties.padded_size_bytes = file.common.padded_size;
|
||||
desc_file.properties.is_hidden = file.common.is_hidden;
|
||||
dst_dir.add_file(desc_file);
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue