Print hidden state better
This commit is contained in:
parent
055e7cbe99
commit
28c17ffa7e
|
@ -6,7 +6,7 @@ pub mod file_writer;
|
|||
pub mod types;
|
||||
|
||||
use tool_helper::{format_if_error, Output, read_file};
|
||||
use types::{CDDesc, Directory};
|
||||
use types::{CDDesc, Directory, Properties};
|
||||
|
||||
pub type CalculateLBAFunction = fn(&mut types::CDDesc);
|
||||
|
||||
|
@ -31,18 +31,43 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
|
|||
const ARROW:&'static str = "|==>";
|
||||
const INDENT_STEP:usize = 4;
|
||||
|
||||
fn write_file(out: &mut Output, indent: usize, file_name: String, file_lba: usize, file_size: usize, file_ex_size: usize) -> Result<(), Error> {
|
||||
Ok(writeln!(out, "{:>indent$}File: {:<name_align$} @{:<lba_align$} ={:<size_align$} >{:<ex_size_align$}", ARROW, file_name, file_lba, file_size, file_ex_size,
|
||||
fn get_visible_indicator(is_hidden: bool) -> char {
|
||||
if is_hidden {
|
||||
'-'
|
||||
}
|
||||
|
||||
else {
|
||||
'o'
|
||||
}
|
||||
}
|
||||
|
||||
fn write_file(out: &mut Output, indent: usize, file_name: String, properties: &Properties, file_lba: usize, file_size: usize, file_ex_size: usize) -> Result<(), Error> {
|
||||
Ok(writeln!(out, "{:>indent$}File: ({}) {:<name_align$} @{:<lba_align$} ={:<size_align$} >{:<ex_size_align$}", ARROW, get_visible_indicator(properties.is_hidden), file_name, file_lba, file_size, file_ex_size,
|
||||
indent=indent + ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name, lba_align=DEFAULT_CONTENT_ALIGNMENT.lba, size_align=DEFAULT_CONTENT_ALIGNMENT.size, ex_size_align=DEFAULT_CONTENT_ALIGNMENT.ex_size)?)
|
||||
}
|
||||
|
||||
fn write_dir(out: &mut Output, indent: usize, dir_name: &str, dir_lba: usize) -> Result<(), Error> {
|
||||
Ok(writeln!(out, "{:>indent$}Dir: {:<name_align$} @{:<lba_align$}", ARROW, dir_name, dir_lba,
|
||||
indent=indent + ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name, lba_align=DEFAULT_CONTENT_ALIGNMENT.lba)?)
|
||||
fn write_dir(out: &mut Output, indent: usize, dir_name: &str, properties: &Properties, dir_lba: usize) -> Result<(), Error> {
|
||||
macro_rules! LBA_OUT {
|
||||
() => {
|
||||
"{:<lba_align$}"
|
||||
};
|
||||
}
|
||||
let is_hidden = properties.is_hidden;
|
||||
|
||||
write!(out, "{:>indent$}Dir: ({}) {:<name_align$} @", ARROW, get_visible_indicator(is_hidden), dir_name,
|
||||
indent=indent + ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name)?;
|
||||
|
||||
if is_hidden {
|
||||
Ok(writeln!(out, LBA_OUT!(), "<None>", lba_align=DEFAULT_CONTENT_ALIGNMENT.lba)?)
|
||||
}
|
||||
|
||||
else {
|
||||
Ok(writeln!(out, LBA_OUT!(), dir_lba, lba_align=DEFAULT_CONTENT_ALIGNMENT.lba)?)
|
||||
}
|
||||
}
|
||||
|
||||
fn write_intro(out: &mut Output) -> Result<(), Error> {
|
||||
writeln!(out, "{:>indent$}Type: {:<name_align$} @{:<lba_align$} ={:<size_align$} >{:<ex_size_align$}", "", "NAME", "LBA", "SIZE", "EXTENDED SIZE",
|
||||
writeln!(out, "{:>indent$}Type: ( ) {:<name_align$} @{:<lba_align$} ={:<size_align$} >{:<ex_size_align$}", "", "NAME", "LBA", "SIZE", "EXTENDED SIZE",
|
||||
indent=ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name, lba_align=DEFAULT_CONTENT_ALIGNMENT.lba, size_align=DEFAULT_CONTENT_ALIGNMENT.size, ex_size_align=DEFAULT_CONTENT_ALIGNMENT.ex_size)?;
|
||||
Ok(writeln!(out, "")?)
|
||||
}
|
||||
|
@ -51,19 +76,21 @@ pub fn dump_content(cd_desc: &CDDesc, 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 properties = &file.properties;
|
||||
let file_lba = file.get_track_rel_lba();
|
||||
let file_size = file.properties.get_real_size();
|
||||
let file_ex_size = file.get_extended_size();
|
||||
|
||||
write_file(out, indent, file_name, file_lba, file_size, file_ex_size)?;
|
||||
write_file(out, indent, file_name, properties, file_lba, file_size, file_ex_size)?;
|
||||
}
|
||||
|
||||
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();
|
||||
let dir = dir.borrow();
|
||||
let dir_name = dir.name.as_str().unwrap_or(NO_NAME);
|
||||
let properties = dir.properties.borrow();
|
||||
let dir_lba = dir.get_track_rel_lba();
|
||||
|
||||
write_dir(out, indent, dir_name, dir_lba)?;
|
||||
write_dir(out, indent, dir_name, &properties, dir_lba)?;
|
||||
dump_dir(&dir, out, indent + INDENT_STEP)?;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue