Write via XML
This commit is contained in:
parent
1b0fc42e84
commit
2e111ef6d0
|
@ -24,7 +24,7 @@ impl CDStringValidator for AStringValidator {
|
|||
let chr = *chr as char;
|
||||
|
||||
if !matches!(chr, '0'..='9' | 'A'..='Z' | ' ' | '!' | '"' | '%' | '&' | '\'' | '(' | ')' | '*' | '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | '=' | '>' | '?' | '_') {
|
||||
return Err(Error::GenericError(format!("{} not a valid a-character", chr)));
|
||||
return Err(Error::GenericError(format!("Error parsing \"{}\": '{}' not a valid a-character", String::from_utf8_lossy(value), chr)));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -37,7 +37,7 @@ impl CDStringValidator for DStringValidator {
|
|||
let chr = *chr as char;
|
||||
|
||||
if !matches!(chr, '\x00' | '\x01' | '0'..='9' | 'A'..='Z' | '_') {
|
||||
return Err(Error::GenericError(format!("{} not a valid d-character", chr)));
|
||||
return Err(Error::GenericError(format!("Error parsing \"{}\": '{}' not a valid d-character", String::from_utf8_lossy(value), chr)));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -5,12 +5,14 @@ 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 cd_desc = parse_configuration(config)?;
|
||||
let mut cd_desc = parse_configuration(config)?;
|
||||
|
||||
calculate_psx_lbas(&mut cd_desc);
|
||||
Ok(cd_desc)
|
||||
}
|
||||
|
||||
|
@ -37,7 +39,7 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
|
|||
let cd_desc = CDDesc::new();
|
||||
|
||||
if let Some(publisher) = config.publisher {
|
||||
cd_desc.pvd.borrow_mut().publisher = publisher;
|
||||
cd_desc.pvd.borrow_mut().set_publisher(publisher);
|
||||
}
|
||||
|
||||
if let Some(_) = config.license_path {
|
||||
|
|
|
@ -1,43 +1,9 @@
|
|||
use psxcdgen_ex::{encoder::psx::{calculate_psx_lbas, encode_psx_image}, file_writer::{ImageType, write_image}, types::{layout::Layout, CDDesc, File, Directory}, config_reader};
|
||||
use psxcdgen_ex::{encoder::psx::encode_psx_image, file_writer::{ImageType, write_image}, types::{layout::Layout}, config_reader};
|
||||
use std::{path::PathBuf, str::FromStr};
|
||||
use tool_helper::Error;
|
||||
|
||||
fn make_file(name: &str) -> Result<File, Error> {
|
||||
let mut name = name.to_owned();
|
||||
|
||||
name.push_str(".txt");
|
||||
File::new_regular(name.as_ref(), "Planschbecken sind planschig und so".to_owned().into_bytes())
|
||||
}
|
||||
|
||||
fn populate() -> Result<CDDesc, Error> {
|
||||
let mut desc = CDDesc::new();
|
||||
let file = make_file("Planschi")?;
|
||||
let file2 = make_file("Wuff")?;
|
||||
let folder = {
|
||||
let mut folder = Directory::new("Sub")?;
|
||||
let sub_folder = {
|
||||
let mut folder = Directory::new("SubSub")?;
|
||||
|
||||
folder.add_file(make_file("Blubb")?);
|
||||
folder
|
||||
};
|
||||
|
||||
folder.add_dir(sub_folder);
|
||||
folder.add_file(make_file("Schwimm")?);
|
||||
folder.add_file(make_file("Miau")?);
|
||||
folder
|
||||
};
|
||||
|
||||
desc.add_dir(folder);
|
||||
desc.add_file(file);
|
||||
desc.add_file(file2);
|
||||
|
||||
calculate_psx_lbas(&mut desc);
|
||||
Ok(desc)
|
||||
}
|
||||
|
||||
fn _run_main() -> Result<(), Error> {
|
||||
let desc = populate()?;
|
||||
fn run_main() -> Result<(), Error> {
|
||||
let desc = psxcdgen_ex::process(config_reader::parse_xml(std::fs::read_to_string("../Tests/ISO_Planschbecken.xml")?)?)?;
|
||||
|
||||
println!("\n<== Planschbecken ==>");
|
||||
for element in desc.get_memory_layout().iter() {
|
||||
|
@ -46,7 +12,7 @@ fn _run_main() -> Result<(), Error> {
|
|||
Layout::PVD(_) => println!("PVD:"),
|
||||
Layout::PathTables(_) => println!("PathTables:"),
|
||||
Layout::Directory(dir) => println!("Dir: {} @{}-{}", dir.borrow().name, dir.borrow().get_track_rel_lba(), dir.borrow().get_extended_size()),
|
||||
Layout::File(file) => println!("File: {} @{}-{}", file.borrow(), file.borrow().get_track_rel_lba(), file.borrow().get_extended_size()),
|
||||
Layout::File(file) => println!("File: {} @{}-{}", file.borrow().name, file.borrow().get_track_rel_lba(), file.borrow().get_extended_size()),
|
||||
}
|
||||
}
|
||||
println!("\n<== Planschbecken ==>");
|
||||
|
@ -58,14 +24,8 @@ fn _run_main() -> Result<(), Error> {
|
|||
write_image(desc, encode_psx_image, ImageType::BinCue, PathBuf::from_str("planschi.bin")?)
|
||||
}
|
||||
|
||||
fn run_main_xml() -> Result<(), Error> {
|
||||
let _cd_desc = psxcdgen_ex::process(config_reader::parse_xml(std::fs::read_to_string("../Tests/ISO_Planschbecken.xml")?)?)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match run_main_xml() {
|
||||
match run_main() {
|
||||
Ok(_) => println!("\n<== Planschbecken End ==>"),
|
||||
Err(error) => println!("{}", error)
|
||||
}
|
||||
|
|
|
@ -105,6 +105,10 @@ impl PrimaryVolumeDescriptor {
|
|||
pub fn new() -> PrimaryVolumeDescriptor {
|
||||
PrimaryVolumeDescriptor{track_rel_lba: 0, publisher: String::new()}
|
||||
}
|
||||
|
||||
pub fn set_publisher(&mut self, publisher: String) {
|
||||
self.publisher = publisher.to_uppercase();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Directory {
|
||||
|
|
Loading…
Reference in New Issue