1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-19 19:56:50 +00:00

Add optional destination dir for OSB file extraction

This commit is contained in:
Paul-Christian Volkmer 2023-11-02 20:56:46 +01:00
parent f851e9c424
commit 1f5ec80cc6
3 changed files with 18 additions and 7 deletions

View File

@ -111,5 +111,7 @@ pub enum SubCommand {
help = "Passwort der OSB-Datei (Optional)"
)]
password: Option<String>,
#[arg(short = 'd', help = "Zielverzeichnis (Optional)")]
dir: Option<String>,
},
}

View File

@ -259,11 +259,19 @@ fn main() -> Result<(), Box<dyn Error>> {
};
}
#[cfg(feature = "unzip-osb")]
SubCommand::UnzipOsb { file, password } => {
SubCommand::UnzipOsb {
file,
password,
dir,
} => {
use crate::unzip_osb::unzip_osb;
match password {
Some(password) => unzip_osb_using_password(file.as_str(), password.as_str()),
None => unzip_osb(file.as_str()),
Some(password) => unzip_osb_using_password(
file.as_str(),
dir.unwrap_or_default().as_str(),
password.as_str(),
),
None => unzip_osb(file.as_str(), dir.unwrap_or_default().as_str()),
}
}
};

View File

@ -24,6 +24,7 @@
use console::style;
use deob::deobfuscate;
use std::path::Path;
use std::{fs, io};
macro_rules! started {
@ -48,7 +49,7 @@ macro_rules! error {
};
}
pub fn unzip_osb_using_password(path: &str, password: &str) {
pub fn unzip_osb_using_password(path: &str, dir: &str, password: &str) {
println!("Entpacke OSB-Datei {}\n", style(path).yellow());
let file = match fs::File::open(path) {
@ -87,7 +88,7 @@ pub fn unzip_osb_using_password(path: &str, password: &str) {
};
let outpath = match file.enclosed_name() {
Some(path) => path.to_owned(),
Some(path) => Path::new(dir).join(path.to_owned()),
None => continue,
};
@ -129,6 +130,6 @@ pub fn unzip_osb_using_password(path: &str, password: &str) {
}
}
pub fn unzip_osb(path: &str) {
unzip_osb_using_password(path, deobfuscate(env!("OSB_KEY").trim()).as_str());
pub fn unzip_osb(path: &str, dir: &str) {
unzip_osb_using_password(path, dir, deobfuscate(env!("OSB_KEY").trim()).as_str());
}