From 11263ab0c7cd7f32fd30b1033e3b295d1e6c1b55 Mon Sep 17 00:00:00 2001 From: iqiziqi Date: Mon, 8 Jul 2024 14:46:34 +0800 Subject: [PATCH] [fix] Fix output path error --- crates/ncmdump-bin/src/main.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/ncmdump-bin/src/main.rs b/crates/ncmdump-bin/src/main.rs index 847ee55..ccbce9a 100644 --- a/crates/ncmdump-bin/src/main.rs +++ b/crates/ncmdump-bin/src/main.rs @@ -8,6 +8,7 @@ use anyhow::Result; use clap::Parser; use ncmdump::{Ncmdump, QmcDump}; +use ncmdump::error::Errors; use ncmdump::utils::FileType; use crate::command::Command; @@ -57,17 +58,20 @@ impl Program { }?; let path = provider.get_path(); - let parent = match &self.command.output { - None => path.parent().ok_or(Error::Path)?, - Some(p) => Path::new(p), + let target_path = match &self.command.output { + None => path.with_extension(ext), + Some(p) => Path::new(p) + .join( + path.file_name() + .ok_or(Errors::IO("Can't get file name".into()))?, + ) + .with_extension(ext), }; - let file_name = path.file_stem().ok_or(Error::Path)?; - let path = parent.join(file_name).with_extension(ext); let mut target = File::options() .create(true) .write(true) .truncate(true) - .open(path)?; + .open(target_path)?; if provider.get_format() == FileType::Ncm { let file = File::open(provider.get_path())?; let mut dump = Ncmdump::from_reader(file)?;