mirror of
https://github.com/Ap0dexMe0/unixtract.git
synced 2026-07-16 05:04:22 +02:00
newreg: simplify getting file/dir and context
This commit is contained in:
+18
-3
@@ -23,6 +23,21 @@ pub struct AppContext {
|
||||
pub input: InputTarget,
|
||||
pub output_dir: PathBuf,
|
||||
}
|
||||
impl AppContext {
|
||||
pub fn file(&self) -> Option<&File> {
|
||||
match &self.input {
|
||||
InputTarget::File(f) => Some(f),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dir(&self) -> Option<&PathBuf> {
|
||||
match &self.input {
|
||||
InputTarget::Directory(p) => Some(p),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("unixtract Firmware extractor");
|
||||
@@ -69,12 +84,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
|
||||
let formats: Vec<Format> = get_registry();
|
||||
println!("Loaded {} formats!\n", formats.len());
|
||||
println!("Loaded {} formats!", formats.len());
|
||||
|
||||
for format in formats {
|
||||
if let Some(ctx) = (format.detector_func)(&app_ctx)? {
|
||||
println!("{} detected!", format.name);
|
||||
(format.extractor_func)(&app_ctx, Some(ctx))?;
|
||||
println!("\n{} detected!", format.name);
|
||||
(format.extractor_func)(&app_ctx, ctx)?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user