Improve properties

This commit is contained in:
Jaby 2022-10-11 19:27:34 +02:00
parent de41985b16
commit 58ab918eca
3 changed files with 8 additions and 26 deletions

View File

@ -24,7 +24,6 @@ fn populate() -> Result<CDDesc, Error> {
desc.root.add_file(file); desc.root.add_file(file);
desc.root.add_file(file2); desc.root.add_file(file2);
desc.calculate_lbas();
Ok(desc) Ok(desc)
} }
@ -35,8 +34,8 @@ fn run_main() -> Result<(), Error> {
match element { match element {
Layout::SystemArea(_) => println!("SystemArea:"), Layout::SystemArea(_) => println!("SystemArea:"),
Layout::PVD(_) => println!("PVD:"), Layout::PVD(_) => println!("PVD:"),
Layout::Directory{name, properties} => println!("Dir: {} @{}", name, properties.lba.unwrap_or(0)), Layout::Directory{name, properties} => println!("Dir: {} @{}", name, properties.lba),
Layout::File(file) => println!("File: {} @{}", file, file.get_lba().unwrap_or(0)), Layout::File(file) => println!("File: {} @{}", file, file.get_lba()),
} }
} }
Ok(()) Ok(())

View File

@ -1,13 +0,0 @@
use super::layout::MemoryLayoutMut;
pub fn calculate(layout: MemoryLayoutMut, start_lba: usize) -> usize {
let lba = start_lba;
for element in layout.into_iter() {
match element {
_ => println!("LBA calculation not implemented yet")
}
}
lba
}

View File

@ -1,5 +1,4 @@
pub mod layout; pub mod layout;
mod lba_calculator;
use cdtypes::types::cdstring::DString; use cdtypes::types::cdstring::DString;
use tool_helper::Error; use tool_helper::Error;
@ -18,10 +17,6 @@ impl CDDesc {
} }
} }
pub fn calculate_lbas(&mut self) {
lba_calculator::calculate(self.get_memory_layout_mut(), 0);
}
pub fn get_memory_layout(&self) -> layout::MemoryLayout { pub fn get_memory_layout(&self) -> layout::MemoryLayout {
layout::DefaultLayout::new(self) layout::DefaultLayout::new(self)
} }
@ -69,7 +64,7 @@ impl Directory {
self.files.push(file); self.files.push(file);
} }
pub fn get_lba(&self) -> Option<usize> { pub fn get_lba(&self) -> usize {
self.properties.lba self.properties.lba
} }
} }
@ -90,7 +85,7 @@ impl File {
Ok(File{name: FileName::from_str(file_name)?, properties: Properties::default()}) Ok(File{name: FileName::from_str(file_name)?, properties: Properties::default()})
} }
pub fn get_lba(&self) -> Option<usize> { pub fn get_lba(&self) -> usize {
self.properties.lba self.properties.lba
} }
} }
@ -153,13 +148,14 @@ impl std::fmt::Display for FileName {
} }
pub struct Properties { pub struct Properties {
pub lba: Option<usize>, pub lba: usize,
pub size_b: Option<usize> pub overwrite_size_sectors: Option<usize>,
pub is_hidden: bool
} }
impl Default for Properties { impl Default for Properties {
fn default() -> Self { fn default() -> Self {
Properties{lba: None, size_b: None} Properties{lba: 0, overwrite_size_sectors: None, is_hidden: false}
} }
} }