Calculate size for DirectoryRecords
This commit is contained in:
parent
441096e52f
commit
8651b7ac9b
|
@ -24,7 +24,7 @@ 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.update_dir_records();
|
desc.calculate_lbas();
|
||||||
Ok(desc)
|
Ok(desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,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),
|
Layout::Directory{name, properties} => println!("Dir: {} @{}-{}", name, properties.lba, properties.overwrite_size_bytes.unwrap_or(0)),
|
||||||
Layout::File(file) => println!("File: {} @{}", file, file.properties.lba),
|
Layout::File(file) => println!("File: {} @{}-{}", file, file.properties.lba, file.properties.overwrite_size_bytes.unwrap_or(0)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -17,6 +17,8 @@ impl DirectoryRecordMember {
|
||||||
pub fn collect_directory_record_member(files: &Vec<File>, dirs: &Vec<Directory>) -> Vec<DirectoryRecordMember> {
|
pub fn collect_directory_record_member(files: &Vec<File>, dirs: &Vec<Directory>) -> Vec<DirectoryRecordMember> {
|
||||||
let mut collection = Vec::new();
|
let mut collection = Vec::new();
|
||||||
|
|
||||||
|
collection.push(DirectoryRecordMember::Directory{name: "\x00".to_owned()});
|
||||||
|
collection.push(DirectoryRecordMember::Directory{name: "\x01".to_owned()});
|
||||||
for file in files {
|
for file in files {
|
||||||
if !file.properties.is_hidden {
|
if !file.properties.is_hidden {
|
||||||
if let Some(name) = file.name.as_string() {
|
if let Some(name) = file.name.as_string() {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod helper;
|
mod helper;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
|
|
||||||
use cdtypes::types::cdstring::DString;
|
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord};
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
|
||||||
pub struct CDDesc {
|
pub struct CDDesc {
|
||||||
|
@ -26,17 +26,18 @@ impl CDDesc {
|
||||||
layout::DefaultLayoutMut::new(self)
|
layout::DefaultLayoutMut::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_dir_records(&mut self) {
|
pub fn calculate_lbas(&mut self) {
|
||||||
fn update_dir_record_of(dir: &mut Directory) {
|
Self::for_each_dir_mut(&mut self.root, &|dir| {dir.update_content_size();});
|
||||||
dir.update_content();
|
|
||||||
|
|
||||||
|
// Now layout iterate?
|
||||||
|
}
|
||||||
|
|
||||||
|
fn for_each_dir_mut<T: Fn(&mut Directory)>(dir: &mut Directory, function: &T) {
|
||||||
|
function(dir);
|
||||||
for sub_dir in &mut dir.dirs {
|
for sub_dir in &mut dir.dirs {
|
||||||
update_dir_record_of(sub_dir);
|
Self::for_each_dir_mut(sub_dir, function);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_dir_record_of(&mut self.root);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SystemArea {
|
pub struct SystemArea {
|
||||||
|
@ -77,7 +78,18 @@ impl Directory {
|
||||||
self.files.push(file);
|
self.files.push(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_content(&mut self) {
|
fn update_content_size(&mut self) {
|
||||||
|
let dir_member = helper::collect_directory_record_member(&self.files, &self.dirs);
|
||||||
|
let mut size_bytes = 0;
|
||||||
|
|
||||||
|
for member in dir_member {
|
||||||
|
size_bytes += DirectoryRecord::calculate_size_for(member.get_name().as_str(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.properties.overwrite_size_bytes = Some(size_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn _update_content(&mut self) {
|
||||||
let dir_member = helper::collect_directory_record_member(&self.files, &self.dirs);
|
let dir_member = helper::collect_directory_record_member(&self.files, &self.dirs);
|
||||||
|
|
||||||
println!("{} updating content", self.name.as_string().unwrap_or("<No name>".to_owned()));
|
println!("{} updating content", self.name.as_string().unwrap_or("<No name>".to_owned()));
|
||||||
|
@ -96,12 +108,12 @@ impl std::fmt::Display for Directory {
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub name: FileName,
|
pub name: FileName,
|
||||||
pub properties: Properties,
|
pub properties: Properties,
|
||||||
content: Vec<u8>
|
_content: Vec<u8>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
pub fn new(file_name: &str) -> Result<File, Error> {
|
pub fn new(file_name: &str) -> Result<File, Error> {
|
||||||
Ok(File{name: FileName::from_str(file_name)?, properties: Properties::default(), content: Vec::new()})
|
Ok(File{name: FileName::from_str(file_name)?, properties: Properties::default(), _content: Vec::new()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,13 +192,13 @@ impl std::fmt::Display for FileName {
|
||||||
|
|
||||||
pub struct Properties {
|
pub struct Properties {
|
||||||
pub lba: usize,
|
pub lba: usize,
|
||||||
pub overwrite_size_sectors: Option<usize>,
|
pub overwrite_size_bytes: Option<usize>,
|
||||||
pub is_hidden: bool
|
pub is_hidden: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Properties {
|
impl Default for Properties {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Properties{lba: 0, overwrite_size_sectors: None, is_hidden: false}
|
Properties{lba: 0, overwrite_size_bytes: None, is_hidden: false}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue