bhf: disable optional output path

This commit is contained in:
dece 2020-05-23 19:20:59 +02:00
parent 4d379aa3b8
commit 3c3a9d0028
2 changed files with 3 additions and 14 deletions

View file

@ -69,7 +69,7 @@ fn main() {
.takes_value(true).required(true)) .takes_value(true).required(true))
.arg(Arg::with_name("output") .arg(Arg::with_name("output")
.help("Output directory") .help("Output directory")
.short("o").long("output").takes_value(true).required(false)) .short("o").long("output").takes_value(true).required(true))
.arg(Arg::with_name("overwrite") .arg(Arg::with_name("overwrite")
.help("Overwrite existing files") .help("Overwrite existing files")
.short("f").long("force").takes_value(false).required(false))) .short("f").long("force").takes_value(false).required(false)))
@ -199,7 +199,7 @@ fn cmd_bnd(args: &ArgMatches) -> i32 {
fn cmd_bhf(args: &ArgMatches) -> i32 { fn cmd_bhf(args: &ArgMatches) -> i32 {
let file_path: &str = args.value_of("file").unwrap(); let file_path: &str = args.value_of("file").unwrap();
let output_path: Option<&str> = args.value_of("output"); let output_path: &str = args.value_of("output").unwrap();
let overwrite: bool = args.is_present("overwrite"); let overwrite: bool = args.is_present("overwrite");
match unpackers::bhf::extract_bhf_file(file_path, output_path, overwrite) { match unpackers::bhf::extract_bhf_file(file_path, output_path, overwrite) {
Err(e) => { eprintln!("Failed to extract BHF: {:?}", e); 1 } Err(e) => { eprintln!("Failed to extract BHF: {:?}", e); 1 }

View file

@ -11,11 +11,9 @@ use crate::utils::fs as utils_fs;
/// Extract BHF file and corresponding BDT contents to disk. /// Extract BHF file and corresponding BDT contents to disk.
/// ///
/// Wraps around `extract_bhf` to load the BHF file from disk. /// Wraps around `extract_bhf` to load the BHF file from disk.
/// If output_dir is none, entries will be extracted relatively to the
/// BHF path.
pub fn extract_bhf_file( pub fn extract_bhf_file(
bhf_path: &str, bhf_path: &str,
output_dir: Option<&str>, output_dir: &str,
overwrite: bool overwrite: bool
) -> Result<(), UnpackError> { ) -> Result<(), UnpackError> {
let bhf = load_bhf_file(bhf_path)?; let bhf = load_bhf_file(bhf_path)?;
@ -30,15 +28,6 @@ pub fn extract_bhf_file(
}; };
let bdt_data = utils_fs::open_file_to_vec(&bdt_path)?; let bdt_data = utils_fs::open_file_to_vec(&bdt_path)?;
let output_dir: &str = if output_dir.is_none() {
let parent = path::Path::new(bhf_path).parent();
if parent.is_none() {
return Err(UnpackError::Naming(format!("Can't find BHF parent dir: {:?}", bhf_path)))
}
parent.unwrap().to_str().unwrap() // Conversion should not fail as bhf_path is valid.
} else {
output_dir.unwrap()
};
extract_bhf(&bhf, &bdt_data, output_dir, overwrite)?; extract_bhf(&bhf, &bdt_data, output_dir, overwrite)?;
Ok(()) Ok(())
} }