Find files
This commit is contained in:
parent
415dcf1ee0
commit
05acd1a519
|
@ -6,6 +6,8 @@
|
||||||
<Track>
|
<Track>
|
||||||
<File name="Miau.txt" padded_size="4096">../Tests/Test.mk</File>
|
<File name="Miau.txt" padded_size="4096">../Tests/Test.mk</File>
|
||||||
<File name="Miau2.txt">../Tests/Test.mk</File>
|
<File name="Miau2.txt">../Tests/Test.mk</File>
|
||||||
|
<File name="SYSTEM.CNF">../Tests/Test.mk</File>
|
||||||
|
<File name="SCES_003.90">../Tests/Test.mk</File>
|
||||||
<Audiofile>../Tests/ISO_Planschbecken.xml</Audiofile>
|
<Audiofile>../Tests/ISO_Planschbecken.xml</Audiofile>
|
||||||
<Directory name="Wuff">
|
<Directory name="Wuff">
|
||||||
<File name="Miau.txt">../Tests/ISO_Planschbecken.xml</File>
|
<File name="Miau.txt">../Tests/ISO_Planschbecken.xml</File>
|
||||||
|
|
|
@ -313,8 +313,8 @@ fn process_file(file: &File, sec_writer: &mut dyn SectorWriter) -> Result<(), Er
|
||||||
let content_sectors = {
|
let content_sectors = {
|
||||||
match &file.content {
|
match &file.content {
|
||||||
FileType::Regular(raw) => builder::create_xa_data_for_vec(None, raw),
|
FileType::Regular(raw) => builder::create_xa_data_for_vec(None, raw),
|
||||||
FileType::Overlay(_) => {
|
FileType::Overlay(_, _) => {
|
||||||
return Err(Error::not_implemented("process_file for Overlay in psx.rs"));
|
return Err(Error::from_str("Trying to encode an unprocessed overlay file"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@ pub mod file_writer;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
use tool_helper::{format_if_error, Output, read_file};
|
use tool_helper::{format_if_error, Output, read_file};
|
||||||
use types::{CDDesc, Directory, File, Properties, SharedPtr};
|
use types::{CDDesc, Directory, File, FileType, FileSystemMap, Properties, SharedPtr};
|
||||||
|
|
||||||
pub type CalculateLBAFunction = fn(&mut types::CDDesc);
|
pub type CalculateLBAFunction = fn(&mut types::CDDesc);
|
||||||
pub type LBAEmbeddedFiles = Vec<SharedPtr<File>>;
|
pub type LBAEmbeddedFiles = Vec<SharedPtr<File>>;
|
||||||
|
@ -27,6 +27,21 @@ pub fn process(config: config_reader::Configuration, calculate_lba: CalculateLBA
|
||||||
Ok((cd_desc, lba_embedded_files))
|
Ok((cd_desc, lba_embedded_files))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn process_files(file_map: FileSystemMap, lba_embedded_files: LBAEmbeddedFiles) -> Result<(), Error> {
|
||||||
|
for lba_embedded_file in lba_embedded_files {
|
||||||
|
let mut lba_embedded_file = lba_embedded_file.borrow_mut();
|
||||||
|
|
||||||
|
match &mut lba_embedded_file.content {
|
||||||
|
FileType::Overlay(content, lba_names) => {
|
||||||
|
let _new_content = types::overlay::update_content(std::mem::take(content), std::mem::take(lba_names), &file_map)?;
|
||||||
|
},
|
||||||
|
_ =>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(Error::not_implemented("process_files"))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
|
pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
|
||||||
const NO_NAME:&'static str = "<No Name>";
|
const NO_NAME:&'static str = "<No Name>";
|
||||||
const ARROW:&'static str = "|==>";
|
const ARROW:&'static str = "|==>";
|
||||||
|
|
|
@ -37,16 +37,10 @@ impl SystemType {
|
||||||
|
|
||||||
fn run_main(cmd_line: CommandLine) -> Result<(), Error> {
|
fn run_main(cmd_line: CommandLine) -> Result<(), Error> {
|
||||||
let encoding_functions = cmd_line.system_type.get_encoding_functions();
|
let encoding_functions = cmd_line.system_type.get_encoding_functions();
|
||||||
let (desc, _lba_embbeded_files) = psxcdgen_ex::process(config_reader::parse_xml(std::fs::read_to_string(cmd_line.input_file)?)?, encoding_functions.lba_calculator)?;
|
let (desc, lba_embedded_files) = psxcdgen_ex::process(config_reader::parse_xml(std::fs::read_to_string(cmd_line.input_file)?)?, encoding_functions.lba_calculator)?;
|
||||||
|
let file_map = desc.create_file_map();
|
||||||
/*
|
|
||||||
// Describes how to use the the file_map
|
|
||||||
println!("\n<== Planschbecken ==>");
|
|
||||||
for rand_item in desc.create_file_map() {
|
|
||||||
println!("{}", rand_item.0);
|
|
||||||
}
|
|
||||||
println!("\n<== Planschbecken ==>");*/
|
|
||||||
|
|
||||||
|
psxcdgen_ex::process_files(file_map, lba_embedded_files)?;
|
||||||
write_image(&desc, encoding_functions.encoder, cmd_line.output_type, cmd_line.output_file)?;
|
write_image(&desc, encoding_functions.encoder, cmd_line.output_type, cmd_line.output_file)?;
|
||||||
|
|
||||||
if let Some(list_content_option) = cmd_line.list_content {
|
if let Some(list_content_option) = cmd_line.list_content {
|
||||||
|
|
|
@ -5,12 +5,14 @@ pub type FileSystemMap = HashMap<String, SharedPtr<File>>;
|
||||||
|
|
||||||
pub fn new_file_map(root: &Directory) -> FileSystemMap {
|
pub fn new_file_map(root: &Directory) -> FileSystemMap {
|
||||||
fn add_files(file_system: &mut FileSystemMap, dir: &Directory, mut parent: String) {
|
fn add_files(file_system: &mut FileSystemMap, dir: &Directory, mut parent: String) {
|
||||||
|
if !dir.name.is_root() {
|
||||||
if let Some(dir_name) = dir.name.as_string() {
|
if let Some(dir_name) = dir.name.as_string() {
|
||||||
if !dir_name.is_empty() {
|
if !dir_name.is_empty() {
|
||||||
parent.push_str(dir_name.as_ref());
|
parent.push_str(dir_name.as_ref());
|
||||||
parent.push('/');
|
parent.push('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for file in &dir.files {
|
for file in &dir.files {
|
||||||
if let Some(name) = file.borrow().name.as_string() {
|
if let Some(name) = file.borrow().name.as_string() {
|
||||||
|
@ -21,6 +23,7 @@ pub fn new_file_map(root: &Directory) -> FileSystemMap {
|
||||||
path
|
path
|
||||||
};
|
};
|
||||||
|
|
||||||
|
println!("Adding: {}", path);
|
||||||
file_system.insert(path, file.clone());
|
file_system.insert(path, file.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ pub mod file_map;
|
||||||
pub mod overlay;
|
pub mod overlay;
|
||||||
|
|
||||||
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, path_table::PathTableL};
|
use cdtypes::types::{cdstring::DString, dir_record::DirectoryRecord, path_table::PathTableL};
|
||||||
use file_map::FileSystemMap;
|
|
||||||
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
||||||
|
|
||||||
|
pub use file_map::FileSystemMap;
|
||||||
pub use tool_helper::Error;
|
pub use tool_helper::Error;
|
||||||
pub type SharedPtr<T> = Rc<RefCell<T>>;
|
pub type SharedPtr<T> = Rc<RefCell<T>>;
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ impl std::fmt::Display for Directory {
|
||||||
|
|
||||||
pub(super) enum FileType {
|
pub(super) enum FileType {
|
||||||
Regular(Vec<u8>),
|
Regular(Vec<u8>),
|
||||||
Overlay(Vec<u8>),
|
Overlay(Vec<u8>, overlay::LBANameVec),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct File {
|
pub struct File {
|
||||||
|
@ -194,8 +194,8 @@ impl File {
|
||||||
Self::new_from_content(file_name, FileType::Regular(content), content_size)
|
Self::new_from_content(file_name, FileType::Regular(content), content_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_overlay(file_name: &str, content: Vec<u8>, content_size: usize) -> Result<File, Error> {
|
pub fn new_overlay(file_name: &str, content: Vec<u8>, lba_names: overlay::LBANameVec, content_size: usize) -> Result<File, Error> {
|
||||||
Self::new_from_content(file_name, FileType::Overlay(content), content_size)
|
Self::new_from_content(file_name, FileType::Overlay(content, lba_names), content_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_track_rel_lba(&self) -> usize {
|
pub fn get_track_rel_lba(&self) -> usize {
|
||||||
|
@ -238,6 +238,10 @@ impl DirectoryName {
|
||||||
pub fn as_str(&self) -> Option<&str> {
|
pub fn as_str(&self) -> Option<&str> {
|
||||||
dstring_as_str(&self.name, self.len)
|
dstring_as_str(&self.name, self.len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_root(&self) -> bool {
|
||||||
|
self.name.as_raw()[0] == 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for DirectoryName {
|
impl std::fmt::Display for DirectoryName {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::File;
|
use super::{File, FileSystemMap};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use no_comment::{IntoWithoutComments as _, languages};
|
use no_comment::{IntoWithoutComments as _, languages};
|
||||||
|
@ -21,10 +21,29 @@ impl OverlayHeader {
|
||||||
|
|
||||||
pub fn load_from(file_name: &str, file_path: PathBuf, lba_source: PathBuf) -> Result<File, Error> {
|
pub fn load_from(file_name: &str, file_path: PathBuf, lba_source: PathBuf) -> Result<File, Error> {
|
||||||
let content = load_content(&file_path)?;
|
let content = load_content(&file_path)?;
|
||||||
let _ = load_lba_names(lba_source)?;
|
let lba_names = load_lba_names(lba_source)?;
|
||||||
let content_size = format_if_error!(tool_helper::compress::lz4(&content, 16), "Compressing {} failed with \"{error_text}\"", file_path.to_string_lossy())?.len();
|
let content_size = format_if_error!(tool_helper::compress::lz4(&content, 16), "Compressing {} failed with \"{error_text}\"", file_path.to_string_lossy())?.len();
|
||||||
|
|
||||||
Ok(File::new_overlay(file_name, content, content_size)?)
|
Ok(File::new_overlay(file_name, content, lba_names, content_size)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_content(_content: Vec<u8>, lba_names: LBANameVec, file_map: &FileSystemMap) -> Result<Vec<u8>, Error> {
|
||||||
|
for mut lba_name in lba_names {
|
||||||
|
if lba_name.find(';').is_none() {
|
||||||
|
lba_name.push_str(";1");
|
||||||
|
}
|
||||||
|
|
||||||
|
print!("Searching {}... ", lba_name);
|
||||||
|
if let Some(info) = file_map.get(&lba_name) {
|
||||||
|
println!("found @ {}", info.borrow().get_track_rel_lba())
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
println!("Not found...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(Error::not_implemented("update_overlay"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_content(file_path: &PathBuf) -> Result<Vec<u8>, Error> {
|
fn load_content(file_path: &PathBuf) -> Result<Vec<u8>, Error> {
|
||||||
|
|
Loading…
Reference in New Issue