Prepare reading in LBA Source for Overlay

This commit is contained in:
Jaby 2022-12-07 02:50:46 +01:00 committed by Jaby
parent f66f7fb8ee
commit 4c07721d45
8 changed files with 36 additions and 34 deletions

View File

@ -13,6 +13,6 @@
<File name="SubM.txt">../Tests/ISO_Planschbecken.xml</File> <File name="SubM.txt">../Tests/ISO_Planschbecken.xml</File>
</Directory> </Directory>
</Directory> </Directory>
<Overlay name="Main.ovl">../../../../JabyAdventure/application/bin/PSX-release/Overlay.main_area</Overlay> <Overlay name="Main.ovl" lba_source="../../../../JabyAdventure/application/src/MainState/LBAs.hpp">../../../../JabyAdventure/application/bin/PSX-release/Overlay.main_area</Overlay>
</Track> </Track>
</ISO_Project> </ISO_Project>

View File

@ -22,7 +22,7 @@ pub struct CommonProperties {
pub enum FileKind { pub enum FileKind {
Regular, Regular,
Overlay Overlay(PathBuf)
} }
pub struct File { pub struct File {
@ -30,13 +30,6 @@ pub struct File {
pub path: PathBuf, pub path: PathBuf,
pub kind: FileKind pub kind: FileKind
} }
pub struct LbaFile {
pub common: CommonProperties,
pub header: Option<PathBuf>,
pub entries: Vec<String>
}
pub struct Directory { pub struct Directory {
pub name: String, pub name: String,
pub is_hidden: bool, pub is_hidden: bool,

View File

@ -8,6 +8,7 @@ mod attribute_names {
pub const NAME: &'static str = "name"; pub const NAME: &'static str = "name";
pub const HIDDEN: &'static str = "hidden"; pub const HIDDEN: &'static str = "hidden";
pub const PADDED_SIZE: &'static str = "padded_size"; pub const PADDED_SIZE: &'static str = "padded_size";
pub const LBA_SOURCE: &'static str = "lba_source";
} }
pub fn parse(xml: String) -> Result<Configuration, Error> { pub fn parse(xml: String) -> Result<Configuration, Error> {
@ -60,10 +61,11 @@ fn parse_track(track: roxmltree::Node, config: &mut Configuration) -> Result<(),
} }
fn parse_overlay_file(file: roxmltree::Node, is_hidden: bool) -> Result<File, Error> { fn parse_overlay_file(file: roxmltree::Node, is_hidden: bool) -> Result<File, Error> {
Ok(File{ Ok(File{
common: read_common_properties(&file, is_hidden)?, common: read_common_properties(&file, is_hidden)?,
path: PathBuf::from(file.text().unwrap_or_default()), path: PathBuf::from(file.text().unwrap_or_default()),
kind: FileKind::Overlay kind: FileKind::Overlay(PathBuf::from(file.attribute(attribute_names::LBA_SOURCE).unwrap_or_default())),
}) })
} }

View File

@ -6,9 +6,10 @@ 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, Properties}; use types::{CDDesc, Directory, File, Properties, SharedPtr};
pub type CalculateLBAFunction = fn(&mut types::CDDesc); pub type CalculateLBAFunction = fn(&mut types::CDDesc);
pub type LBAEmbeddedFiles = Vec<SharedPtr<File>>;
struct ContentDumpAlignment { struct ContentDumpAlignment {
name: usize, name: usize,
@ -19,11 +20,11 @@ struct ContentDumpAlignment {
const DEFAULT_CONTENT_ALIGNMENT:ContentDumpAlignment = ContentDumpAlignment{name: 24, lba: 8, size: 8, ex_size: 8}; const DEFAULT_CONTENT_ALIGNMENT:ContentDumpAlignment = ContentDumpAlignment{name: 24, lba: 8, size: 8, ex_size: 8};
pub fn process(config: config_reader::Configuration, calculate_lba: CalculateLBAFunction) -> Result<CDDesc, Error> { pub fn process(config: config_reader::Configuration, calculate_lba: CalculateLBAFunction) -> Result<(CDDesc, LBAEmbeddedFiles), Error> {
let mut cd_desc = parse_configuration(config)?; let (mut cd_desc, lba_embedded_files) = parse_configuration(config)?;
calculate_lba(&mut cd_desc); calculate_lba(&mut cd_desc);
Ok(cd_desc) Ok((cd_desc, lba_embedded_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> {
@ -101,29 +102,33 @@ pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> {
format_if_error!(dump_dir(&cd_desc.root.borrow(), &mut out, 0), "Creating content dump failed with: {error_text}") format_if_error!(dump_dir(&cd_desc.root.borrow(), &mut out, 0), "Creating content dump failed with: {error_text}")
} }
fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, Error> { fn parse_configuration(config: config_reader::Configuration) -> Result<(CDDesc, LBAEmbeddedFiles), Error> {
fn parse_dir(dst_dir: &mut types::Directory, src_dir: config_reader::Directory) -> Result<(), Error> { fn parse_dir(dst_dir: &mut types::Directory, src_dir: config_reader::Directory, lba_embedded_files: &mut LBAEmbeddedFiles) -> Result<(), Error> {
for member in src_dir.into_iter() { for member in src_dir.into_iter() {
match member { match member {
config_reader::DirMember::Directory(dir) => { config_reader::DirMember::Directory(dir) => {
let mut new_dir = types::Directory::new(dir.name.as_str())?; let mut new_dir = types::Directory::new(dir.name.as_str())?;
new_dir.properties.borrow_mut().is_hidden = dir.is_hidden; new_dir.properties.borrow_mut().is_hidden = dir.is_hidden;
parse_dir(&mut new_dir, dir)?; parse_dir(&mut new_dir, dir, lba_embedded_files)?;
dst_dir.add_dir(new_dir); dst_dir.add_dir(new_dir);
}, },
config_reader::DirMember::File(file) => { config_reader::DirMember::File(file) => {
let mut desc_file = { let (mut desc_file, needs_treatment) = {
match file.kind { match file.kind {
config_reader::FileKind::Regular => types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?, config_reader::FileKind::Regular => (types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?, false),
config_reader::FileKind::Overlay => types::overlay::load_from(file.common.name.as_str(), file.path)?, config_reader::FileKind::Overlay(_) => (types::overlay::load_from(file.common.name.as_str(), file.path)?, true)
} }
}; };
desc_file.properties.padded_size_bytes = file.common.padded_size; desc_file.properties.padded_size_bytes = file.common.padded_size;
desc_file.properties.is_hidden = file.common.is_hidden; desc_file.properties.is_hidden = file.common.is_hidden;
dst_dir.add_file(desc_file);
let new_file = dst_dir.add_file(desc_file);
if needs_treatment {
lba_embedded_files.push(new_file);
}
}, },
} }
} }
@ -132,6 +137,7 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
} }
let cd_desc = CDDesc::new(); let cd_desc = CDDesc::new();
let mut lba_embedded_files = Vec::new();
if let Some(publisher) = config.publisher { if let Some(publisher) = config.publisher {
cd_desc.pvd.borrow_mut().set_publisher(publisher); cd_desc.pvd.borrow_mut().set_publisher(publisher);
@ -141,6 +147,6 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<CDDesc, E
cd_desc.system_area.borrow_mut().license_file_path = Some(license_path); cd_desc.system_area.borrow_mut().license_file_path = Some(license_path);
} }
parse_dir(&mut cd_desc.root.borrow_mut(), config.root)?; parse_dir(&mut cd_desc.root.borrow_mut(), config.root, &mut lba_embedded_files)?;
Ok(cd_desc) Ok((cd_desc, lba_embedded_files))
} }

View File

@ -37,7 +37,7 @@ 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 = psxcdgen_ex::process(config_reader::parse_xml(std::fs::read_to_string(cmd_line.input_file)?)?, encoding_functions.lba_calculator)?; 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)?;
/* /*
// Describes how to use the the file_map // Describes how to use the the file_map

View File

@ -130,9 +130,12 @@ impl Directory {
self.dirs.push(new_shared_ptr(dir)); self.dirs.push(new_shared_ptr(dir));
} }
pub fn add_file(&mut self, mut file: File) { pub fn add_file(&mut self, mut file: File) -> SharedPtr<File> {
file.parent_properties = Some(self.properties.clone()); file.parent_properties = Some(self.properties.clone());
self.files.push(new_shared_ptr(file));
let file = new_shared_ptr(file);
self.files.push(file.clone());
file
} }
pub fn get_track_rel_lba(&self) -> usize { pub fn get_track_rel_lba(&self) -> usize {
@ -191,9 +194,7 @@ 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>) -> Result<File, Error> { pub fn new_overlay(file_name: &str, content: Vec<u8>, content_size: usize) -> Result<File, Error> {
let content_size = content.len();
Self::new_from_content(file_name, FileType::Overlay(content), content_size) Self::new_from_content(file_name, FileType::Overlay(content), content_size)
} }

View File

@ -38,6 +38,6 @@ pub fn load_from(file_name: &str, file_path: PathBuf) -> Result<File, Error> {
count += 1; count += 1;
} }
let content = format_if_error!(tool_helper::compress::lz4(content, 16), "Compressing {} failed with \"{error_text}\"", file_path.to_string_lossy())?; 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)?) Ok(File::new_overlay(file_name, content, content_size)?)
} }

View File

@ -1,7 +1,7 @@
use super::Error; use super::Error;
use lz4::EncoderBuilder; use lz4::EncoderBuilder;
pub fn lz4(data: Vec<u8>, compression_level: u32) -> Result<Vec<u8>, Error> { pub fn lz4(data: &Vec<u8>, compression_level: u32) -> Result<Vec<u8>, Error> {
let mut lz4_encoder = EncoderBuilder::new().level(compression_level).build(Vec::<u8>::new())?; let mut lz4_encoder = EncoderBuilder::new().level(compression_level).build(Vec::<u8>::new())?;
std::io::copy(&mut&data[..], &mut lz4_encoder)?; std::io::copy(&mut&data[..], &mut lz4_encoder)?;