Seperate between internal and external conversion

This commit is contained in:
Jaby
2024-05-21 19:30:54 +02:00
committed by Jaby
parent 21f89cfad2
commit d128a6001a
5 changed files with 49 additions and 12 deletions

View File

@@ -1,10 +1,27 @@
use clap::Args;
use std::io::Write;
use tool_helper::{Error, Input};
use clap::{Args, ValueEnum};
use std::path::PathBuf;
use tool_helper::Error;
#[derive(Args)]
pub struct Arguments {}
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
}
pub fn convert(_args: Arguments, _input: Input, _output: &mut dyn Write) -> Result<(), Error> {
#[derive(Copy, Clone, ValueEnum)]
pub enum Quality {
Low,
High
}
#[derive(Copy, Clone, ValueEnum)]
pub enum Sample {
Mono,
Stereo
}
pub fn convert(_args: Arguments, _input: PathBuf, _output: PathBuf) -> Result<(), Error> {
Err(Error::not_implemented("XA Audio convert"))
}

View File

@@ -26,8 +26,8 @@ enum SubCommands {
XA(xa::Arguments)
}
fn run_main(cmd: CommandLine) -> Result<(), Error> {
let mut input = tool_helper::open_input(cmd.input_file)?;
fn run_internal_conversion(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 dst_buffer = {
@@ -44,7 +44,7 @@ fn run_main(cmd: CommandLine) -> Result<(), Error> {
match cmd.sub_command {
SubCommands::Nothing => nothing::copy(&mut input, dst_buffer),
SubCommands::SimpleTIM(args) => reduced_tim::convert(args, input, dst_buffer),
SubCommands::XA(args) => xa::convert(args, input, dst_buffer),
_ => Err(Error::not_implemented("External functions can not be called internal"))
}
};
@@ -66,7 +66,27 @@ fn run_main(cmd: CommandLine) -> Result<(), Error> {
output_file.write(&buffer)?;
}
Ok(())
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"))?;
match cmd.sub_command {
SubCommands::XA(args) => xa::convert(args, input_file, output_file),
_ => Err(Error::not_implemented("Internal functions can not be called external"))
}
}
fn run_main(cmd: CommandLine) -> Result<(), Error> {
if matches!(cmd.sub_command, SubCommands::XA(_)) {
run_external_conversion(cmd)
}
else {
run_internal_conversion(cmd)
}
}
fn main() {