From a6031e004a232a60f97213c0c0f0060e4002deb6 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 16 Oct 2022 21:35:56 +0200 Subject: [PATCH] Create File map --- src/Tools/psxcdgen_ex/src/main.rs | 5 +++ src/Tools/psxcdgen_ex/src/types/file_map.rs | 37 +++++++++++++++++++++ src/Tools/psxcdgen_ex/src/types/mod.rs | 6 ++++ 3 files changed, 48 insertions(+) create mode 100644 src/Tools/psxcdgen_ex/src/types/file_map.rs diff --git a/src/Tools/psxcdgen_ex/src/main.rs b/src/Tools/psxcdgen_ex/src/main.rs index 7f9e9619..42ccf87c 100644 --- a/src/Tools/psxcdgen_ex/src/main.rs +++ b/src/Tools/psxcdgen_ex/src/main.rs @@ -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(()) } diff --git a/src/Tools/psxcdgen_ex/src/types/file_map.rs b/src/Tools/psxcdgen_ex/src/types/file_map.rs new file mode 100644 index 00000000..949eee7a --- /dev/null +++ b/src/Tools/psxcdgen_ex/src/types/file_map.rs @@ -0,0 +1,37 @@ +use super::*; +use std::collections::hash_map::HashMap; + +pub type FileSystemMap = HashMap>; + +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 +} \ No newline at end of file diff --git a/src/Tools/psxcdgen_ex/src/types/mod.rs b/src/Tools/psxcdgen_ex/src/types/mod.rs index d91c1b1e..5792c6ec 100644 --- a/src/Tools/psxcdgen_ex/src/types/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/mod.rs @@ -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;