Convert configuration to CDDesc
This commit is contained in:
parent
aa4da7bbca
commit
e5a63d5195
|
@ -1,13 +1,13 @@
|
||||||
<ISO_Project>
|
<ISO_Project>
|
||||||
<Description>
|
<Description>
|
||||||
<Publisher>Jaby Wuff</Publisher>
|
<Publisher>Jaby Wuff</Publisher>
|
||||||
<License>C:/../</License>
|
<License>../Tests/ISO_Planschbecken.xml</License>
|
||||||
</Description>
|
</Description>
|
||||||
<Track>
|
<Track>
|
||||||
<File name="Miau.png">C:/../</File>
|
<File name="Miau.png">../Tests/ISO_Planschbecken.xml</File>
|
||||||
<Audiofile>C:/../</Audiofile>
|
<Audiofile>../Tests/ISO_Planschbecken.xml</Audiofile>
|
||||||
<Directory name="Wuff">
|
<Directory name="Wuff">
|
||||||
<File name="Miau.png" type="file">C:/../</File>
|
<File name="Miau.png" type="file">../Tests/ISO_Planschbecken.xml</File>
|
||||||
</Directory>
|
</Directory>
|
||||||
</Track>
|
</Track>
|
||||||
</ISO_Project>
|
</ISO_Project>
|
|
@ -3,14 +3,14 @@ use std::path::PathBuf;
|
||||||
mod xml;
|
mod xml;
|
||||||
|
|
||||||
pub struct Configuration {
|
pub struct Configuration {
|
||||||
pub publisher: String,
|
pub publisher: Option<String>,
|
||||||
pub license_path: PathBuf,
|
pub license_path: Option<PathBuf>,
|
||||||
pub root: Directory,
|
pub root: Directory,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Configuration {
|
impl Configuration {
|
||||||
pub fn new() -> Configuration {
|
pub fn new() -> Configuration {
|
||||||
Configuration{publisher: String::new(), license_path: PathBuf::new(), root: Directory::new("root")}
|
Configuration{publisher: None, license_path: None, root: Directory::new("root")}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +42,13 @@ impl Directory {
|
||||||
pub fn add_dir(&mut self, dir: Directory) {
|
pub fn add_dir(&mut self, dir: Directory) {
|
||||||
self.member.push(DirMember::Directory(dir));
|
self.member.push(DirMember::Directory(dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_iter(self) -> std::vec::IntoIter<DirMember> {
|
||||||
|
self.member.into_iter()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DirMember {
|
pub enum DirMember {
|
||||||
File(File),
|
File(File),
|
||||||
Directory(Directory),
|
Directory(Directory),
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ fn parse_description(description: roxmltree::Node, config: &mut Configuration) {
|
||||||
for node in description.descendants() {
|
for node in description.descendants() {
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
match node.tag_name().name() {
|
match node.tag_name().name() {
|
||||||
"Publisher" => config.publisher = String::from(node.text().unwrap_or_default()),
|
"Publisher" => config.publisher = Some(String::from(node.text().unwrap_or_default())),
|
||||||
"License" => config.license_path = PathBuf::from(node.text().unwrap_or_default()),
|
"License" => config.license_path = Some(PathBuf::from(node.text().unwrap_or_default())),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,47 @@ pub use tool_helper::{Error, ErrorString};
|
||||||
pub mod config_reader;
|
pub mod config_reader;
|
||||||
pub mod encoder;
|
pub mod encoder;
|
||||||
pub mod file_writer;
|
pub mod file_writer;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
use tool_helper::read_file;
|
||||||
|
use types::CDDesc;
|
||||||
|
|
||||||
|
pub fn process(config: config_reader::Configuration) -> Result<CDDesc, Error> {
|
||||||
|
let cd_desc = parse_configuration(config)?;
|
||||||
|
|
||||||
|
Ok(cd_desc)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, Error> {
|
||||||
|
fn parse_dir(dst_dir: &mut types::Directory, src_dir: config_reader::Directory) -> Result<(), Error> {
|
||||||
|
for member in src_dir.into_iter() {
|
||||||
|
match member {
|
||||||
|
config_reader::DirMember::Directory(dir) => {
|
||||||
|
let mut new_dir = types::Directory::new(dir.name.as_str())?;
|
||||||
|
|
||||||
|
parse_dir(&mut new_dir, dir)?;
|
||||||
|
dst_dir.add_dir(new_dir);
|
||||||
|
},
|
||||||
|
|
||||||
|
config_reader::DirMember::File(file) => {
|
||||||
|
dst_dir.add_file(types::File::new_regular(file.name.as_str(), read_file(file.path)?)?);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
let cd_desc = CDDesc::new();
|
||||||
|
|
||||||
|
if let Some(publisher) = config.publisher {
|
||||||
|
cd_desc.pvd.borrow_mut().publisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(_) = config.license_path {
|
||||||
|
println!("Warning: Ignoring License path for now");
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_dir(&mut cd_desc.root.borrow_mut(), config.root)?;
|
||||||
|
Ok(cd_desc)
|
||||||
|
}
|
|
@ -59,7 +59,7 @@ fn _run_main() -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_main_xml() -> Result<(), Error> {
|
fn run_main_xml() -> Result<(), Error> {
|
||||||
let _ = config_reader::parse_xml(std::fs::read_to_string("../Tests/ISO_Planschbecken.xml")?);
|
let _cd_desc = psxcdgen_ex::process(config_reader::parse_xml(std::fs::read_to_string("../Tests/ISO_Planschbecken.xml")?)?)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,4 +134,15 @@ pub fn input_to_vec(input: Input) -> Result<Vec<u8>, Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(data)
|
Ok(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_file(file_path: PathBuf) -> Result<Vec<u8>, Error> {
|
||||||
|
match std::fs::read(&file_path) {
|
||||||
|
Ok(data) => {
|
||||||
|
Ok(data)
|
||||||
|
},
|
||||||
|
Err(error) => {
|
||||||
|
Err(Error::from_text(format!("Failed reading file {} with error: \"{}\"", file_path.display(), error)))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue