Prepare content dump

This commit is contained in:
Jaby 2022-11-17 02:52:32 +01:00
parent 7ea1803c65
commit 0c62e2e14f
3 changed files with 39 additions and 15 deletions

View File

@ -5,8 +5,8 @@ pub mod encoder;
pub mod file_writer;
pub mod types;
use tool_helper::read_file;
use types::CDDesc;
use tool_helper::{format_if_error, Output, read_file};
use types::{CDDesc, Directory};
pub type CalculateLBAFunction = fn(&mut types::CDDesc);
@ -17,6 +17,30 @@ pub fn process(config: config_reader::Configuration, calculate_lba: CalculateLBA
Ok(cd_desc)
}
pub fn dump_content(cd_desc: &CDDesc, out: Output) -> Result<(), Error> {
fn dump_dir(dir: &Directory, mut out: Output) -> Result<(), Error> {
for file in dir.file_iter() {
let file = file.borrow();
let file_name = file.name.as_string().unwrap_or("<No name>".to_owned());
let file_lba = file.get_track_rel_lba();
writeln!(out, "File: {} @{}", file_name, file_lba)?;
}
for dir in dir.dir_iter() {
let dir = dir.borrow();
let dir_name = dir.name.as_str().unwrap_or("<No name>");
let dir_lba = dir.get_track_rel_lba();
writeln!(out, "Dir: {} @{}", dir_name, dir_lba)?;
}
Ok(())
}
format_if_error!(dump_dir(&cd_desc.root.borrow(), out), "Creating content dump failed with: {error_text}")
}
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() {

View File

@ -1,5 +1,5 @@
use clap::{Parser, ValueEnum};
use psxcdgen_ex::{encoder::{EncodingFunctions, psx::{encode_psx_image, calculate_psx_lbas}}, file_writer::{ImageType, write_image}, types::{layout::Layout}, config_reader};
use psxcdgen_ex::{encoder::{EncodingFunctions, psx::{encode_psx_image, calculate_psx_lbas}}, file_writer::{ImageType, write_image}, config_reader};
use std::{path::PathBuf, };
use tool_helper::Error;
@ -35,22 +35,14 @@ impl SystemType {
fn run_main(cmd_line: CommandLine) -> Result<(), Error> {
let encoding_functions = cmd_line.system_type.get_encoding_functions();
let desc = psxcdgen_ex::process(config_reader::parse_xml(std::fs::read_to_string(cmd_line.input_file)?)?, encoding_functions.lba_calculator)?;
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 ==>");
psxcdgen_ex::dump_content(&desc, tool_helper::open_output(None)?)?;
println!("\n<== Planschbecken ==>\nStart encoding");
write_image(desc, encoding_functions.encoder, cmd_line.output_type, cmd_line.output_file)
}

View File

@ -156,6 +156,14 @@ impl Directory {
self.properties.borrow_mut().size_bytes = size_bytes;
}
pub(super) fn file_iter(&self) -> core::slice::Iter<SharedPtr<File>> {
self.files.iter()
}
pub(super) fn dir_iter(&self) -> core::slice::Iter<SharedPtr<Directory>> {
self.dirs.iter()
}
}
impl std::fmt::Display for Directory {