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
@@ -64,7 +64,7 @@ struct Entry {
}
pub fn is_sony_bdp_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, 4)?;
if header == b"\x01\x73\xEC\xC9" || header == b"\x01\x73\xEC\x1F" || header == b"\xEC\x7D\xB0\xB0" { //MSB1x, MSB0x, BDPPxx
@@ -74,8 +74,8 @@ pub fn is_sony_bdp_file(app_ctx: &AppContext) -> Result<Option<Box<dyn Any>>, Bo
}
}
pub fn extract_sony_bdp(app_ctx: &AppContext, _ctx: Option<Box<dyn Any>>) -> Result<(), Box<dyn std::error::Error>> {
let mut file = match &app_ctx.input {InputTarget::File(f) => f, InputTarget::Directory(_) => return Err("Extractor expected file, not directory".into())};
pub fn extract_sony_bdp(app_ctx: &AppContext, _ctx: Box<dyn Any>) -> Result<(), Box<dyn std::error::Error>> {
let mut file = app_ctx.file().ok_or("Extractor expected file")?;
let obf_header = common::read_exact(&mut file, 300)?;
let header = hex_substitute(&obf_header);
@@ -128,7 +128,7 @@ pub fn extract_sony_bdp(app_ctx: &AppContext, _ctx: Option<Box<dyn Any>>) -> Res
if let Some(result) = formats::mtk_bdp::is_mtk_bdp_file(&ctx)? {
println!("- MTK BDP file detected!\n");
formats::mtk_bdp::extract_mtk_bdp(&ctx, Some(result))?;
formats::mtk_bdp::extract_mtk_bdp(&ctx, result)?;
} else {
println!("- Not an MTK BDP file.");
}