Support LZ4 compression in psxcdgen_ex
This commit is contained in:
parent
f893c99b65
commit
44987ba5d9
|
@ -9,6 +9,7 @@ use config_reader::LZ4State;
|
|||
use encoder::{LbaCalculatorFunction, LengthCalculatorFunction};
|
||||
use tool_helper::{format_if_error, Output, read_file};
|
||||
use types::{layout::Layout, CDDesc, Directory, File, FileType, FileSystemMap, Properties, SharedPtr};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub type LBAEmbeddedFiles = Vec<SharedPtr<File>>;
|
||||
|
||||
|
@ -157,24 +158,30 @@ fn parse_configuration(config: config_reader::Configuration) -> Result<(CDDesc,
|
|||
},
|
||||
|
||||
config_reader::DirMember::File(file) => {
|
||||
let lz4_state = file.common.lz4_state;
|
||||
let (mut desc_file, needs_treatment) = {
|
||||
fn handle_file_load(file_path: &PathBuf, lz4_state: &LZ4State) -> Result<Vec<u8>, Error> {
|
||||
let file_content = read_file(file_path)?;
|
||||
|
||||
if matches!(lz4_state, LZ4State::Compress) {
|
||||
tool_helper::compress::psx_default::lz4(&file_content)
|
||||
}
|
||||
|
||||
else {
|
||||
Ok(file_content)
|
||||
}
|
||||
}
|
||||
|
||||
match file.kind {
|
||||
config_reader::FileKind::Regular => (types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?, false),
|
||||
config_reader::FileKind::Main(lba_source) => (types::overlay::load_for_main(file.common.name.as_str(), read_file(&file.path)?, lba_source)?, true),
|
||||
config_reader::FileKind::Regular => (types::File::new_regular(file.common.name.as_str(), handle_file_load(&file.path, &lz4_state)?)?, false),
|
||||
config_reader::FileKind::Main(lba_source) => (types::overlay::load_for_main(file.common.name.as_str(), handle_file_load(&file.path, &lz4_state)?, lba_source)?, true),
|
||||
config_reader::FileKind::Overlay(lba_source) => (types::overlay::load_from(file.common.name.as_str(), &file.path, lba_source)?, true),
|
||||
}
|
||||
};
|
||||
|
||||
desc_file.properties.padded_size_bytes = file.common.padded_size;
|
||||
desc_file.properties.is_hidden = file.common.is_hidden;
|
||||
|
||||
match file.common.lz4_state {
|
||||
LZ4State::None => desc_file.properties.is_lz4 = false,
|
||||
LZ4State::AlreadyCompressed => desc_file.properties.is_lz4 = true,
|
||||
LZ4State::Compress => {
|
||||
return Err(Error::from_text(format!("LZ4 compression requested for file {} but feature is not supported yet", &file.path.to_string_lossy())));
|
||||
}
|
||||
}
|
||||
desc_file.properties.is_lz4 = !matches!(lz4_state, LZ4State::None);
|
||||
|
||||
let new_file = dst_dir.add_file(desc_file);
|
||||
if needs_treatment {
|
||||
|
|
Loading…
Reference in New Issue