Remove old XA conversion support
This commit is contained in:
parent
f32e94f0f3
commit
9b8921bb47
|
@ -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<I, S>(input: PathBuf, output: PathBuf, args: I) -> Result<(), Error>
|
||||
where
|
||||
I: IntoIterator<Item = S>,
|
||||
S: AsRef<std::ffi::OsStr>, {
|
||||
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<PathBuf, Error> {
|
||||
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 \"<Jaby Engine>/bin/extern\""));
|
||||
}
|
||||
|
||||
Ok(tool_path)
|
||||
}
|
|
@ -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",
|
||||
])
|
||||
}
|
|
@ -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::<u8>::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),
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -89,40 +72,6 @@ fn run_internal_conversion(cmd: CommandLine) -> Result<(), Error> {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match CommandLine::try_parse() {
|
||||
Ok(cmd) => {
|
||||
|
|
Loading…
Reference in New Issue