From 068badad7efb642a8419767af1e3afef346a1ad4 Mon Sep 17 00:00:00 2001 From: Jujuforce Date: Sun, 22 Mar 2026 16:29:49 +0100 Subject: [PATCH] feat: name output folder after the input .app file Output directory is now derived from the input .app path (without extension) instead of the intermediate VHD filename. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/main.rs | 6 ++++-- src/vhd.rs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index d61e613..ccc7513 100644 --- a/src/main.rs +++ b/src/main.rs @@ -393,7 +393,8 @@ fn main() -> Result<()> { if deltas.is_empty() { // Standalone base VHD, just extract if let Some(base) = base { - if let Err(e) = vhd::extract_vhd(&base.vhd_path) { + let output_dir = base.input_path.with_extension(""); + if let Err(e) = vhd::extract_vhd(&base.vhd_path, &output_dir) { println!("WARNING: VHD extraction failed: {e:#}"); } } @@ -408,7 +409,8 @@ fn main() -> Result<()> { // Merge + extract each delta with the base (pure Rust, no admin needed) for delta in &deltas { - if let Err(e) = vhd::extract_merged_vhd(&base.vhd_path, &delta.vhd_path) { + let output_dir = delta.input_path.with_extension(""); + if let Err(e) = vhd::extract_merged_vhd(&base.vhd_path, &delta.vhd_path, &output_dir) { println!("WARNING: Merged VHD extraction failed: {e:#}"); } } diff --git a/src/vhd.rs b/src/vhd.rs index fc05c28..57d0806 100644 --- a/src/vhd.rs +++ b/src/vhd.rs @@ -656,13 +656,13 @@ fn extract_ntfs_to_dir(fs: &mut T, output_dir: &Path, prefix: &s // --------------------------------------------------------------------------- /// Extract all files from a single VHD's NTFS filesystem, then delete the VHD. -pub fn extract_vhd(vhd_path: &Path) -> Result<()> { - let output_dir = vhd_path.with_extension(""); +/// The `output_dir` is where files are extracted to. +pub fn extract_vhd(vhd_path: &Path, output_dir: &Path) -> Result<()> { println!("Extracting VHD: {}", vhd_path.display()); let mut vhd = VhdReader::new(File::open(vhd_path)?).map_err(|e| anyhow!(e))?; - let prefix = vhd_path.file_name().unwrap_or_default().to_string_lossy().to_string(); - extract_ntfs_to_dir(&mut vhd, &output_dir, &prefix)?; + let prefix = output_dir.file_name().unwrap_or_default().to_string_lossy().to_string(); + extract_ntfs_to_dir(&mut vhd, output_dir, &prefix)?; println!("Extracted to: {}", output_dir.display()); @@ -675,16 +675,16 @@ pub fn extract_vhd(vhd_path: &Path) -> Result<()> { /// Extract files from a merged view of base + delta VHDs (pure Rust, no admin needed). /// Reads delta blocks where available, falls back to base. Deletes both VHDs after. -pub fn extract_merged_vhd(base_path: &Path, delta_path: &Path) -> Result<()> { - let output_dir = base_path.with_extension(""); +/// The `output_dir` is where files are extracted to. +pub fn extract_merged_vhd(base_path: &Path, delta_path: &Path, output_dir: &Path) -> Result<()> { println!("Extracting merged VHD: {} + {}", base_path.display(), delta_path.display()); let base = File::open(base_path)?; let delta = File::open(delta_path)?; let mut merged = MergedVhdReader::new(base, delta).map_err(|e| anyhow!(e))?; - let prefix = base_path.file_name().unwrap_or_default().to_string_lossy().to_string(); - extract_ntfs_to_dir(&mut merged, &output_dir, &prefix)?; + let prefix = output_dir.file_name().unwrap_or_default().to_string_lossy().to_string(); + extract_ntfs_to_dir(&mut merged, output_dir, &prefix)?; println!("Extracted to: {}", output_dir.display());