use std::path::PathBuf;
use argp::FromArgs;
use nod::{
read::{DiscOptions, PartitionEncryption},
write::FormatOptions,
};
use crate::util::{redump, shared::convert_and_verify};
#[derive(FromArgs, Debug)]
#[argp(subcommand, name = "verify")]
pub struct Args {
#[argp(positional)]
file: Vec<PathBuf>,
#[argp(switch)]
md5: bool,
#[argp(option, short = 'd')]
dat: Vec<PathBuf>,
#[argp(switch)]
decrypt: bool,
#[argp(switch)]
encrypt: bool,
}
pub fn run(args: Args) -> nod::Result<()> {
if !args.dat.is_empty() {
println!("Loading dat files...");
redump::load_dats(args.dat.iter().map(PathBuf::as_ref))?;
}
let options = DiscOptions {
partition_encryption: match (args.decrypt, args.encrypt) {
(true, false) => PartitionEncryption::ForceDecrypted,
(false, true) => PartitionEncryption::ForceEncrypted,
(false, false) => PartitionEncryption::Original,
(true, true) => {
return Err(nod::Error::Other(
"Both --decrypt and --encrypt specified".to_string(),
));
}
},
#[cfg(feature = "threading")]
preloader_threads: 4.min(num_cpus::get()),
};
let format_options = FormatOptions::default();
for file in &args.file {
convert_and_verify(file, None, args.md5, false, &options, &format_options)?;
println!();
}
Ok(())
}