Seperate between internal and external conversion
This commit is contained in:
parent
df36c2cd92
commit
49417295fc
|
@ -34,7 +34,7 @@ fn configurate(cmd: &mut CommandLine) -> Result<Configuration, Error> {
|
|||
|
||||
fn run_main(mut cmd: CommandLine) -> Result<(), Error> {
|
||||
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))?;
|
||||
|
||||
return cpp_out::convert(cfg, input, output);
|
||||
|
|
|
@ -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"))
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -18,7 +18,7 @@ struct CommandLine {
|
|||
|
||||
fn parse_input(input: Option<PathBuf>) -> Result<OverlayDesc, Error> {
|
||||
if let Some(input) = input {
|
||||
let input = format_if_error!(open_input(Some(input)), "Opening input file failed with: {error_text}")?;
|
||||
let input = format_if_error!(open_input(&Some(input)), "Opening input file failed with: {error_text}")?;
|
||||
format_if_error!(mkoverlay::types::json_reader::read_config(input), "Parsing JSON file failed with: {error_text}")
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ pub fn open_output(output_file: &Option<PathBuf>) -> Result<Output, Error> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn open_input(input_file: Option<PathBuf>) -> Result<Input, Error> {
|
||||
pub fn open_input(input_file: &Option<PathBuf>) -> Result<Input, Error> {
|
||||
match input_file {
|
||||
Some(input_path) => Ok(Box::new(open_input_file_buffered(&input_path)?)),
|
||||
None => Ok(Box::new(BufReader::new(std::io::stdin()))),
|
||||
|
|
Loading…
Reference in New Issue