Make fconv delete faulty files

This commit is contained in:
Jaby
2023-10-12 14:03:44 +02:00
committed by Jaby
parent b1c9fd93c9
commit 7db63b0f66
11 changed files with 1014 additions and 995 deletions

View File

@@ -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"}

View File

@@ -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();

View File

@@ -1 +1,2 @@
pub mod images;
pub mod images;
pub mod nothing;

View File

@@ -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

View 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(())
}