feat: add experimental cli

This commit is contained in:
鲁树人
2024-09-04 21:31:28 +01:00
parent 1a282c0912
commit 2c53e4d950
7 changed files with 246 additions and 3 deletions

9
um_cli/src/cmd/mod.rs Normal file
View File

@@ -0,0 +1,9 @@
use clap::Subcommand;
pub mod qmc1;
#[derive(Subcommand)]
pub enum Commands {
#[command(name = "qmc1")]
QMCv1(qmc1::ArgsQMCv1),
}

41
um_cli/src/cmd/qmc1.rs Normal file
View File

@@ -0,0 +1,41 @@
use anyhow::Result;
use clap::Args;
use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
/// Decrypt a QMCv1 file
#[derive(Args)]
pub struct ArgsQMCv1 {
/// Path to output file, e.g. /export/Music/song.flac
#[clap(short, long)]
output: PathBuf,
/// Path to input file, e.g. /export/Music/song.qmcflac
#[arg(name = "input")]
input: PathBuf,
}
// 4MiB buffer is working well on my machine.
const BUFFER_SIZE: usize = 4 * 1024 * 1024;
impl ArgsQMCv1 {
pub fn run(&self) -> Result<i32> {
let mut file_input = File::open(&self.input)?;
let mut file_output = File::create(&self.output)?;
let mut offset = 0usize;
let mut buffer = vec![0u8; BUFFER_SIZE].into_boxed_slice();
while let Ok(n) = file_input.read(&mut buffer) {
if n == 0 {
break;
}
umc_qmc::v1::decrypt(&mut buffer[..n], offset);
file_output.write_all(&buffer[..n])?;
offset += n;
}
Ok(0)
}
}