Create File map
This commit is contained in:
parent
05498f45f3
commit
e38f0758b5
|
@ -41,6 +41,11 @@ fn run_main() -> Result<(), Error> {
|
|||
Layout::File(file) => println!("File: {} @{}-{}", file.borrow(), file.borrow().properties.lba, file.borrow().properties.overwrite_size_bytes.unwrap_or(0)),
|
||||
}
|
||||
}
|
||||
println!("\n<== Planschbecken ==>");
|
||||
for rand_item in desc.create_file_map() {
|
||||
println!("{}", rand_item.0);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
use super::*;
|
||||
use std::collections::hash_map::HashMap;
|
||||
|
||||
pub type FileSystemMap = HashMap<String, SharedPtr<File>>;
|
||||
|
||||
pub fn new_file_map(root: &Directory) -> FileSystemMap {
|
||||
fn add_files(file_system: &mut FileSystemMap, dir: &Directory, mut parent: String) {
|
||||
if let Some(dir_name) = dir.name.as_string() {
|
||||
if !dir_name.is_empty() {
|
||||
parent.push_str(dir_name.as_ref());
|
||||
parent.push('/');
|
||||
}
|
||||
}
|
||||
|
||||
for file in &dir.files {
|
||||
if let Some(name) = file.borrow().name.as_string() {
|
||||
let path = {
|
||||
let mut path = parent.clone();
|
||||
|
||||
path.push_str(name.as_ref());
|
||||
path
|
||||
};
|
||||
|
||||
file_system.insert(path, file.clone());
|
||||
}
|
||||
}
|
||||
|
||||
for dir in &dir.dirs {
|
||||
add_files(file_system, &dir.borrow(), parent.clone());
|
||||
}
|
||||
}
|
||||
|
||||
let mut file_system = HashMap::new();
|
||||
|
||||
add_files(&mut file_system, root, "".to_owned());
|
||||
file_system
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
mod helper;
|
||||
pub mod layout;
|
||||
pub mod file_map;
|
||||
|
||||
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, helper::{round_bytes_mode2_form1, sector_count_mode2_form1}, sector::*, path_table::PathTableL};
|
||||
use file_map::FileSystemMap;
|
||||
use layout::Layout;
|
||||
use tool_helper::Error;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
@ -40,6 +42,10 @@ impl CDDesc {
|
|||
self.root.borrow_mut().add_file(file);
|
||||
}
|
||||
|
||||
pub fn create_file_map(&self) -> FileSystemMap {
|
||||
file_map::new_file_map(&self.root.borrow())
|
||||
}
|
||||
|
||||
pub fn calculate_lbas(&mut self) {
|
||||
let mut path_table_properties = {
|
||||
let mut size_bytes = 0;
|
||||
|
|
Loading…
Reference in New Issue