mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-15 21:00:03 +02:00
cleanup main
This commit is contained in:
+15
-15
@@ -11,7 +11,7 @@ use crate::formats::{Format, get_registry};
|
|||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Args {
|
struct Args {
|
||||||
input_target: String,
|
input_target: String,
|
||||||
output_folder: Option<String>,
|
output_directory: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppContext<'a> {
|
pub struct AppContext<'a> {
|
||||||
@@ -23,21 +23,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
println!("unixtract Firmware extractor");
|
println!("unixtract Firmware extractor");
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let target_path = args.input_target;
|
let target_path_str = args.input_target;
|
||||||
println!("Input target: {}", target_path);
|
println!("Input target: {}", target_path_str);
|
||||||
let path = PathBuf::from(target_path);
|
let target_path = PathBuf::from(&target_path_str);
|
||||||
|
|
||||||
let output_path = if args.output_folder.is_some() {
|
let output_path_str = if args.output_directory.is_some() {
|
||||||
args.output_folder.unwrap()
|
args.output_directory.unwrap()
|
||||||
} else {
|
} else {
|
||||||
format!("_{}", path.file_name().and_then(|s| s.to_str()).unwrap())
|
format!("_{}", target_path.file_name().and_then(|s| s.to_str()).unwrap())
|
||||||
};
|
};
|
||||||
println!("Output folder: {}\n", output_path);
|
println!("Output directory: {}\n", output_path_str);
|
||||||
|
let output_directory_path = PathBuf::from(&output_path_str);
|
||||||
|
|
||||||
let output_folder_path = PathBuf::from(&output_path);
|
if output_directory_path.exists() {
|
||||||
if output_folder_path.exists() {
|
if output_directory_path.is_dir() {
|
||||||
if output_folder_path.is_dir() {
|
let is_empty = fs::read_dir(&output_directory_path)?.next().is_none();
|
||||||
let is_empty = fs::read_dir(&output_folder_path)?.next().is_none();
|
|
||||||
if !is_empty {
|
if !is_empty {
|
||||||
println!("Warning: Output folder already exists and is NOT empty! Files may be overwritten!");
|
println!("Warning: Output folder already exists and is NOT empty! Files may be overwritten!");
|
||||||
println!("Press Enter if you want to continue...");
|
println!("Press Enter if you want to continue...");
|
||||||
@@ -46,10 +46,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let file = File::open(path)?;
|
let file = File::open(target_path)?;
|
||||||
let app_ctx: AppContext = AppContext { file: &file, output_dir: &output_path };
|
let app_ctx: AppContext = AppContext { file: &file, output_dir: &output_path_str };
|
||||||
let formats: Vec<Format> = get_registry();
|
|
||||||
|
|
||||||
|
let formats: Vec<Format> = get_registry();
|
||||||
for format in formats {
|
for format in formats {
|
||||||
if let Some(ctx) = (format.detector_func)(&app_ctx)? {
|
if let Some(ctx) = (format.detector_func)(&app_ctx)? {
|
||||||
println!("{} detected!", format.name);
|
println!("{} detected!", format.name);
|
||||||
|
|||||||
Reference in New Issue
Block a user