diff --git a/src/main.rs b/src/main.rs index b1ecd71..a5a42f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -349,11 +349,18 @@ pub fn export_script( pb.push(fname); } } + pb.set_extension(""); + if let Some(ext) = script.archive_output_ext() { + pb.set_extension(ext); + } pb.to_string_lossy().into_owned() } None => { let mut pb = std::path::PathBuf::from(filename); pb.set_extension(""); + if let Some(ext) = script.archive_output_ext() { + pb.set_extension(ext); + } pb.to_string_lossy().into_owned() } }; @@ -804,6 +811,10 @@ pub fn import_script( pb.push(fname); } } + pb.set_extension(""); + if let Some(ext) = script.archive_output_ext() { + pb.set_extension(ext); + } pb.to_string_lossy().into_owned() }; let files: Vec<_> = script.iter_archive()?.collect(); @@ -1244,11 +1255,17 @@ pub fn unpack_archive( } } pb.set_extension(""); + if let Some(ext) = script.archive_output_ext() { + pb.set_extension(ext); + } pb.to_string_lossy().into_owned() } None => { let mut pb = std::path::PathBuf::from(filename); pb.set_extension(""); + if let Some(ext) = script.archive_output_ext() { + pb.set_extension(ext); + } pb.to_string_lossy().into_owned() } }; diff --git a/src/scripts/artemis/archive/pfs.rs b/src/scripts/artemis/archive/pfs.rs index b225718..0438615 100644 --- a/src/scripts/artemis/archive/pfs.rs +++ b/src/scripts/artemis/archive/pfs.rs @@ -29,7 +29,7 @@ impl ScriptBuilder for ArtemisArcBuilder { fn build_script( &self, buf: Vec, - _filename: &str, + filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, @@ -38,6 +38,7 @@ impl ScriptBuilder for ArtemisArcBuilder { MemReader::new(buf), archive_encoding, config, + filename, )?)) } @@ -50,18 +51,28 @@ impl ScriptBuilder for ArtemisArcBuilder { ) -> Result> { let f = std::fs::File::open(filename)?; let f = std::io::BufReader::new(f); - Ok(Box::new(ArtemisArc::new(f, archive_encoding, config)?)) + Ok(Box::new(ArtemisArc::new( + f, + archive_encoding, + config, + filename, + )?)) } fn build_script_from_reader( &self, reader: Box, - _filename: &str, + filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, ) -> Result> { - Ok(Box::new(ArtemisArc::new(reader, archive_encoding, config)?)) + Ok(Box::new(ArtemisArc::new( + reader, + archive_encoding, + config, + filename, + )?)) } fn extensions(&self) -> &'static [&'static str] { @@ -91,10 +102,16 @@ pub struct ArtemisArc { reader: Arc>, entries: Vec, xor_key: Option<[u8; 20]>, + output_ext: Option, } impl ArtemisArc { - pub fn new(mut reader: T, archive_encoding: Encoding, _config: &ExtraConfig) -> Result { + pub fn new( + mut reader: T, + archive_encoding: Encoding, + _config: &ExtraConfig, + filename: &str, + ) -> Result { let mut magic = [0; 2]; reader.read_exact(&mut magic)?; if &magic != b"pf" { @@ -131,10 +148,15 @@ impl ArtemisArc { } else { None }; + let output_ext = std::path::Path::new(filename) + .extension() + .filter(|s| *s != "pfs") + .map(|s| s.to_string_lossy().to_string()); Ok(ArtemisArc { reader: Arc::new(Mutex::new(reader)), entries, xor_key, + output_ext, }) } } @@ -167,6 +189,10 @@ impl Script for ArtemisArc { xor_key: self.xor_key.clone(), })) } + + fn archive_output_ext<'a>(&'a self) -> Option<&'a str> { + self.output_ext.as_ref().map(|s| s.as_str()) + } } struct Entry { diff --git a/src/scripts/base.rs b/src/scripts/base.rs index 723f0cf..35b83f3 100644 --- a/src/scripts/base.rs +++ b/src/scripts/base.rs @@ -257,6 +257,11 @@ pub trait Script: std::fmt::Debug { Ok(Box::new(std::iter::empty())) } + /// Returns output extension for archive output folder. + fn archive_output_ext<'a>(&'a self) -> Option<&'a str> { + None + } + #[cfg(feature = "image")] fn is_image(&self) -> bool { false