newreg: simplify getting file/dir and context

This commit is contained in:
theubusu
2026-02-06 16:27:13 +01:00
parent 9b059c67ab
commit 438d106c96
31 changed files with 142 additions and 127 deletions
+4 -4
View File
@@ -1,5 +1,5 @@
use std::any::Any;
use crate::{InputTarget, AppContext, formats::Format};
use crate::{AppContext, formats::Format};
pub fn format() -> Format {
Format { name: "mstar", detector_func: is_mstar_file, extractor_func: extract_mstar }
}
@@ -14,7 +14,7 @@ use crate::utils::lzop::{unlzop_to_file};
use crate::utils::sparse::{unsparse_to_file};
pub fn is_mstar_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Box<dyn std::error::Error>> {
let file = match &app_ctx.input {InputTarget::File(f) => f, InputTarget::Directory(_) => return Ok(None)};
let file = match app_ctx.file() {Some(f) => f, None => return Ok(None)};
let header = common::read_file(&file, 0, 32768)?;
let header_string = String::from_utf8_lossy(&header);
@@ -33,8 +33,8 @@ fn parse_number(s: &str) -> Option<u64> {
}
}
pub fn extract_mstar(app_ctx: &AppContext, _ctx: Option<Box<dyn Any>>) -> Result<(), Box<dyn std::error::Error>> {
let file = match &app_ctx.input {InputTarget::File(f) => f, InputTarget::Directory(_) => return Err("Extractor expected file, not directory".into())};
pub fn extract_mstar(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
let file = app_ctx.file().ok_or("Extractor expected file")?;
let mut script = common::read_file(&file, 0, 32768)?;