From 9b8921bb4785bdf8a4bee59aeb954c2f1aaf9f2f Mon Sep 17 00:00:00 2001 From: jaby Date: Tue, 17 Dec 2024 20:52:06 +0100 Subject: [PATCH] Remove old XA conversion support --- src/Tools/psxfileconv/src/audio/mod.rs | 44 +--------------- src/Tools/psxfileconv/src/audio/xa/mod.rs | 55 -------------------- src/Tools/psxfileconv/src/main.rs | 61 ++--------------------- 3 files changed, 6 insertions(+), 154 deletions(-) delete mode 100644 src/Tools/psxfileconv/src/audio/xa/mod.rs diff --git a/src/Tools/psxfileconv/src/audio/mod.rs b/src/Tools/psxfileconv/src/audio/mod.rs index 677cedea..be2c4c30 100644 --- a/src/Tools/psxfileconv/src/audio/mod.rs +++ b/src/Tools/psxfileconv/src/audio/mod.rs @@ -1,44 +1,2 @@ pub mod my_xa; -pub mod vag; -pub mod xa; - -use std::{env, path::PathBuf, process::Command}; -use tool_helper::Error; - -fn run_psxavenc(input: PathBuf, output: PathBuf, args: I) -> Result<(), Error> -where - I: IntoIterator, - S: AsRef, { - let psxavenc = get_psxavenc_path()?; - let result = Command::new(psxavenc).args(args).arg(input.to_string_lossy().as_ref()).arg(output.to_string_lossy().as_ref()).output()?; - - let stderr = tool_helper::vec_helper::to_string(result.stderr)?; - let stdout = tool_helper::vec_helper::to_string(result.stdout)?; - - if !result.status.success() { - return Err(Error::from_text(format!("psxavenc returned: {}. {}", result.status, stderr))); - } - - if !stdout.is_empty() { - println!("{}", stdout); - } - Ok(()) -} - -fn get_psxavenc_path() -> Result { - let tool_path = { - let mut my_path = env::current_exe()?; - - my_path.pop(); - my_path.push("extern"); - my_path.push("psxavenc"); - - my_path - }; - - if !tool_path.exists() { - return Err(Error::from_str("Could not locate psxavenc. Make sure it is installed under \"/bin/extern\"")); - } - - Ok(tool_path) -} \ No newline at end of file +pub mod vag; \ No newline at end of file diff --git a/src/Tools/psxfileconv/src/audio/xa/mod.rs b/src/Tools/psxfileconv/src/audio/xa/mod.rs deleted file mode 100644 index 82a66ed4..00000000 --- a/src/Tools/psxfileconv/src/audio/xa/mod.rs +++ /dev/null @@ -1,55 +0,0 @@ -use clap::{Args, ValueEnum}; -use std::{path::PathBuf, str}; -use tool_helper::Error; - -#[derive(Args)] -pub struct Arguments { - #[clap(value_enum, value_parser, default_value_t=Quality::High)] - quality: Quality, - #[clap(value_enum, value_parser, default_value_t=Sample::Stereo)] - sample: Sample -} - -#[derive(Copy, Clone, ValueEnum)] -pub enum Quality { - Low, - High -} - -impl Quality { - fn get_frequency(&self) -> u64 { - match self { - Self::Low => 18900, - Self::High => 37800, - } - } -} - -#[derive(Copy, Clone, ValueEnum)] -pub enum Sample { - Mono, - Stereo -} - -impl Sample { - fn get_channel(&self) -> u64 { - match self { - Self::Mono => 1, - Self::Stereo => 2, - } - } -} - -pub fn convert(args: Arguments, input: PathBuf, output: PathBuf) -> Result<(), Error> { - let quality = args.quality; - let sample = args.sample; - - super::run_psxavenc(input, output, [ - "-t", "xacd", - "-f", quality.get_frequency().to_string().as_ref(), - "-b", "4", - "-c", sample.get_channel().to_string().as_ref(), - "-F", "0", - "-C", "0", - ]) -} \ No newline at end of file diff --git a/src/Tools/psxfileconv/src/main.rs b/src/Tools/psxfileconv/src/main.rs index da407a47..5c1d9fbb 100644 --- a/src/Tools/psxfileconv/src/main.rs +++ b/src/Tools/psxfileconv/src/main.rs @@ -1,7 +1,7 @@ use clap::{Parser, Subcommand}; use psxfileconv::{audio::{self, *}, images::*, nothing}; use std::path::PathBuf; -use tool_helper::{exit_with_error, print_warning, Error}; +use tool_helper::{exit_with_error, Error}; #[derive(Parser)] #[clap(about = "Converts files to various JabyEngine related file formats", long_about = None)] @@ -25,26 +25,10 @@ enum SubCommands { Nothing, SimpleTIM(reduced_tim::Arguments), VAG(vag::Arguments), - MyXA(my_xa::Arguments), - - // === External Commands === - XA(xa::Arguments), + XA(my_xa::Arguments), } -impl SubCommands { - pub fn is_external_command(&self) -> bool { - match self { - SubCommands::Nothing => false, - SubCommands::SimpleTIM(_) => false, - SubCommands::VAG(_) => false, - SubCommands::MyXA(_) => false, - - SubCommands::XA(_) => true - } - } -} - -fn run_internal_conversion(cmd: CommandLine) -> Result<(), Error> { +fn run_main(cmd: CommandLine) -> Result<(), Error> { let mut input = tool_helper::open_input(&cmd.input_file)?; let mut buffer = Vec::::new(); let mut output_file = tool_helper::open_output(&cmd.output_file)?; @@ -63,8 +47,7 @@ fn run_internal_conversion(cmd: CommandLine) -> Result<(), Error> { SubCommands::Nothing => nothing::copy(&mut input, dst_buffer), SubCommands::SimpleTIM(args) => reduced_tim::convert(args, input, dst_buffer), SubCommands::VAG(args) => audio::vag::convert(args, &cmd.output_file, input, dst_buffer), - SubCommands::MyXA(args) => audio::my_xa::convert(args, input, dst_buffer), - _ => Err(Error::from_str("External functions can not be called for internal conversion")) + SubCommands::XA(args) => audio::my_xa::convert(args, input, dst_buffer), } }; @@ -86,41 +69,7 @@ fn run_internal_conversion(cmd: CommandLine) -> Result<(), Error> { output_file.write(&buffer)?; } - Ok(()) -} - -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"))?; - let is_xa = matches!(cmd.sub_command, SubCommands::XA(_)); - - match cmd.sub_command { - 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> { - if cmd.sub_command.is_external_command() { - run_external_conversion(cmd) - } - - else { - run_internal_conversion(cmd) - } + Ok(()) } fn main() {