Parse hidden flag in XML
This commit is contained in:
parent
1855a0686a
commit
f227ea5bec
|
@ -15,13 +15,14 @@ impl Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
|
pub is_hidden: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
pub fn new() -> File {
|
pub fn new() -> File {
|
||||||
File{name: String::new(), path: PathBuf::new()}
|
File{name: String::new(), path: PathBuf::new(), is_hidden: false}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,23 +10,25 @@ pub fn parse(xml: String) -> Result<Configuration, Error> {
|
||||||
|
|
||||||
for node in children {
|
for node in children {
|
||||||
if node.is_element() && node.tag_name().name() == "ISO_Project" {
|
if node.is_element() && node.tag_name().name() == "ISO_Project" {
|
||||||
parse_iso_project(node, &mut config);
|
parse_iso_project(node, &mut config)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_iso_project(iso_project: roxmltree::Node, config: &mut Configuration) {
|
fn parse_iso_project(iso_project: roxmltree::Node, config: &mut Configuration) -> Result<(), Error> {
|
||||||
for node in iso_project.children() {
|
for node in iso_project.children() {
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
match node.tag_name().name() {
|
match node.tag_name().name() {
|
||||||
"Description" => parse_description(node, config),
|
"Description" => parse_description(node, config),
|
||||||
"Track" => parse_track(node, config),
|
"Track" => parse_track(node, config)?,
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_description(description: roxmltree::Node, config: &mut Configuration) {
|
fn parse_description(description: roxmltree::Node, config: &mut Configuration) {
|
||||||
|
@ -41,44 +43,69 @@ fn parse_description(description: roxmltree::Node, config: &mut Configuration) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_track(track: roxmltree::Node, config: &mut Configuration) {
|
fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(), Error> {
|
||||||
fn parse_file(file: roxmltree::Node) -> File {
|
fn parse_file(file: roxmltree::Node) -> Result<File, Error> {
|
||||||
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")?
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_file_system(cur_node: roxmltree::Node, root: &mut Directory) {
|
fn parse_file_system(cur_node: roxmltree::Node, root: &mut Directory) -> 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)?),
|
||||||
"Directory" => {
|
"Directory" => {
|
||||||
let mut new_dir = Directory::new(node.attribute("name").unwrap_or_default());
|
let mut new_dir = Directory::new(node.attribute("name").unwrap_or_default());
|
||||||
|
|
||||||
parse_file_system(node, &mut new_dir);
|
parse_file_system(node, &mut new_dir)?;
|
||||||
root.add_dir(new_dir);
|
root.add_dir(new_dir);
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_file_system(track, &mut config.root);
|
parse_file_system(track, &mut config.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Error(roxmltree::Error);
|
fn parse_boolean_attribute(xml: &roxmltree::Node, attribute_name: &str) -> Result<bool, Error> {
|
||||||
|
if let Some(bool_str) = xml.attribute(attribute_name) {
|
||||||
|
match bool_str {
|
||||||
|
"true" | "1" => Ok(true),
|
||||||
|
"false" | "0" => Ok(false),
|
||||||
|
_ => {
|
||||||
|
return Err(Error::Generic(super::Error::from_text(format!("Attribute \"{}\" expects either true,false or 1,0 as valid attributes - found {}", attribute_name, bool_str))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Error {
|
||||||
|
XML(roxmltree::Error),
|
||||||
|
Generic(super::Error)
|
||||||
|
}
|
||||||
|
|
||||||
impl ErrorString for Error {
|
impl ErrorString for Error {
|
||||||
fn to_string(self) -> String {
|
fn to_string(self) -> String {
|
||||||
self.0.to_string()
|
match self {
|
||||||
|
Self::XML(xml) => xml.to_string(),
|
||||||
|
Self::Generic(generic) => generic.to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<roxmltree::Error> for Error {
|
impl std::convert::From<roxmltree::Error> for Error {
|
||||||
fn from(error: roxmltree::Error) -> Error {
|
fn from(error: roxmltree::Error) -> Error {
|
||||||
Error(error)
|
Error::XML(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -86,7 +86,13 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
|
||||||
},
|
},
|
||||||
|
|
||||||
config_reader::DirMember::File(file) => {
|
config_reader::DirMember::File(file) => {
|
||||||
dst_dir.add_file(types::File::new_regular(file.name.as_str(), read_file(file.path)?)?);
|
let 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;
|
||||||
|
dst_dir.add_file(desc_file);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue