Cause error on not a number padded_size value
This commit is contained in:
parent
2994569970
commit
d912ea949e
|
@ -10,7 +10,7 @@
|
||||||
<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">
|
<Directory name="Sub" hidden="true">
|
||||||
<File name="SubM.txt" type="file">../Tests/ISO_Planschbecken.xml</File>
|
<File name="SubM.txt" type="file" padded_size="planschi">../Tests/ISO_Planschbecken.xml</File>
|
||||||
</Directory>
|
</Directory>
|
||||||
</Directory>
|
</Directory>
|
||||||
</Track>
|
</Track>
|
||||||
|
|
|
@ -18,12 +18,7 @@ pub struct File {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub is_hidden: bool,
|
pub is_hidden: bool,
|
||||||
}
|
pub padded_size: Option<usize>,
|
||||||
|
|
||||||
impl File {
|
|
||||||
pub fn new() -> File {
|
|
||||||
File{name: String::new(), path: PathBuf::new(), is_hidden: false}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Directory {
|
pub struct Directory {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use tool_helper::format_if_error;
|
||||||
use crate::config_reader::Directory;
|
use crate::config_reader::Directory;
|
||||||
|
|
||||||
use super::{Configuration, ErrorString, File};
|
use super::{Configuration, ErrorString, File};
|
||||||
|
@ -48,7 +49,8 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(),
|
||||||
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: is_hidden | parse_boolean_attribute(&file, "hidden")?
|
is_hidden: is_hidden | parse_boolean_attribute(&file, "hidden")?,
|
||||||
|
padded_size: read_padded_size(&file)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +77,17 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(),
|
||||||
parse_file_system(track, &mut config.root, false)
|
parse_file_system(track, &mut config.root, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_padded_size(xml: &roxmltree::Node) -> Result<Option<usize>, Error> {
|
||||||
|
if let Some(padded_attr) = xml.attribute("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))
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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> {
|
||||||
if let Some(bool_str) = xml.attribute(attribute_name) {
|
if let Some(bool_str) = xml.attribute(attribute_name) {
|
||||||
match bool_str {
|
match bool_str {
|
||||||
|
@ -110,3 +123,9 @@ impl std::convert::From<roxmltree::Error> for Error {
|
||||||
Error::XML(error)
|
Error::XML(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::convert::From<super::Error> for Error {
|
||||||
|
fn from(error: super::Error) -> Error {
|
||||||
|
Error::Generic(error)
|
||||||
|
}
|
||||||
|
}
|
|
@ -286,7 +286,6 @@ fn process_directory_record(dir: &Directory, sec_writer: &mut dyn SectorWriter)
|
||||||
raw_data = &mut raw_data[bytes_written..raw_data_len];
|
raw_data = &mut raw_data[bytes_written..raw_data_len];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let dir_record_sectors = builder::create_xa_data_for_vec(None, &dir_record);
|
let dir_record_sectors = builder::create_xa_data_for_vec(None, &dir_record);
|
||||||
let dir_record_sector_count = dir_record_sectors.len();
|
let dir_record_sector_count = dir_record_sectors.len();
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,12 @@ pub type Input = Box<dyn Read>;
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! format_if_error {
|
macro_rules! format_if_error {
|
||||||
($result:expr, $format_text:literal) => {
|
($result:expr, $format_text:literal) => {
|
||||||
tool_helper::callback_if_error($result, |error_text| {
|
tool_helper::callback_if_any_error($result, |error_text| {
|
||||||
format!($format_text, error_text=error_text)
|
format!($format_text, error_text=error_text)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
($result:expr, $format_text:literal, $($arg:expr)*) => {
|
($result:expr, $format_text:literal, $($arg:expr)*) => {
|
||||||
tool_helper::callback_if_error($result, |error_text| {
|
tool_helper::callback_if_any_error($result, |error_text| {
|
||||||
format!($format_text, $($arg),*, error_text=error_text)
|
format!($format_text, $($arg),*, error_text=error_text)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
@ -139,6 +139,15 @@ pub fn callback_if_error<F: Fn(String) -> String, T>(result: Result<T, Error>, c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn callback_if_any_error<F: Fn(String) -> String, T, E: std::string::ToString>(result: Result<T, E>, callback: F) -> Result<T, Error> {
|
||||||
|
match result {
|
||||||
|
Ok(value) => Ok(value),
|
||||||
|
Err(error) => {
|
||||||
|
Err(Error::from_text(callback(error.to_string())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn open_output_file(output_path: &PathBuf) -> Result<BufWriter<std::fs::File>, Error> {
|
pub fn open_output_file(output_path: &PathBuf) -> Result<BufWriter<std::fs::File>, Error> {
|
||||||
Ok(std::io::BufWriter::new(std::fs::File::create(output_path)?))
|
Ok(std::io::BufWriter::new(std::fs::File::create(output_path)?))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue