jabyengine/src/Tools/psxcdgen_ex/src/main.rs

66 lines
2.2 KiB
Rust

use clap::{Parser, ValueEnum};
use psxcdgen_ex::{encoder::psx::{encode_psx_image, calculate_psx_lbas}, file_writer::{ImageType, write_image}, types::{layout::Layout}, config_reader};
use std::{path::PathBuf, str::FromStr};
use tool_helper::Error;
#[derive(Parser)]
#[clap(about = "Creates an ISO image from a description file", long_about = None)]
struct CommandLine {
#[clap(value_enum, value_parser)]
system_type: SystemType,
#[clap(value_enum, value_parser, default_value_t=OutputType::BinCue)]
output_type: OutputType,
#[clap(short='o')]
output_file: PathBuf,
#[clap(value_parser)]
input_file: PathBuf,
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
enum SystemType {
Psx
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
enum OutputType {
BinCue
}
fn run_main() -> Result<(), Error> {
let desc = psxcdgen_ex::process(config_reader::parse_xml(std::fs::read_to_string("../Tests/ISO_Planschbecken.xml")?)?, calculate_psx_lbas)?;
println!("\n<== Planschbecken ==>");
for element in desc.get_memory_layout().iter() {
match element {
Layout::SystemArea(_) => println!("SystemArea:"),
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().name, file.borrow().get_track_rel_lba(), file.borrow().get_extended_size()),
}
}
println!("\n<== Planschbecken ==>");
for rand_item in desc.create_file_map() {
println!("{}", rand_item.0);
}
println!("\n<== Planschbecken ==>\nStart encoding");
write_image(desc, encode_psx_image, ImageType::BinCue, PathBuf::from_str("planschi.bin")?)
}
fn main() {
match CommandLine::try_parse() {
Ok(_) => {
match run_main() {
Ok(_) => println!("\n<== Planschbecken End ==>"),
Err(error) => println!("{}", error)
}
},
Err(error) => {
println!("{}", error);
}
}
}