Improve print of LBAs

This commit is contained in:
jaby 2024-07-21 21:32:29 +02:00
parent 355de5f67c
commit 79f2b436ff
3 changed files with 24 additions and 14 deletions

View File

@ -10,19 +10,21 @@ const ROOT_DIR_NAME:&'static str = "\x00";
pub mod size_of { pub mod size_of {
use cdtypes::types::{sector::Mode0, helper::{sector_count_mode2_form1, sector_count_mode2_form2}}; use cdtypes::types::{sector::Mode0, helper::{sector_count_mode2_form1, sector_count_mode2_form2}};
use crate::types::FileType; 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 SYSTEM_AREA_SECTOR_COUNT:usize = 16;
pub const PVD_SECTOR_COUNT:usize = 2; pub const PVD_SECTOR_COUNT:usize = 2;
pub const fn system_area() -> SizeInfo { pub const fn system_area() -> SizeInfo {
SizeInfo{ SizeInfo{
real_size: RealSizeInfo{bytes: None, sectors: SYSTEM_AREA_SECTOR_COUNT},
full_size: FullSizeInfo{bytes: None, sectors: SYSTEM_AREA_SECTOR_COUNT} full_size: FullSizeInfo{bytes: None, sectors: SYSTEM_AREA_SECTOR_COUNT}
} }
} }
pub const fn pvd() -> SizeInfo { pub const fn pvd() -> SizeInfo {
SizeInfo{ SizeInfo{
real_size: RealSizeInfo{bytes: None, sectors: PVD_SECTOR_COUNT},
full_size: FullSizeInfo{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 { pub fn path_tables(root: &Directory) -> SizeInfo {
let path_table_size = PathTable::calculate_size_for(root); let path_table_size = PathTable::calculate_size_for(root);
SizeInfo{ 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)} full_size: FullSizeInfo{bytes: Some(path_table_size), sectors: sector_count_mode2_form1(path_table_size)}
} }
} }
pub fn directory(dir: &Directory) -> SizeInfo { pub fn directory(dir: &Directory) -> SizeInfo {
let real_size_bytes = dir.properties.borrow().get_real_size();
let full_size_bytes = dir.get_extended_size(); let full_size_bytes = dir.get_extended_size();
SizeInfo{ 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)} full_size: FullSizeInfo{bytes: Some(full_size_bytes), sectors: sector_count_mode2_form1(full_size_bytes)}
} }
} }
pub fn file(file: &File) -> SizeInfo { pub fn file(file: &File) -> SizeInfo {
let real_size_bytes = file.properties.get_real_size();
let full_size_bytes = file.get_extended_size(); let full_size_bytes = file.get_extended_size();
if matches!(file.content, FileType::XAAudio(_)) { if matches!(file.content, FileType::XAAudio(_)) {
SizeInfo{ 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)} full_size: FullSizeInfo{bytes: Some(full_size_bytes), sectors: sector_count_mode2_form2(full_size_bytes)}
} }
} }
else { else {
SizeInfo{ 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)} 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 { pub fn lead_out(sectors: usize) -> SizeInfo {
SizeInfo{ SizeInfo{
real_size: RealSizeInfo{bytes: Some(sectors*Mode0::DATA_SIZE), sectors},
full_size: FullSizeInfo{bytes: Some(sectors*Mode0::DATA_SIZE), sectors} full_size: FullSizeInfo{bytes: Some(sectors*Mode0::DATA_SIZE), sectors}
} }
} }

View File

@ -4,10 +4,12 @@ pub mod cd;
pub mod builder; pub mod builder;
pub struct SizeInfo { pub struct SizeInfo {
pub real_size: RealSizeInfo,
pub full_size: FullSizeInfo pub full_size: FullSizeInfo
} }
pub struct FullSizeInfo { pub struct FullSizeInfo {
pub bytes: Option<usize>, pub bytes: Option<usize>,
pub sectors: usize, pub sectors: usize,
} }
pub use FullSizeInfo as RealSizeInfo;

View File

@ -8,7 +8,7 @@ pub mod types;
use crate::types::RawData; use crate::types::RawData;
use cdtypes::types::sector::AudioSample; use cdtypes::types::sector::AudioSample;
use config_reader::LZ4State; 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 tool_helper::{format_if_error, Output, read_file};
use types::{layout::Layout, CDDesc, Directory, File, FileType, FileSystemMap, Properties, SharedPtr}; use types::{layout::Layout, CDDesc, Directory, File, FileType, FileSystemMap, Properties, SharedPtr};
use std::path::PathBuf; use std::path::PathBuf;
@ -22,7 +22,7 @@ struct ContentDumpAlignment {
ex_size: usize, 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> { pub fn process(config: config_reader::Configuration) -> Result<(CDDesc, LBAEmbeddedFiles), Error> {
let (mut cd_desc, lba_embedded_files) = parse_configuration(config)?; 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) 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> { 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_lba_display_string(file_rel_lba, file_abs_lba), file_size, file_ex_size, 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)?) 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)?; indent=indent + ARROW.len(), name_align=DEFAULT_CONTENT_ALIGNMENT.name)?;
if is_hidden { 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 { 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> { 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)?; 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, "")?) Ok(writeln!(out, "")?)
} }
@ -123,10 +123,9 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
let properties = &file.properties; let properties = &file.properties;
let file_rel_lba = file.get_track_rel_lba(); let file_rel_lba = file.get_track_rel_lba();
let file_abs_lba = file.get_absolute_lba(); let file_abs_lba = file.get_absolute_lba();
let file_size = file.properties.get_real_size(); let file_size = cd::size_of::file(&file);
let file_ex_size = file.get_extended_size();
write_file(out, indent, file_name, properties, file_rel_lba, file_abs_lba, file_size)?;
write_file(out, indent, file_name, properties, file_rel_lba, file_abs_lba, file_size, file_ex_size)?;
} }
for dir in dir.dir_iter() { for dir in dir.dir_iter() {