From c2e45a833b628b9c67441f167cf1f22c998de0a7 Mon Sep 17 00:00:00 2001 From: jaby Date: Mon, 20 Feb 2023 13:07:58 +0100 Subject: [PATCH] Refactored code --- src/Tools/psxcdgen_ex/src/encoder/psx.rs | 18 ++++++------ src/Tools/psxcdgen_ex/src/types/helper.rs | 8 +++--- src/Tools/psxcdgen_ex/src/types/mod.rs | 34 +++++++++++------------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Tools/psxcdgen_ex/src/encoder/psx.rs b/src/Tools/psxcdgen_ex/src/encoder/psx.rs index 7397e1ad..bf10aef1 100644 --- a/src/Tools/psxcdgen_ex/src/encoder/psx.rs +++ b/src/Tools/psxcdgen_ex/src/encoder/psx.rs @@ -42,7 +42,7 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) { for element in cd_desc.get_memory_layout() { fn update_lba(properties: &mut Properties, cur_lba: usize, track_offset: usize, content_sector_size: usize) -> usize { - properties.track_rel_lba.overwrite(cur_lba, track_offset); + properties.lba.overwrite(cur_lba, track_offset); cur_lba + content_sector_size } @@ -51,21 +51,21 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) { Layout::SystemArea(system_area) => { let mut system_area = system_area.borrow_mut(); - system_area.track_rel_lba.overwrite(cur_lba, track_offset); + system_area.lba.overwrite(cur_lba, track_offset); cur_lba += element_size_info.sectors; }, Layout::PVD(pvd) => { let mut pvd = pvd.borrow_mut(); - pvd.track_rel_lba.overwrite(cur_lba, track_offset); + pvd.lba.overwrite(cur_lba, track_offset); cur_lba += element_size_info.sectors; }, Layout::PathTables(_, path_table) => { let mut path_table = path_table.borrow_mut(); - path_table.track_rel_lba.overwrite(cur_lba, track_offset); + path_table.lba.overwrite(cur_lba, track_offset); path_table.size_bytes = element_size_info.bytes.unwrap_or(0); cur_lba += element_size_info.sectors*4; @@ -77,7 +77,7 @@ pub fn calculate_psx_lbas(cd_desc: &mut CDDesc) { cd_desc.vol_sector_count += element_size_info.sectors; if properties.is_hidden { - properties.track_rel_lba.overwrite(0, 0); + properties.lba.overwrite(0, 0); } else { @@ -186,7 +186,7 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit Ok(()) } - let system_area_lba = system_area.track_rel_lba.get_for_cur_track(); + let system_area_lba = system_area.lba.get_track_relative(); if system_area_lba != 0 { return Err(Error::from_text(format!("System Area required to start at sector 0 of Track - found LBA: {}", system_area_lba))); } @@ -211,7 +211,7 @@ fn process_pvd(pvd: &PrimaryVolumeDescriptor, path_table: SharedPtr, let path_table = validate_and_unwrap_path_table(&path_table)?; let root_dir = root_dir.borrow(); - let pvd_lba = pvd.track_rel_lba.get_for_cur_track(); + let pvd_lba = pvd.lba.get_track_relative(); if pvd_lba != 16 { return Err(Error::from_text(format!("PVD required to start at sector 16 of Track - found LBA: {}", pvd_lba))); @@ -434,7 +434,7 @@ fn write_dir_record(dir_record: &mut [u8], dir_member: &DirectoryRecordMember, h } }; - let dir_record = create_dir_record_raw(dir_record, name.as_str(), *track_rel_lba, round_bytes_mode2_form1(*real_size as usize) as u32, system_use)?; + let dir_record = create_dir_record_raw(dir_record, name.as_str(), *track_rel_lba as u32, round_bytes_mode2_form1(*real_size as usize) as u32, system_use)?; dir_record.set_directory(); return Ok(dir_record.length[0] as usize); @@ -454,7 +454,7 @@ fn write_dir_record(dir_record: &mut [u8], dir_member: &DirectoryRecordMember, h } }; - let dir_record = create_dir_record_raw(dir_record, name.as_str(), *track_rel_lba, *real_size, system_use)?; + let dir_record = create_dir_record_raw(dir_record, name.as_str(), *track_rel_lba as u32, *real_size as u32, system_use)?; dir_record.set_file(); return Ok(dir_record.length[0] as usize); diff --git a/src/Tools/psxcdgen_ex/src/types/helper.rs b/src/Tools/psxcdgen_ex/src/types/helper.rs index b5669203..5d75c800 100644 --- a/src/Tools/psxcdgen_ex/src/types/helper.rs +++ b/src/Tools/psxcdgen_ex/src/types/helper.rs @@ -10,17 +10,17 @@ pub struct PathTableMember { } pub enum DirectoryRecordMember { - Directory{name: String, track_rel_lba: u32, real_size: u32}, - File{name: String, track_rel_lba: u32, real_size: u32}, + Directory{name: String, track_rel_lba: usize, real_size: usize}, + File{name: String, track_rel_lba: usize, real_size: usize}, } impl DirectoryRecordMember { pub fn new_dir(name: String, properties: &Properties) -> DirectoryRecordMember { - DirectoryRecordMember::Directory{name, track_rel_lba: properties.track_rel_lba.get_for_cur_track() as u32, real_size: properties.get_real_size() as u32} + DirectoryRecordMember::Directory{name, track_rel_lba: properties.lba.get_track_relative(), real_size: properties.get_real_size()} } pub fn new_file(name: String, properties: &Properties) -> DirectoryRecordMember { - DirectoryRecordMember::File{name, track_rel_lba: properties.track_rel_lba.get_for_cur_track() as u32, real_size: properties.get_real_size() as u32} + DirectoryRecordMember::File{name, track_rel_lba: properties.lba.get_track_relative(), real_size: properties.get_real_size()} } pub fn get_name(&self) -> &String { diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index f0158ac5..68d00414 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -57,24 +57,24 @@ impl CDDesc { } pub struct SystemArea { - pub(in super) track_rel_lba: LBA, + pub(in super) lba: LBA, pub(in super) license_file_path: Option, } impl SystemArea { pub fn new() -> SystemArea { - SystemArea{track_rel_lba: LBA::default(), license_file_path: None} + SystemArea{lba: LBA::default(), license_file_path: None} } } pub struct PathTable { - pub(super) track_rel_lba: LBA, - pub(super) size_bytes: usize, + pub(super) lba: LBA, + pub(super) size_bytes: usize, } impl PathTable { pub fn new() -> PathTable { - PathTable{track_rel_lba: LBA::default(), size_bytes: 0} + PathTable{lba: LBA::default(), size_bytes: 0} } pub fn collect_member(root: SharedPtr) -> Vec { @@ -93,18 +93,18 @@ impl PathTable { pub fn get_track_rel_lba_for(&self, table_num: usize, sector_count_func: fn(data_size: usize) -> usize) -> usize { let table_num = table_num - 1; - self.track_rel_lba.get_for_cur_track() + (table_num*sector_count_func(self.size_bytes)) + self.lba.get_track_relative() + (table_num*sector_count_func(self.size_bytes)) } } pub struct PrimaryVolumeDescriptor { - pub(super) track_rel_lba: LBA, - pub(super) publisher: String, + pub(super) lba: LBA, + pub(super) publisher: String, } impl PrimaryVolumeDescriptor { pub fn new() -> PrimaryVolumeDescriptor { - PrimaryVolumeDescriptor{track_rel_lba: LBA::default(), publisher: String::new()} + PrimaryVolumeDescriptor{lba: LBA::default(), publisher: String::new()} } pub fn set_publisher(&mut self, publisher: String) { @@ -139,11 +139,11 @@ impl Directory { } pub fn get_track_rel_lba(&self) -> usize { - self.properties.borrow().track_rel_lba.get_for_cur_track() + self.properties.borrow().lba.get_track_relative() } pub fn get_absolute_lba(&self) -> usize { - self.properties.borrow().track_rel_lba.get_for_track1() + self.properties.borrow().lba.get_track_absolute() } pub fn get_extended_size(&self) -> usize { @@ -210,11 +210,11 @@ impl File { } pub fn get_track_rel_lba(&self) -> usize { - self.properties.track_rel_lba.get_for_cur_track() + self.properties.lba.get_track_relative() } pub fn get_absolute_lba(&self) -> usize { - self.properties.track_rel_lba.get_for_track1() + self.properties.lba.get_track_absolute() } pub fn get_extended_size(&self) -> usize { @@ -312,7 +312,7 @@ impl std::fmt::Display for FileName { } pub struct Properties { - pub(super) track_rel_lba: LBA, + pub(super) lba: LBA, pub(super) size_bytes: usize, pub(super) padded_size_bytes: Option, pub(super) is_hidden: bool @@ -340,7 +340,7 @@ impl Properties { impl Default for Properties { fn default() -> Self { - Properties{track_rel_lba: LBA::default(), size_bytes: 0, padded_size_bytes: None, is_hidden: false} + Properties{lba: LBA::default(), size_bytes: 0, padded_size_bytes: None, is_hidden: false} } } @@ -372,11 +372,11 @@ impl LBA { self.set_track_rel(rel_lba); } - pub fn get_for_cur_track(&self) -> usize { + pub fn get_track_relative(&self) -> usize { self.track_rel } - pub fn get_for_track1(&self) -> usize { + pub fn get_track_absolute(&self) -> usize { self.track_rel + self.track_offset } }