Write via XML
This commit is contained in:
parent
e5a63d5195
commit
afd6365278
|
@ -24,7 +24,7 @@ impl CDStringValidator for AStringValidator {
|
||||||
let chr = *chr as char;
|
let chr = *chr as char;
|
||||||
|
|
||||||
if !matches!(chr, '0'..='9' | 'A'..='Z' | ' ' | '!' | '"' | '%' | '&' | '\'' | '(' | ')' | '*' | '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | '=' | '>' | '?' | '_') {
|
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(())
|
Ok(())
|
||||||
|
@ -37,7 +37,7 @@ impl CDStringValidator for DStringValidator {
|
||||||
let chr = *chr as char;
|
let chr = *chr as char;
|
||||||
|
|
||||||
if !matches!(chr, '\x00' | '\x01' | '0'..='9' | 'A'..='Z' | '_') {
|
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(())
|
Ok(())
|
||||||
|
|
|
@ -5,12 +5,14 @@ pub mod encoder;
|
||||||
pub mod file_writer;
|
pub mod file_writer;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
use encoder::psx::calculate_psx_lbas;
|
||||||
use tool_helper::read_file;
|
use tool_helper::read_file;
|
||||||
use types::CDDesc;
|
use types::CDDesc;
|
||||||
|
|
||||||
pub fn process(config: config_reader::Configuration) -> Result<CDDesc, Error> {
|
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)
|
Ok(cd_desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
|
||||||
let cd_desc = CDDesc::new();
|
let cd_desc = CDDesc::new();
|
||||||
|
|
||||||
if let Some(publisher) = config.publisher {
|
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 {
|
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 std::{path::PathBuf, str::FromStr};
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
|
||||||
fn make_file(name: &str) -> Result<File, Error> {
|
fn run_main() -> Result<(), Error> {
|
||||||
let mut name = name.to_owned();
|
let desc = psxcdgen_ex::process(config_reader::parse_xml(std::fs::read_to_string("../Tests/ISO_Planschbecken.xml")?)?)?;
|
||||||
|
|
||||||
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()?;
|
|
||||||
|
|
||||||
println!("\n<== Planschbecken ==>");
|
println!("\n<== Planschbecken ==>");
|
||||||
for element in desc.get_memory_layout().iter() {
|
for element in desc.get_memory_layout().iter() {
|
||||||
|
@ -46,7 +12,7 @@ fn _run_main() -> Result<(), Error> {
|
||||||
Layout::PVD(_) => println!("PVD:"),
|
Layout::PVD(_) => println!("PVD:"),
|
||||||
Layout::PathTables(_) => println!("PathTables:"),
|
Layout::PathTables(_) => println!("PathTables:"),
|
||||||
Layout::Directory(dir) => println!("Dir: {} @{}-{}", dir.borrow().name, dir.borrow().get_track_rel_lba(), dir.borrow().get_extended_size()),
|
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 ==>");
|
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")?)
|
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() {
|
fn main() {
|
||||||
match run_main_xml() {
|
match run_main() {
|
||||||
Ok(_) => println!("\n<== Planschbecken End ==>"),
|
Ok(_) => println!("\n<== Planschbecken End ==>"),
|
||||||
Err(error) => println!("{}", error)
|
Err(error) => println!("{}", error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,10 @@ impl PrimaryVolumeDescriptor {
|
||||||
pub fn new() -> PrimaryVolumeDescriptor {
|
pub fn new() -> PrimaryVolumeDescriptor {
|
||||||
PrimaryVolumeDescriptor{track_rel_lba: 0, publisher: String::new()}
|
PrimaryVolumeDescriptor{track_rel_lba: 0, publisher: String::new()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_publisher(&mut self, publisher: String) {
|
||||||
|
self.publisher = publisher.to_uppercase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Directory {
|
pub struct Directory {
|
||||||
|
|
Loading…
Reference in New Issue