Skip to content

Commit

Permalink
Add blk extension override
Browse files Browse the repository at this point in the history
  • Loading branch information
FlareFlo committed Jan 2, 2024
1 parent 516f537 commit 221ccde
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/cli/unpack_vromf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ pub fn unpack_vromf() -> Command {
.required(false)
.help("Packs output into single zipfile")
)
.arg(
Arg::new("blk_extension")
.long("blk_extension")
.required(false)
.help("Replaces all blk files extension to this when provided, leaves them unchanged otherwise")
)
}
18 changes: 15 additions & 3 deletions src/subcommands/unpack_vromf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ffi::OsStr;
use std::fs::File;
use std::io::Write;
use std::ops::ControlFlow;
use std::sync::Arc;

use clap::ArgMatches;
use color_eyre::eyre::{Context, ContextCompat, Result};
Expand Down Expand Up @@ -43,6 +44,8 @@ pub fn unpack_vromf(args: &ArgMatches) -> Result<()> {

let avif2dds = *args.get_one::<bool>("avif2dds").context("Invalid argument: avif2dds")?;

let blk_extension = args.get_one::<String>("blk_extension").map(|e|Arc::new(e.to_owned()));

if parsed_input_dir.is_dir() {
let output_folder = match () {
_ if let Some(path) = args.get_one::<String>("Output directory") => {
Expand Down Expand Up @@ -70,12 +73,13 @@ pub fn unpack_vromf(args: &ArgMatches) -> Result<()> {
.ends_with("vromfs.bin")
{
let output_folder = output_folder.clone();
let blk_extension = blk_extension.clone();
threads.push(Box::new(thread::spawn(move || {
let read = fs::read(file.path()).with_context(context!(format!(
"Failed to read vromf {:?}",
file.path()
)))?;
parse_and_write_one_vromf(file.path(), read, output_folder, mode, crlf, should_override, avif2dds, zip)
parse_and_write_one_vromf(file.path(), read, output_folder, mode, crlf, should_override, avif2dds, zip, blk_extension)
.suggestion(format!("Error filename: {}", file.file_name().to_string_lossy()))?;
Ok(())
})))
Expand All @@ -101,7 +105,7 @@ pub fn unpack_vromf(args: &ArgMatches) -> Result<()> {
}
};
let read = fs::read(&parsed_input_dir)?;
parse_and_write_one_vromf(parsed_input_dir, read, output_folder, mode, crlf, should_override, avif2dds, zip)?;
parse_and_write_one_vromf(parsed_input_dir, read, output_folder, mode, crlf, should_override, avif2dds, zip, blk_extension)?;
}

Ok(())
Expand All @@ -117,6 +121,7 @@ fn parse_and_write_one_vromf(
#[allow(unused)] // Conditionally depending on target
avif2dds: bool,
zip: bool,
blk_extension: Option<Arc<String>>
) -> Result<()> {
let parser = VromfUnpacker::from_file((file_path.clone(), read))?;
let files = parser.unpack_all(format, should_override)?;
Expand Down Expand Up @@ -193,7 +198,14 @@ fn parse_and_write_one_vromf(
}
}
let rel_file_path = vromf_name.clone().join(&file.0);
let joined_final_path = output_dir.join(&rel_file_path);
let mut joined_final_path = output_dir.join(&rel_file_path);

if let Some(extension) = blk_extension.clone() {
if joined_final_path.extension() == Some(OsStr::new("blk")) {
joined_final_path.set_extension(extension.as_str());
}
}

if zip {
sender.send(ControlFlow::Continue((file.1, rel_file_path)))?;
} else {
Expand Down

0 comments on commit 221ccde

Please sign in to comment.