diff --git a/src/Tools/.cargo/config.toml b/src/Tools/.cargo/config.toml deleted file mode 100644 index d07fa72e..00000000 --- a/src/Tools/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.x86_64-unknown-linux-musl] -linker = "rust-lld" \ No newline at end of file diff --git a/src/Tools/psxcdgen_ex/src/lib.rs b/src/Tools/psxcdgen_ex/src/lib.rs index 474e8e31..7238fd3b 100644 --- a/src/Tools/psxcdgen_ex/src/lib.rs +++ b/src/Tools/psxcdgen_ex/src/lib.rs @@ -117,7 +117,7 @@ fn parse_configuration(config: config_reader::Configuration) -> Result types::File::new_regular(file.common.name.as_str(), read_file(&file.path)?)?, - config_reader::FileKind::Overlay => types::overlay::load_from(file.path)?, + config_reader::FileKind::Overlay => types::overlay::load_from(file.common.name.as_str(), file.path)?, } }; diff --git a/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs b/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs index 98d2fb0f..6c65cbc4 100644 --- a/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs +++ b/src/Tools/psxcdgen_ex/src/types/overlay/mod.rs @@ -1,7 +1,6 @@ use super::File; use std::path::PathBuf; -use byteorder::{ByteOrder, BigEndian, LittleEndian}; -use lz4::EncoderBuilder; +use byteorder::{ByteOrder, LittleEndian}; use tool_helper::{Error, format_if_error, read_file}; #[repr(packed)] @@ -17,7 +16,7 @@ impl OverlayHeader { } } -pub fn load_from(file_path: PathBuf) -> Result { +pub fn load_from(file_name: &str, file_path: PathBuf) -> Result { let overlay_header_size = std::mem::size_of::(); let mut content = read_file(&file_path)?; @@ -39,17 +38,6 @@ pub fn load_from(file_path: PathBuf) -> Result { count += 1; } - let mut lz4_encoder = EncoderBuilder::new().level(16).build(Vec::::new())?; - - std::io::copy(&mut&content[..], &mut lz4_encoder)?; - let (output, result) = lz4_encoder.finish(); - - match result { - Ok(()) => println!("Wuff: {}", output.len()), - Err(error) => { - return Err(Error::from_error(error)); - } - } - - Err(Error::not_implemented("load_from overlay")) + let content = format_if_error!(tool_helper::compress::lz4(content, 16), "Compressing {} failed with \"{error_text}\"", file_path.to_string_lossy())?; + Ok(File::new_overlay(file_name, content)?) } \ No newline at end of file diff --git a/src/Tools/tool_helper/Cargo.toml b/src/Tools/tool_helper/Cargo.toml index 10eac76f..415b0407 100644 --- a/src/Tools/tool_helper/Cargo.toml +++ b/src/Tools/tool_helper/Cargo.toml @@ -1,10 +1,11 @@ [package] name = "tool_helper" -version = "0.5.0" +version = "0.6.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] cdtypes = {path = "../cdtypes"} +lz4 = "*" paste = "*" \ No newline at end of file diff --git a/src/Tools/tool_helper/src/compress.rs b/src/Tools/tool_helper/src/compress.rs new file mode 100644 index 00000000..88377098 --- /dev/null +++ b/src/Tools/tool_helper/src/compress.rs @@ -0,0 +1,14 @@ +use super::Error; +use lz4::EncoderBuilder; + +pub fn lz4(data: Vec, compression_level: u32) -> Result, Error> { + let mut lz4_encoder = EncoderBuilder::new().level(compression_level).build(Vec::::new())?; + + std::io::copy(&mut&data[..], &mut lz4_encoder)?; + let (output, result) = lz4_encoder.finish(); + + match result { + Ok(()) => Ok(output), + Err(error) => Err(Error::from_error(error)) + } +} \ No newline at end of file diff --git a/src/Tools/tool_helper/src/lib.rs b/src/Tools/tool_helper/src/lib.rs index ab20d80e..706053c1 100644 --- a/src/Tools/tool_helper/src/lib.rs +++ b/src/Tools/tool_helper/src/lib.rs @@ -1,6 +1,7 @@ use std::{boxed::Box, io::{BufReader, BufWriter, Read, Write}, path::PathBuf}; pub mod bits; +pub mod compress; pub mod raw; pub type BufferedInputFile = BufReader;