Make fconv delete faulty files
This commit is contained in:
parent
7ceb13863e
commit
e37321de89
|
@ -35,7 +35,7 @@ fn configurate(cmd: &mut CommandLine) -> Result<Configuration, Error> {
|
||||||
fn run_main(mut cmd: CommandLine) -> Result<(), Error> {
|
fn run_main(mut cmd: CommandLine) -> Result<(), Error> {
|
||||||
let cfg = configurate(&mut cmd)?;
|
let cfg = configurate(&mut cmd)?;
|
||||||
let input = tool_helper::open_input(cmd.input_file)?;
|
let input = tool_helper::open_input(cmd.input_file)?;
|
||||||
let output = tool_helper::open_output(Some(cmd.output_file))?;
|
let output = tool_helper::open_output(&Some(cmd.output_file))?;
|
||||||
|
|
||||||
return cpp_out::convert(cfg, input, output);
|
return cpp_out::convert(cfg, input, output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "jaby_engine_fconv"
|
name = "jaby_engine_fconv"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
@ -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> {
|
fn encode<T: PSXImageConverter>(image: T, color_depth: ColorType, clut_align: ClutAlignment, output: &mut dyn Write) -> Result<(), Error> {
|
||||||
let (width, height) = {
|
let (width, height) = {
|
||||||
fn return_error(clut_type: u32, div: u32, width: u16, height: u16) -> Result<(u16, u16), Error> {
|
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,
|
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)}));
|
||||||
width, div, (width as f32/div as f32),
|
|
||||||
height, div, (height as f32/div as f32))}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let width = image.width();
|
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 clap::{Parser, Subcommand};
|
||||||
use jaby_engine_fconv::images::*;
|
use jaby_engine_fconv::{images::*, nothing};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tool_helper::{Error, exit_with_error};
|
use tool_helper::{Error, exit_with_error};
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ enum SubCommands {
|
||||||
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||||
let mut input = tool_helper::open_input(cmd.input_file)?;
|
let mut input = tool_helper::open_input(cmd.input_file)?;
|
||||||
let mut buffer = Vec::<u8>::new();
|
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 = {
|
let dst_buffer = {
|
||||||
if cmd.compress_lz4 {
|
if cmd.compress_lz4 {
|
||||||
&mut buffer as &mut dyn std::io::Write
|
&mut buffer as &mut dyn std::io::Write
|
||||||
|
@ -39,13 +39,23 @@ fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let cmd_result: Result<(), Error> = {
|
||||||
match cmd.sub_command {
|
match cmd.sub_command {
|
||||||
SubCommands::Nothing => {
|
SubCommands::Nothing => nothing::copy(&mut input, dst_buffer),
|
||||||
std::io::copy(&mut input, dst_buffer)?;
|
SubCommands::SimpleTIM(args) => reduced_tim::convert(args, 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
|
// We encoded the file to a temporary buffer and now need to write it
|
||||||
|
|
|
@ -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(())
|
||||||
|
}
|
|
@ -29,8 +29,8 @@ fn parse_input(input: Option<PathBuf>) -> Result<OverlayDesc, Error> {
|
||||||
|
|
||||||
fn run_main(cmd_line: CommandLine) -> Result<(), Error> {
|
fn run_main(cmd_line: CommandLine) -> Result<(), Error> {
|
||||||
let input = parse_input(cmd_line.input)?;
|
let input = parse_input(cmd_line.input)?;
|
||||||
let mut mk_output = format_if_error!(open_output(cmd_line.mk_file_output), "Opening file for writing makefile failed with: {error_text}")?;
|
let mut mk_output = format_if_error!(open_output(&cmd_line.mk_file_output), "Opening file for writing makefile failed with: {error_text}")?;
|
||||||
let mut ld_output = format_if_error!(open_output(cmd_line.ld_file_output), "Opening file for writing linkerfile failed with: {error_text}")?;
|
let mut ld_output = format_if_error!(open_output(&cmd_line.ld_file_output), "Opening file for writing linkerfile failed with: {error_text}")?;
|
||||||
|
|
||||||
format_if_error!(mkoverlay::creator::makefile::write(&mut mk_output, &input), "Writing makefile failed with: {error_text}")?;
|
format_if_error!(mkoverlay::creator::makefile::write(&mut mk_output, &input), "Writing makefile failed with: {error_text}")?;
|
||||||
format_if_error!(mkoverlay::creator::ldscript::write(&mut ld_output, &input), "Writing ld script failed with: {error_text}")
|
format_if_error!(mkoverlay::creator::ldscript::write(&mut ld_output, &input), "Writing ld script failed with: {error_text}")
|
||||||
|
|
|
@ -2,8 +2,7 @@ use super::{*, SectorWriter, {CDDesc, Error}};
|
||||||
use super::super::types::{helper::{DirectoryRecordMember, PathTableMember}, layout::Layout, *};
|
use super::super::types::{helper::{DirectoryRecordMember, PathTableMember}, layout::Layout, *};
|
||||||
use builder::SubModeBuilder;
|
use builder::SubModeBuilder;
|
||||||
use cdtypes::types::{cdstring::{AString, DString}, date::*, dir_record::*, helper::{round_bytes_mode2_form1, sector_count_mode2_form1}, path_table::*, pvd as cd_pvd, lsb_msb::*, sector::Mode2Form1};
|
use cdtypes::types::{cdstring::{AString, DString}, date::*, dir_record::*, helper::{round_bytes_mode2_form1, sector_count_mode2_form1}, path_table::*, pvd as cd_pvd, lsb_msb::*, sector::Mode2Form1};
|
||||||
use colored::*;
|
use tool_helper::{BufferedInputFile, format_if_error, open_input_file_buffered, print_warning};
|
||||||
use tool_helper::{BufferedInputFile, format_if_error, open_input_file_buffered};
|
|
||||||
use std::io::{Read, Seek, SeekFrom};
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
|
|
||||||
const ROOT_DIR_NAME:&'static str = "\x00";
|
const ROOT_DIR_NAME:&'static str = "\x00";
|
||||||
|
@ -199,7 +198,7 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
|
||||||
|
|
||||||
else {
|
else {
|
||||||
// No license specified - filling it with zeros
|
// No license specified - filling it with zeros
|
||||||
eprintln!("{}", "WARNING: No license file provided. Some emulators (like No$PSX) will not boot this CD.".yellow());
|
print_warning("WARNING: No license file provided. Some emulators (like No$PSX) will not boot this CD.".to_owned());
|
||||||
for _ in 0..SYSTEM_AREA_SECTOR_COUNT {
|
for _ in 0..SYSTEM_AREA_SECTOR_COUNT {
|
||||||
sec_writer.write_cd_xa_data(builder::create_xa_data_zero())?;
|
sec_writer.write_cd_xa_data(builder::create_xa_data_zero())?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ fn run_main(cmd_line: CommandLine) -> Result<(), Error> {
|
||||||
write_image(&desc, encoding_functions.encoder, cmd_line.output_type, cmd_line.output_file)?;
|
write_image(&desc, encoding_functions.encoder, cmd_line.output_type, cmd_line.output_file)?;
|
||||||
|
|
||||||
if let Some(list_content_option) = cmd_line.list_content {
|
if let Some(list_content_option) = cmd_line.list_content {
|
||||||
psxcdgen_ex::dump_content(&desc, tool_helper::open_output(list_content_option)?)
|
psxcdgen_ex::dump_content(&desc, tool_helper::open_output(&list_content_option)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub fn main() {
|
||||||
|
|
||||||
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||||
if cmd.raw_dump {
|
if cmd.raw_dump {
|
||||||
psxreadmap::get_tool_output(cmd.use_wsl, cmd.input, open_output(cmd.output)?)?;
|
psxreadmap::get_tool_output(cmd.use_wsl, cmd.input, open_output(&cmd.output)?)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||||
|
|
||||||
fn dump_memory_map(output: Option<PathBuf>, memory_map: &readmap::types::MemoryMap) -> Result<(), Error> {
|
fn dump_memory_map(output: Option<PathBuf>, memory_map: &readmap::types::MemoryMap) -> Result<(), Error> {
|
||||||
if let Some(output) = output {
|
if let Some(output) = output {
|
||||||
let output = tool_helper::open_output(Some(output))?;
|
let output = tool_helper::open_output(&Some(output))?;
|
||||||
|
|
||||||
readmap::dump::write(output, &memory_map)?;
|
readmap::dump::write(output, &memory_map)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,10 @@ pub fn exit_with_error(error: Error) {
|
||||||
std::process::exit(error.exit_code);
|
std::process::exit(error.exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn print_warning(str: String) {
|
||||||
|
eprintln!("{}", str.yellow());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn prefix_if_error<T>(prefix: &str, result: Result<T, Error>) -> Result<T, Error> {
|
pub fn prefix_if_error<T>(prefix: &str, result: Result<T, Error>) -> Result<T, Error> {
|
||||||
match result {
|
match result {
|
||||||
Ok(value) => Ok(value),
|
Ok(value) => Ok(value),
|
||||||
|
@ -166,7 +170,7 @@ pub fn open_output_file(output_path: &PathBuf) -> Result<BufWriter<std::fs::File
|
||||||
Ok(std::io::BufWriter::new(std::fs::File::create(output_path)?))
|
Ok(std::io::BufWriter::new(std::fs::File::create(output_path)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_output(output_file: Option<PathBuf>) -> Result<Output, Error> {
|
pub fn open_output(output_file: &Option<PathBuf>) -> Result<Output, Error> {
|
||||||
match output_file {
|
match output_file {
|
||||||
Some(output_path) => Ok(Box::new(open_output_file(&output_path)?)),
|
Some(output_path) => Ok(Box::new(open_output_file(&output_path)?)),
|
||||||
None => Ok(Box::new(BufWriter::new(std::io::stdout()))),
|
None => Ok(Box::new(BufWriter::new(std::io::stdout()))),
|
||||||
|
|
Loading…
Reference in New Issue