From 1f5ec80cc65c37bdb70f18d77cf1764d80165f24 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Thu, 2 Nov 2023 20:56:46 +0100 Subject: [PATCH] Add optional destination dir for OSB file extraction --- src/cli.rs | 2 ++ src/main.rs | 14 +++++++++++--- src/unzip_osb.rs | 9 +++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index cbdfd2d..6f574ee 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -111,5 +111,7 @@ pub enum SubCommand { help = "Passwort der OSB-Datei (Optional)" )] password: Option, + #[arg(short = 'd', help = "Zielverzeichnis (Optional)")] + dir: Option, }, } diff --git a/src/main.rs b/src/main.rs index 21194e5..523a503 100644 --- a/src/main.rs +++ b/src/main.rs @@ -259,11 +259,19 @@ fn main() -> Result<(), Box> { }; } #[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()), } } }; diff --git a/src/unzip_osb.rs b/src/unzip_osb.rs index 334517b..129996c 100644 --- a/src/unzip_osb.rs +++ b/src/unzip_osb.rs @@ -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()); }