Improve FileLength struct
This commit is contained in:
parent
4d25c39b74
commit
57f646f5e0
|
@ -10,49 +10,60 @@ const ROOT_DIR_NAME:&'static str = "\x00";
|
|||
pub mod length_of {
|
||||
use cdtypes::types::{sector::Mode0, helper::{sector_count_mode2_form1, sector_count_mode2_form2}};
|
||||
use crate::types::FileType;
|
||||
use super::{Directory, File, LengthInfo, PathTable};
|
||||
use super::{Directory, File, FullSizeInfo, SizeInfo, PathTable};
|
||||
|
||||
pub const SYSTEM_AREA_SECTOR_COUNT:usize = 16;
|
||||
pub const PVD_SECTOR_COUNT:usize = 2;
|
||||
|
||||
pub const fn system_area() -> LengthInfo {
|
||||
LengthInfo{bytes: None, sectors: SYSTEM_AREA_SECTOR_COUNT}
|
||||
pub const fn system_area() -> SizeInfo {
|
||||
SizeInfo{
|
||||
full_size: FullSizeInfo{bytes: None, sectors: SYSTEM_AREA_SECTOR_COUNT}
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn pvd() -> LengthInfo {
|
||||
LengthInfo{bytes: None, sectors: PVD_SECTOR_COUNT}
|
||||
pub const fn pvd() -> SizeInfo {
|
||||
SizeInfo{
|
||||
full_size: FullSizeInfo{bytes: None, sectors: PVD_SECTOR_COUNT}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn path_tables(root: &Directory) -> LengthInfo {
|
||||
pub fn path_tables(root: &Directory) -> SizeInfo {
|
||||
let path_table_size = PathTable::calculate_size_for(root);
|
||||
LengthInfo{bytes: Some(path_table_size), sectors: sector_count_mode2_form1(path_table_size)}
|
||||
SizeInfo{
|
||||
full_size: FullSizeInfo{bytes: Some(path_table_size), sectors: sector_count_mode2_form1(path_table_size)}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn directory(dir: &Directory) -> LengthInfo {
|
||||
let properties = dir.properties.borrow_mut();
|
||||
let size_bytes = properties.get_padded_size();
|
||||
|
||||
LengthInfo{bytes: Some(size_bytes), sectors: sector_count_mode2_form1(size_bytes)}
|
||||
pub fn directory(dir: &Directory) -> SizeInfo {
|
||||
let full_size_bytes = dir.get_extended_size();
|
||||
SizeInfo{
|
||||
full_size: FullSizeInfo{bytes: Some(full_size_bytes), sectors: sector_count_mode2_form1(full_size_bytes)}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file(file: &File) -> LengthInfo {
|
||||
let fake_size = file.properties.get_padded_size();
|
||||
|
||||
pub fn file(file: &File) -> SizeInfo {
|
||||
let full_size_bytes = file.get_extended_size();
|
||||
if matches!(file.content, FileType::XAAudio(_)) {
|
||||
LengthInfo{bytes: Some(fake_size), sectors: sector_count_mode2_form2(fake_size)}
|
||||
SizeInfo{
|
||||
full_size: FullSizeInfo{bytes: Some(full_size_bytes), sectors: sector_count_mode2_form2(full_size_bytes)}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
LengthInfo{bytes: Some(fake_size), sectors: sector_count_mode2_form1(fake_size)}
|
||||
SizeInfo{
|
||||
full_size: FullSizeInfo{bytes: Some(full_size_bytes), sectors: sector_count_mode2_form1(full_size_bytes)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lead_out(sectors: usize) -> LengthInfo {
|
||||
LengthInfo{bytes: Some(sectors*Mode0::DATA_SIZE), sectors}
|
||||
pub fn lead_out(sectors: usize) -> SizeInfo {
|
||||
SizeInfo{
|
||||
full_size: FullSizeInfo{bytes: Some(sectors*Mode0::DATA_SIZE), sectors}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn calculate_length_for(element: &Layout) -> LengthInfo {
|
||||
pub fn calculate_length_for(element: &Layout) -> SizeInfo {
|
||||
match element {
|
||||
Layout::SystemArea(_) => length_of::system_area(),
|
||||
Layout::PVD(_) => length_of::pvd(),
|
||||
|
@ -81,44 +92,44 @@ pub fn calculate_lbas(cd_desc: &mut CDDesc) {
|
|||
let mut system_area = system_area.borrow_mut();
|
||||
|
||||
system_area.lba.overwrite(cur_lba, track_offset);
|
||||
cur_lba += element_size_info.sectors;
|
||||
cur_lba += element_size_info.full_size.sectors;
|
||||
},
|
||||
|
||||
Layout::PVD(pvd) => {
|
||||
let mut pvd = pvd.borrow_mut();
|
||||
|
||||
pvd.lba.overwrite(cur_lba, track_offset);
|
||||
cur_lba += element_size_info.sectors;
|
||||
cur_lba += element_size_info.full_size.sectors;
|
||||
},
|
||||
|
||||
Layout::PathTables(_, path_table) => {
|
||||
let mut path_table = path_table.borrow_mut();
|
||||
|
||||
path_table.lba.overwrite(cur_lba, track_offset);
|
||||
path_table.size_bytes = element_size_info.bytes.unwrap_or(0);
|
||||
path_table.size_bytes = element_size_info.full_size.bytes.unwrap_or(0);
|
||||
|
||||
cur_lba += element_size_info.sectors*4;
|
||||
cur_lba += element_size_info.full_size.sectors*4;
|
||||
},
|
||||
|
||||
Layout::Directory(dir) => {
|
||||
let dir = dir.borrow_mut();
|
||||
let mut properties = dir.properties.borrow_mut();
|
||||
|
||||
cd_desc.vol_sector_count += element_size_info.sectors;
|
||||
cd_desc.vol_sector_count += element_size_info.full_size.sectors;
|
||||
if properties.is_hidden {
|
||||
properties.lba.overwrite(0, 0);
|
||||
}
|
||||
|
||||
else {
|
||||
cur_lba = update_lba(&mut properties, cur_lba, track_offset, element_size_info.sectors);
|
||||
cur_lba = update_lba(&mut properties, cur_lba, track_offset, element_size_info.full_size.sectors);
|
||||
}
|
||||
},
|
||||
|
||||
Layout::File(file) => {
|
||||
let mut file = file.borrow_mut();
|
||||
|
||||
cd_desc.vol_sector_count += element_size_info.sectors;
|
||||
cur_lba = update_lba(&mut file.properties, cur_lba, track_offset, element_size_info.sectors);
|
||||
cd_desc.vol_sector_count += element_size_info.full_size.sectors;
|
||||
cur_lba = update_lba(&mut file.properties, cur_lba, track_offset, element_size_info.full_size.sectors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,11 @@ use super::{file_writer::SectorWriter, types::{CDDesc, Error}};
|
|||
pub mod cd;
|
||||
pub mod builder;
|
||||
|
||||
pub struct LengthInfo {
|
||||
pub struct SizeInfo {
|
||||
pub full_size: FullSizeInfo
|
||||
}
|
||||
|
||||
pub struct FullSizeInfo {
|
||||
pub bytes: Option<usize>,
|
||||
pub sectors: usize,
|
||||
}
|
|
@ -63,7 +63,6 @@ pub fn write_image(cd_desc: &CDDesc, image_type: ImageType, mut output_path: Pat
|
|||
let mut writer = BinCueWriter::new(open_output_file(&output_path)?, &output_path)?;
|
||||
|
||||
encode_image(cd_desc, &mut writer)?;
|
||||
// TODO: Write times here?!
|
||||
writer.write_cue(open_output_file(&cue_output_path)?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,16 +48,16 @@ pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFil
|
|||
lba_embedded_file_raw.borrow_mut().make_regular(new_content);
|
||||
let new_size_info = calculate_length_for(&Layout::File(lba_embedded_file_raw.clone()));
|
||||
|
||||
if new_size_info.sectors != old_size_info.sectors {
|
||||
if new_size_info.full_size.sectors != old_size_info.full_size.sectors {
|
||||
let lba_embedded_file = lba_embedded_file_raw.borrow();
|
||||
let lba_embedded_file_name = lba_embedded_file.name.to_string();
|
||||
|
||||
if new_size_info.sectors < old_size_info.sectors {
|
||||
return Err(Error::from_text(format!("Failed converting Overlay \"{}\" because new size ({} sectors) is small then {} sectors! (This might be allowed in the future)", lba_embedded_file_name, new_size_info.sectors, old_size_info.sectors)));
|
||||
if new_size_info.full_size.sectors < old_size_info.full_size.sectors {
|
||||
return Err(Error::from_text(format!("Failed converting Overlay \"{}\" because new size ({} sectors) is small then {} sectors! (This might be allowed in the future)", lba_embedded_file_name, new_size_info.full_size.sectors, old_size_info.full_size.sectors)));
|
||||
}
|
||||
|
||||
else {
|
||||
return Err(Error::from_text(format!("Failed converting Overlay \"{}\" because new size ({} sectors) is bigger then {} sectors!", lba_embedded_file_name, new_size_info.sectors, old_size_info.sectors)));
|
||||
return Err(Error::from_text(format!("Failed converting Overlay \"{}\" because new size ({} sectors) is bigger then {} sectors!", lba_embedded_file_name, new_size_info.full_size.sectors, old_size_info.full_size.sectors)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: 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_lba_display_string("LBA", "abs LBA"), "SIZE", "EXTENDED 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, "")?)
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ impl CDDesc {
|
|||
}
|
||||
});
|
||||
|
||||
size += cd::length_of::lead_out(self.lead_out_sectors).bytes.unwrap_or(0);
|
||||
size += cd::length_of::lead_out(self.lead_out_sectors).full_size.bytes.unwrap_or(0);
|
||||
size
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ fn for_each_lba_name<F: FnMut(usize, (usize, usize), bool) -> Result<(), Error>>
|
|||
}
|
||||
|
||||
else {
|
||||
calculate_length_for(&Layout::File(file.clone())).bytes
|
||||
calculate_length_for(&Layout::File(file.clone())).full_size.bytes
|
||||
}
|
||||
});
|
||||
let is_lz4 = file_ref.properties.is_lz4;
|
||||
|
|
Loading…
Reference in New Issue