Support LZ4 compression for external CMDs
This commit is contained in:
parent
1529e279ab
commit
90e6f40705
|
@ -88,16 +88,26 @@ fn run_internal_conversion(cmd: CommandLine) -> Result<(), Error> {
|
|||
fn run_external_conversion(cmd: CommandLine) -> Result<(), Error> {
|
||||
let input_file = cmd.input_file.ok_or(Error::from_str("Input has to be a file"))?;
|
||||
let output_file = cmd.output_file.ok_or(Error::from_str("Output has to be a file"))?;
|
||||
|
||||
if cmd.compress_lz4 {
|
||||
print_warning("LZ4 compression not supported for external commands".to_owned());
|
||||
}
|
||||
let is_xa = matches!(cmd.sub_command, SubCommands::XA(_));
|
||||
|
||||
match cmd.sub_command {
|
||||
SubCommands::VAG(args) => vag::convert(args, input_file, output_file),
|
||||
SubCommands::XA(args) => xa::convert(args, input_file, output_file),
|
||||
SubCommands::VAG(args) => vag::convert(args, input_file, output_file.clone()),
|
||||
SubCommands::XA(args) => xa::convert(args, input_file, output_file.clone()),
|
||||
_ => Err(Error::from_str("Internal functions can not be called for external conversion"))
|
||||
}?;
|
||||
|
||||
if cmd.compress_lz4 {
|
||||
if is_xa {
|
||||
print_warning(format!("File {} is of type XA and can not be compressed", output_file.to_string_lossy()));
|
||||
}
|
||||
|
||||
else {
|
||||
let compressed_file = tool_helper::compress::psx_default::lz4(&tool_helper::read_file(&output_file)?)?;
|
||||
return tool_helper::write_file(&output_file, compressed_file);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use colored::*;
|
||||
use envmnt::{ExpandOptions, ExpansionType};
|
||||
use std::{boxed::Box, io::{BufRead, BufReader, BufWriter, Read, Write}, path::PathBuf, str::FromStr};
|
||||
use std::{boxed::Box, fs::OpenOptions, io::{BufRead, BufReader, BufWriter, Read, Write}, path::PathBuf, str::FromStr};
|
||||
|
||||
pub mod bits;
|
||||
pub mod compress;
|
||||
|
@ -241,6 +241,13 @@ pub fn read_file_to_string(file_path: &PathBuf) -> Result<String, Error> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn write_file(file_path: &PathBuf, data: Vec<u8>) -> Result<(), Error> {
|
||||
let mut file = OpenOptions::new().read(true).write(true).truncate(true).create(true).open(file_path)?;
|
||||
|
||||
file.write_all(data.as_slice())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_file_read_error<T>(file_path: &PathBuf, error: std::io::Error) -> Result<T, Error> {
|
||||
Err(Error::from_text(format!("Failed reading file {} with error: \"{}\"", file_path.display(), error)))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue