Print content dump intro

This commit is contained in:
jaby 2022-11-17 03:50:16 +01:00
parent 55882bc20a
commit ef54bd8db2
1 changed files with 15 additions and 4 deletions

View File

@ -18,15 +18,25 @@ pub fn process(config: config_reader::Configuration, calculate_lba: CalculateLBA
}
pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
fn write_intro(out: &mut Output) -> Result<(), Error> {
writeln!(out, "File: <File name> @<Track relative LBA> - <Size in Bytes>/<Extended size in bytes>")?;
writeln!(out, "Dir: <Directory name> @<Track relative LBA>")?;
writeln!(out, "")?;
Ok(())
}
fn dump_dir(dir: &Directory, out: &mut Output, indent: usize) -> Result<(), Error> {
const INDENT_STEP:usize = 4;
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();
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();
let file_size = file.properties.get_real_size();
let file_ex_size = file.get_extended_size();
writeln!(out, "{:indent$}File: {} @{}", " ", file_name, file_lba, indent=indent)?;
writeln!(out, "{:indent$}File: {} @{} - {}/{}", " ", file_name, file_lba, file_size, file_ex_size, indent=indent)?;
}
for dir in dir.dir_iter() {
@ -41,6 +51,7 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
Ok(())
}
format_if_error!(write_intro(&mut out), "Writing content dump intro failed with: {error_text}")?;
format_if_error!(dump_dir(&cd_desc.root.borrow(), &mut out, 0), "Creating content dump failed with: {error_text}")
}