51 lines
1.5 KiB
Rust
51 lines
1.5 KiB
Rust
pub use tool_helper::{Error, ErrorString};
|
|
|
|
pub mod config_reader;
|
|
pub mod encoder;
|
|
pub mod file_writer;
|
|
pub mod types;
|
|
|
|
use encoder::psx::calculate_psx_lbas;
|
|
use tool_helper::read_file;
|
|
use types::CDDesc;
|
|
|
|
pub fn process(config: config_reader::Configuration) -> Result<CDDesc, Error> {
|
|
let mut cd_desc = parse_configuration(config)?;
|
|
|
|
calculate_psx_lbas(&mut cd_desc);
|
|
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().set_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)
|
|
} |