Make jaby_engine_fconv output lz4 files on request

This commit is contained in:
Jaby
2022-12-27 20:58:43 +01:00
committed by Jaby
parent c995fe0713
commit 4917d07270
5 changed files with 51 additions and 20 deletions

View File

@@ -6,6 +6,9 @@ use tool_helper::Error;
#[derive(Parser)]
#[clap(about = "Converts files to various JabyEngine related file formats", long_about = None)]
struct CommandLine {
#[clap(long="lz4", default_value_t=false)]
compress_lz4: bool,
#[clap(short='o')]
output_file: Option<PathBuf>,
@@ -24,14 +27,42 @@ enum SubCommands {
fn run_main() -> Result<(), Error> {
match CommandLine::try_parse() {
Ok(cmd) => {
let input = tool_helper::open_input(cmd.input_file)?;
let output = tool_helper::open_output(cmd.output_file)?;
let input = tool_helper::open_input(cmd.input_file)?;
let mut buffer = Vec::<u8>::new();
let mut output_file = tool_helper::open_output(cmd.output_file)?;
let dst_buffer = {
if cmd.compress_lz4 {
&mut buffer as &mut dyn std::io::Write
}
else {
&mut output_file as &mut dyn std::io::Write
}
};
match cmd.sub_command {
SubCommands::SimpleTIM(args) => reduced_tim::convert(args, input, output),
SubCommands::SimpleTIM(args) => {
reduced_tim::convert(args, input, dst_buffer)?;
}
}
// We encoded the file to a temporary buffer and now need to write it
if cmd.compress_lz4 {
println!("Buffer-Size: {} ({} Sectors)", buffer.len(), (buffer.len() + 2047)/2048);
let buffer = tool_helper::compress::lz4(&buffer, 16)?;
println!("New buffer-Size: {} ({} Sectors)", buffer.len(), (buffer.len() + 2047)/2048);
output_file.write(&buffer)?;
}
Ok(())
},
Err(error) => Err(Error::from_error(error))
Err(error) => Err({
let mut error = Error::from_error(error);
error.exit_code = 0;
error
})
}
}