Make fconv delete faulty files
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
[package]
|
||||
name = "jaby_engine_fconv"
|
||||
version = "0.1.4"
|
||||
edition = "2021"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
clap = {version = "*", features = ["derive"]}
|
||||
image = "*"
|
||||
paste = "*"
|
||||
png = "*"
|
||||
[package]
|
||||
name = "jaby_engine_fconv"
|
||||
version = "0.1.5"
|
||||
edition = "2021"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
clap = {version = "*", features = ["derive"]}
|
||||
image = "*"
|
||||
paste = "*"
|
||||
png = "*"
|
||||
tool_helper = {path = "../tool_helper"}
|
||||
@@ -64,9 +64,7 @@ fn modify_palette(mut image: IndexedImage, clut_align: ClutAlignment, semi_trans
|
||||
fn encode<T: PSXImageConverter>(image: T, color_depth: ColorType, clut_align: ClutAlignment, output: &mut dyn Write) -> Result<(), Error> {
|
||||
let (width, height) = {
|
||||
fn return_error(clut_type: u32, div: u32, width: u16, height: u16) -> Result<(u16, u16), Error> {
|
||||
return Err(Error::from_callback(|| {format!("CLUT {} images require a width divideable by {} (found width: {}/{}={}, height: {}/{}={})", clut_type, div,
|
||||
width, div, (width as f32/div as f32),
|
||||
height, div, (height as f32/div as f32))}));
|
||||
return Err(Error::from_callback(|| {format!("CLUT {} images require a width divideable by {} (found width: {}/{}={}, height: {})", clut_type, div, width, div, (width as f32/div as f32), height)}));
|
||||
}
|
||||
|
||||
let width = image.width();
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod images;
|
||||
pub mod images;
|
||||
pub mod nothing;
|
||||
@@ -1,5 +1,5 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
use jaby_engine_fconv::images::*;
|
||||
use jaby_engine_fconv::{images::*, nothing};
|
||||
use std::path::PathBuf;
|
||||
use tool_helper::{Error, exit_with_error};
|
||||
|
||||
@@ -28,7 +28,7 @@ enum SubCommands {
|
||||
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||
let mut 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 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
|
||||
@@ -39,13 +39,23 @@ fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||
}
|
||||
};
|
||||
|
||||
match cmd.sub_command {
|
||||
SubCommands::Nothing => {
|
||||
std::io::copy(&mut input, dst_buffer)?;
|
||||
},
|
||||
SubCommands::SimpleTIM(args) => {
|
||||
reduced_tim::convert(args, input, dst_buffer)?;
|
||||
let cmd_result: Result<(), Error> = {
|
||||
match cmd.sub_command {
|
||||
SubCommands::Nothing => nothing::copy(&mut input, dst_buffer),
|
||||
SubCommands::SimpleTIM(args) => reduced_tim::convert(args, input, dst_buffer)
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(cmd_error) = cmd_result {
|
||||
if let Some(file_path) = cmd.output_file {
|
||||
let _result = std::fs::remove_file(file_path);
|
||||
}
|
||||
|
||||
else {
|
||||
tool_helper::print_warning("Open stream detected! Incomplete file can not be deleted".to_owned());
|
||||
}
|
||||
|
||||
return Err(cmd_error);
|
||||
}
|
||||
|
||||
// We encoded the file to a temporary buffer and now need to write it
|
||||
|
||||
7
src/Tools/jaby_engine_fconv/src/nothing/mod.rs
Normal file
7
src/Tools/jaby_engine_fconv/src/nothing/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use std::io::Write;
|
||||
use tool_helper::{Error, Input};
|
||||
|
||||
pub fn copy(input: &mut Input, output: &mut dyn Write) -> Result<(), Error> {
|
||||
std::io::copy(input, output)?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user