Improve print of LBAs
This commit is contained in:
parent
355de5f67c
commit
79f2b436ff
|
@ -10,19 +10,21 @@ const ROOT_DIR_NAME:&'static str = "\x00";
|
|||
pub mod size_of {
|
||||
use cdtypes::types::{sector::Mode0, helper::{sector_count_mode2_form1, sector_count_mode2_form2}};
|
||||
use crate::types::FileType;
|
||||
use super::{Directory, File, FullSizeInfo, SizeInfo, PathTable};
|
||||
use super::{Directory, File, FullSizeInfo, RealSizeInfo, SizeInfo, PathTable};
|
||||
|
||||
pub const SYSTEM_AREA_SECTOR_COUNT:usize = 16;
|
||||
pub const PVD_SECTOR_COUNT:usize = 2;
|
||||
|
||||
pub const fn system_area() -> SizeInfo {
|
||||
SizeInfo{
|
||||
real_size: RealSizeInfo{bytes: None, sectors: SYSTEM_AREA_SECTOR_COUNT},
|
||||
full_size: FullSizeInfo{bytes: None, sectors: SYSTEM_AREA_SECTOR_COUNT}
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn pvd() -> SizeInfo {
|
||||
SizeInfo{
|
||||
real_size: RealSizeInfo{bytes: None, sectors: PVD_SECTOR_COUNT},
|
||||
full_size: FullSizeInfo{bytes: None, sectors: PVD_SECTOR_COUNT}
|
||||
}
|
||||
}
|
||||
|
@ -30,27 +32,33 @@ pub mod size_of {
|
|||
pub fn path_tables(root: &Directory) -> SizeInfo {
|
||||
let path_table_size = PathTable::calculate_size_for(root);
|
||||
SizeInfo{
|
||||
real_size: RealSizeInfo{bytes: Some(path_table_size), sectors: sector_count_mode2_form1(path_table_size)},
|
||||
full_size: FullSizeInfo{bytes: Some(path_table_size), sectors: sector_count_mode2_form1(path_table_size)}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn directory(dir: &Directory) -> SizeInfo {
|
||||
let real_size_bytes = dir.properties.borrow().get_real_size();
|
||||
let full_size_bytes = dir.get_extended_size();
|
||||
SizeInfo{
|
||||
real_size: RealSizeInfo{bytes: Some(real_size_bytes), sectors: sector_count_mode2_form1(real_size_bytes)},
|
||||
full_size: FullSizeInfo{bytes: Some(full_size_bytes), sectors: sector_count_mode2_form1(full_size_bytes)}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file(file: &File) -> SizeInfo {
|
||||
let real_size_bytes = file.properties.get_real_size();
|
||||
let full_size_bytes = file.get_extended_size();
|
||||
if matches!(file.content, FileType::XAAudio(_)) {
|
||||
SizeInfo{
|
||||
real_size: RealSizeInfo{bytes: Some(real_size_bytes), sectors: sector_count_mode2_form2(real_size_bytes)},
|
||||
full_size: FullSizeInfo{bytes: Some(full_size_bytes), sectors: sector_count_mode2_form2(full_size_bytes)}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
SizeInfo{
|
||||
real_size: RealSizeInfo{bytes: Some(real_size_bytes), sectors: sector_count_mode2_form1(real_size_bytes)},
|
||||
full_size: FullSizeInfo{bytes: Some(full_size_bytes), sectors: sector_count_mode2_form1(full_size_bytes)}
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +66,7 @@ pub mod size_of {
|
|||
|
||||
pub fn lead_out(sectors: usize) -> SizeInfo {
|
||||
SizeInfo{
|
||||
real_size: RealSizeInfo{bytes: Some(sectors*Mode0::DATA_SIZE), sectors},
|
||||
full_size: FullSizeInfo{bytes: Some(sectors*Mode0::DATA_SIZE), sectors}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,12 @@ pub mod cd;
|
|||
pub mod builder;
|
||||
|
||||
pub struct SizeInfo {
|
||||
pub real_size: RealSizeInfo,
|
||||
pub full_size: FullSizeInfo
|
||||
}
|
||||
|
||||
pub struct FullSizeInfo {
|
||||
pub bytes: Option<usize>,
|
||||
pub sectors: usize,
|
||||
}
|
||||
}
|
||||
pub use FullSizeInfo as RealSizeInfo;
|
|
@ -8,7 +8,7 @@ pub mod types;
|
|||
use crate::types::RawData;
|
||||
use cdtypes::types::sector::AudioSample;
|
||||
use config_reader::LZ4State;
|
||||
use encoder::cd::{calculate_lbas, calculate_length_for};
|
||||
use encoder::{cd::{self, calculate_lbas, calculate_length_for}, SizeInfo};
|
||||
use tool_helper::{format_if_error, Output, read_file};
|
||||
use types::{layout::Layout, CDDesc, Directory, File, FileType, FileSystemMap, Properties, SharedPtr};
|
||||
use std::path::PathBuf;
|
||||
|
@ -22,7 +22,7 @@ struct ContentDumpAlignment {
|
|||
ex_size: usize,
|
||||
}
|
||||
|
||||
const DEFAULT_CONTENT_ALIGNMENT:ContentDumpAlignment = ContentDumpAlignment{name: 24, lba_pair: 16, size: 8, ex_size: 8};
|
||||
const DEFAULT_CONTENT_ALIGNMENT:ContentDumpAlignment = ContentDumpAlignment{name: 24, lba_pair: 16, size: 16, ex_size: 16};
|
||||
|
||||
pub fn process(config: config_reader::Configuration) -> Result<(CDDesc, LBAEmbeddedFiles), Error> {
|
||||
let (mut cd_desc, lba_embedded_files) = parse_configuration(config)?;
|
||||
|
@ -81,12 +81,12 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
|
|||
}
|
||||
}
|
||||
|
||||
fn create_lba_display_string<T: std::fmt::Display>(rel_lba: T, abs_lba: T) -> String {
|
||||
fn create_pair_display_string<T: std::fmt::Display>(rel_lba: T, abs_lba: T) -> String {
|
||||
format!("{}({})", rel_lba, abs_lba)
|
||||
}
|
||||
|
||||
fn write_file(out: &mut Output, indent: usize, file_name: String, properties: &Properties, file_rel_lba: usize, file_abs_lba: usize, file_size: usize, file_ex_size: usize) -> Result<(), Error> {
|
||||
Ok(writeln!(out, "{:>indent$}File: ({}) {:<name_align$} @{:<lba_pair_align$} ={:<size_align$} >{:<ex_size_align$}", ARROW, get_visible_indicator(properties.is_hidden), file_name, create_lba_display_string(file_rel_lba, file_abs_lba), file_size, file_ex_size,
|
||||
fn write_file(out: &mut Output, indent: usize, file_name: String, properties: &Properties, file_rel_lba: usize, file_abs_lba: usize, file_size: SizeInfo) -> Result<(), Error> {
|
||||
Ok(writeln!(out, "{:>indent$}File: ({}) {:<name_align$} @{:<lba_pair_align$} ={:<size_align$} >{:<ex_size_align$}", ARROW, get_visible_indicator(properties.is_hidden), file_name, create_pair_display_string(file_rel_lba, file_abs_lba), create_pair_display_string(file_size.real_size.sectors, file_size.real_size.bytes.unwrap()), create_pair_display_string(file_size.full_size.sectors, file_size.full_size.bytes.unwrap()),
|
||||
indent=indent + ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name, lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair, size_align=DEFAULT_CONTENT_ALIGNMENT.size, ex_size_align=DEFAULT_CONTENT_ALIGNMENT.ex_size)?)
|
||||
}
|
||||
|
||||
|
@ -102,16 +102,16 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
|
|||
indent=indent + ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name)?;
|
||||
|
||||
if is_hidden {
|
||||
Ok(writeln!(out, LBA_OUT!(), create_lba_display_string("<None>", "<None>"), lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair)?)
|
||||
Ok(writeln!(out, LBA_OUT!(), create_pair_display_string("<None>", "<None>"), lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair)?)
|
||||
}
|
||||
|
||||
else {
|
||||
Ok(writeln!(out, LBA_OUT!(), create_lba_display_string(dir_rel_lba, dir_abs_lba), lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair)?)
|
||||
Ok(writeln!(out, LBA_OUT!(), create_pair_display_string(dir_rel_lba, dir_abs_lba), lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair)?)
|
||||
}
|
||||
}
|
||||
|
||||
fn write_intro(out: &mut Output) -> Result<(), Error> {
|
||||
writeln!(out, "{:>indent$}Type: ( ) {:<name_align$} @{:<lba_pair_align$} ={:<size_align$} >{:<ex_size_align$}", "", "NAME", create_lba_display_string("LBA", "abs LBA"), "SIZE", "EXTENDED SIZE",
|
||||
writeln!(out, "{:>indent$}Type: ( ) {:<name_align$} @{:<lba_pair_align$} ={:<size_align$} >{:<ex_size_align$}", "", "Name", create_pair_display_string("LBA", "abs LBA"), "Sectors(bytes)", "Padded sectors(padded bytes)",
|
||||
indent=ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name, lba_pair_align=DEFAULT_CONTENT_ALIGNMENT.lba_pair, size_align=DEFAULT_CONTENT_ALIGNMENT.size, ex_size_align=DEFAULT_CONTENT_ALIGNMENT.ex_size)?;
|
||||
Ok(writeln!(out, "")?)
|
||||
}
|
||||
|
@ -123,10 +123,9 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
|
|||
let properties = &file.properties;
|
||||
let file_rel_lba = file.get_track_rel_lba();
|
||||
let file_abs_lba = file.get_absolute_lba();
|
||||
let file_size = file.properties.get_real_size();
|
||||
let file_ex_size = file.get_extended_size();
|
||||
|
||||
write_file(out, indent, file_name, properties, file_rel_lba, file_abs_lba, file_size, file_ex_size)?;
|
||||
let file_size = cd::size_of::file(&file);
|
||||
|
||||
write_file(out, indent, file_name, properties, file_rel_lba, file_abs_lba, file_size)?;
|
||||
}
|
||||
|
||||
for dir in dir.dir_iter() {
|
||||
|
|
Loading…
Reference in New Issue