From acbd18a3f666877982905e6068a0c48faca0736e Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sun, 12 Apr 2026 16:25:59 +0800 Subject: [PATCH] Fix lifetime --- src/ext/io.rs | 12 +- src/scripts/artemis/archive/pf2.rs | 14 ++- src/scripts/artemis/archive/pfs.rs | 14 ++- src/scripts/base.rs | 8 +- src/scripts/bgi/archive/v1.rs | 14 ++- src/scripts/bgi/archive/v2.rs | 14 ++- src/scripts/bgi/audio/audio.rs | 6 +- src/scripts/cat_system/archive/int.rs | 15 ++- src/scripts/circus/archive/crm.rs | 14 ++- src/scripts/circus/archive/dat.rs | 14 ++- src/scripts/circus/archive/pck.rs | 14 ++- src/scripts/circus/audio/pcm.rs | 6 +- src/scripts/emote/pimg.rs | 6 +- src/scripts/emote/psb.rs | 6 +- src/scripts/escude/archive.rs | 14 ++- src/scripts/ex_hibit/arc/grp.rs | 53 +++++---- src/scripts/hexen_haus/archive/arcc.rs | 19 ++-- src/scripts/hexen_haus/archive/odio.rs | 14 ++- src/scripts/hexen_haus/archive/wag.rs | 14 ++- src/scripts/kirikiri/archive/xp3/archive.rs | 4 +- src/scripts/kirikiri/archive/xp3/crypt/cx.rs | 23 ++-- src/scripts/kirikiri/archive/xp3/crypt/cz.rs | 12 +- src/scripts/kirikiri/archive/xp3/crypt/mod.rs | 4 +- src/scripts/kirikiri/archive/xp3/mod.rs | 104 +++++++++--------- src/scripts/kirikiri/archive/xp3/read.rs | 10 +- src/scripts/kirikiri/scn.rs | 6 +- src/scripts/musica/archive/paz.rs | 16 +-- src/scripts/qlie/archive/pack/mod.rs | 14 ++- src/scripts/softpal/arc/pac.rs | 15 ++- src/scripts/yaneurao/itufuru/archive.rs | 14 ++- 30 files changed, 267 insertions(+), 226 deletions(-) diff --git a/src/ext/io.rs b/src/ext/io.rs index 1b8fa63..ae99e26 100644 --- a/src/ext/io.rs +++ b/src/ext/io.rs @@ -2457,14 +2457,14 @@ impl Seek for PrefixStream { /// A readable stream that concatenates multiple streams. #[derive(Debug)] -pub struct MultipleReadStream { - streams: Vec>, +pub struct MultipleReadStream<'a> { + streams: Vec>, stream_lengths: Vec, total_length: u64, pos: u64, } -impl MultipleReadStream { +impl<'a> MultipleReadStream<'a> { /// Creates a new `MultipleReadStream`. pub fn new() -> Self { MultipleReadStream { @@ -2476,7 +2476,7 @@ impl MultipleReadStream { } /// Adds a new stream to the end of the concatenated streams. - pub fn add_stream(&mut self, mut stream: T) -> Result<()> { + pub fn add_stream(&mut self, mut stream: T) -> Result<()> { let length = stream.stream_length()?; self.streams.push(Box::new(stream)); self.stream_lengths.push(self.total_length); @@ -2494,7 +2494,7 @@ impl MultipleReadStream { } } -impl Read for MultipleReadStream { +impl<'a> Read for MultipleReadStream<'a> { fn read(&mut self, buf: &mut [u8]) -> Result { if self.pos >= self.total_length { return Ok(0); @@ -2518,7 +2518,7 @@ impl Read for MultipleReadStream { } } -impl Seek for MultipleReadStream { +impl<'a> Seek for MultipleReadStream<'a> { fn seek(&mut self, pos: SeekFrom) -> Result { let new_pos = match pos { SeekFrom::Start(offset) => offset, diff --git a/src/scripts/artemis/archive/pf2.rs b/src/scripts/artemis/archive/pf2.rs index 5968acf..aa78e98 100644 --- a/src/scripts/artemis/archive/pf2.rs +++ b/src/scripts/artemis/archive/pf2.rs @@ -65,15 +65,15 @@ impl ScriptBuilder for ArtemisPf2Builder { )?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ArtemisPf2::new( reader, archive_encoding, @@ -132,13 +132,14 @@ struct Pf2EntryHeader { #[derive(Debug)] /// The Artemis PF2 archive script. -pub struct ArtemisPf2 { +pub struct ArtemisPf2<'a, T: Read + Seek + std::fmt::Debug + 'a> { reader: Arc>, entries: Vec, output_ext: Option, + _mark: std::marker::PhantomData<&'a ()>, } -impl ArtemisPf2 { +impl<'a, T: Read + Seek + std::fmt::Debug + 'a> ArtemisPf2<'a, T> { /// Creates a new Artemis PF2 archive script. /// /// * `reader` - The reader for the archive. @@ -182,11 +183,12 @@ impl ArtemisPf2 { reader: Arc::new(Mutex::new(reader)), entries, output_ext, + _mark: std::marker::PhantomData, }) } } -impl Script for ArtemisPf2 { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for ArtemisPf2<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/artemis/archive/pfs.rs b/src/scripts/artemis/archive/pfs.rs index 893e355..6053307 100644 --- a/src/scripts/artemis/archive/pfs.rs +++ b/src/scripts/artemis/archive/pfs.rs @@ -67,15 +67,15 @@ impl ScriptBuilder for ArtemisArcBuilder { )?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ArtemisArc::new( reader, archive_encoding, @@ -131,14 +131,15 @@ struct PfsEntryHeader { #[derive(Debug)] /// The Artemis PFS archive script. -pub struct ArtemisArc { +pub struct ArtemisArc<'a, T: Read + Seek + std::fmt::Debug + 'a> { reader: Arc>, entries: Vec, xor_key: Option<[u8; 20]>, output_ext: Option, + _mark: std::marker::PhantomData<&'a ()>, } -impl ArtemisArc { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> ArtemisArc<'b, T> { /// Creates a new Artemis PFS archive script. /// /// * `reader` - The reader for the archive. @@ -196,11 +197,12 @@ impl ArtemisArc { entries, xor_key, output_ext, + _mark: std::marker::PhantomData, }) } } -impl Script for ArtemisArc { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for ArtemisArc<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/base.rs b/src/scripts/base.rs index f349b2c..f13bd29 100644 --- a/src/scripts/base.rs +++ b/src/scripts/base.rs @@ -86,15 +86,15 @@ pub trait ScriptBuilder: std::fmt::Debug { /// * `archive_encoding` - The encoding of the archive, if applicable. /// * `config` - Additional configuration options. /// * `archive` - An optional archive to which the script belongs. - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - mut reader: Box, + mut reader: Box, filename: &str, encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, archive: Option<&Box>, - ) -> Result> { + ) -> Result> { let mut data = Vec::new(); reader .read_to_end(&mut data) @@ -263,7 +263,7 @@ pub trait ArchiveContent: Read { } /// A trait for script types. -pub trait Script: std::fmt::Debug + std::any::Any { +pub trait Script: std::fmt::Debug { /// Returns the default output script type for this script. fn default_output_script_type(&self) -> OutputScriptType; diff --git a/src/scripts/bgi/archive/v1.rs b/src/scripts/bgi/archive/v1.rs index 74e4f5c..3c32cc6 100644 --- a/src/scripts/bgi/archive/v1.rs +++ b/src/scripts/bgi/archive/v1.rs @@ -77,15 +77,15 @@ impl ScriptBuilder for BgiArchiveBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiArchive::new( reader, archive_encoding, @@ -219,15 +219,16 @@ impl Seek for Entry { #[derive(Debug)] /// Buriko General Interpreter/Ethornell Archive File Version 1 (.arc) -pub struct BgiArchive { +pub struct BgiArchive<'a, T: Read + Seek + std::fmt::Debug + 'a> { reader: Arc>, entries: Vec, base_offset: u64, #[cfg(feature = "bgi-img")] is_sysgrp_arc: bool, + _mark: std::marker::PhantomData<&'a ()>, } -impl BgiArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> BgiArchive<'b, T> { /// Creates a new BGI archive from a reader. /// /// * `reader` - The reader to read the archive from. @@ -267,11 +268,12 @@ impl BgiArchive { base_offset: 16 + (file_count as u64 * 32), #[cfg(feature = "bgi-img")] is_sysgrp_arc, + _mark: std::marker::PhantomData, }) } } -impl Script for BgiArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for BgiArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/bgi/archive/v2.rs b/src/scripts/bgi/archive/v2.rs index eff7022..086bc69 100644 --- a/src/scripts/bgi/archive/v2.rs +++ b/src/scripts/bgi/archive/v2.rs @@ -77,15 +77,15 @@ impl ScriptBuilder for BgiArchiveBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiArchive::new( reader, archive_encoding, @@ -251,15 +251,16 @@ impl Option<&'static ScriptType>> ArchiveContent fo #[derive(Debug)] /// BGI Archive Version 2 -pub struct BgiArchive { +pub struct BgiArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { reader: Arc>, entries: Vec, base_offset: u64, #[cfg(feature = "bgi-img")] is_sysgrp_arc: bool, + _mark: std::marker::PhantomData<&'b ()>, } -impl BgiArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> BgiArchive<'b, T> { /// Creates a new BGI Archive from a reader. /// /// * `reader` - The reader to read the archive from. @@ -299,11 +300,12 @@ impl BgiArchive { base_offset: 16 + (file_count as u64 * 0x80), #[cfg(feature = "bgi-img")] is_sysgrp_arc, + _mark: std::marker::PhantomData, }) } } -impl Script for BgiArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for BgiArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/bgi/audio/audio.rs b/src/scripts/bgi/audio/audio.rs index 4b53dcb..8981892 100644 --- a/src/scripts/bgi/audio/audio.rs +++ b/src/scripts/bgi/audio/audio.rs @@ -46,15 +46,15 @@ impl ScriptBuilder for BgiAudioBuilder { Ok(Box::new(BgiAudio::new(f, config)?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(BgiAudio::new(reader, config)?)) } diff --git a/src/scripts/cat_system/archive/int.rs b/src/scripts/cat_system/archive/int.rs index ad490a9..6ec8855 100644 --- a/src/scripts/cat_system/archive/int.rs +++ b/src/scripts/cat_system/archive/int.rs @@ -78,15 +78,15 @@ impl ScriptBuilder for CSIntArcBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CSIntArc::new( reader, archive_encoding, @@ -243,15 +243,16 @@ impl ArchiveContent for MemEntry { #[derive(Debug)] /// CatSystem2 Archive script. -pub struct CSIntArc { +pub struct CSIntArc<'b, T: Read + Seek + std::fmt::Debug + 'b> { reader: Arc>, encrypt: Option, entries: Vec, + _mark: std::marker::PhantomData<&'b ()>, } const NAME_SIZES: [usize; 2] = [0x20, 0x40]; -impl CSIntArc { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> CSIntArc<'b, T> { /// Creates a new instance of `CSIntArc` from a reader. /// /// * `reader` - The reader to read the archive from. @@ -315,6 +316,7 @@ impl CSIntArc { reader: Arc::new(Mutex::new(reader)), encrypt: Some(encrypt), entries: entries, + _mark: std::marker::PhantomData, }); } let file_size = reader.seek(SeekFrom::End(0))?; @@ -346,6 +348,7 @@ impl CSIntArc { reader: Arc::new(Mutex::new(reader)), encrypt: None, entries, + _mark: std::marker::PhantomData, }); } } @@ -392,7 +395,7 @@ impl CSIntArc { } } -impl Script for CSIntArc { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for CSIntArc<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/circus/archive/crm.rs b/src/scripts/circus/archive/crm.rs index d44b4ac..38c1d2a 100644 --- a/src/scripts/circus/archive/crm.rs +++ b/src/scripts/circus/archive/crm.rs @@ -65,15 +65,15 @@ impl ScriptBuilder for CrmArchiveBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(CrmArchive::new(reader, archive_encoding, config)?)) } @@ -182,12 +182,13 @@ impl Seek for Entry { #[derive(Debug)] /// Circus CRM Archive -pub struct CrmArchive { +pub struct CrmArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { reader: Arc>, entries: Vec, + _mark: std::marker::PhantomData<&'b ()>, } -impl CrmArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> CrmArchive<'b, T> { /// Creates a new `CrmArchive` from a reader. /// /// * `reader` - The reader to read the CRM archive from. @@ -227,11 +228,12 @@ impl CrmArchive { Ok(Self { reader: Arc::new(Mutex::new(reader)), entries, + _mark: std::marker::PhantomData, }) } } -impl Script for CrmArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for CrmArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/circus/archive/dat.rs b/src/scripts/circus/archive/dat.rs index 0693c2f..e97ae30 100644 --- a/src/scripts/circus/archive/dat.rs +++ b/src/scripts/circus/archive/dat.rs @@ -64,15 +64,15 @@ impl ScriptBuilder for DatArchiveBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(DatArchive::new(reader, archive_encoding, config)?)) } @@ -185,15 +185,16 @@ pub struct DatExtraInfo { #[derive(Debug)] /// Circus DAT Archive -pub struct DatArchive { +pub struct DatArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { reader: Arc>, entries: Vec, name_len: usize, + _mark: std::marker::PhantomData<&'b ()>, } const NAME_LEN: [usize; 3] = [0x24, 0x30, 0x3C]; -impl DatArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> DatArchive<'b, T> { /// Creates a new `DatArchive` from a reader. /// /// * `reader` - The reader to read the DAT archive from. @@ -206,6 +207,7 @@ impl DatArchive { reader, entries, name_len, + _mark: std::marker::PhantomData, }) } @@ -265,7 +267,7 @@ impl DatArchive { } } -impl Script for DatArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for DatArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/circus/archive/pck.rs b/src/scripts/circus/archive/pck.rs index 9ccf4d1..274dd5a 100644 --- a/src/scripts/circus/archive/pck.rs +++ b/src/scripts/circus/archive/pck.rs @@ -68,15 +68,15 @@ impl ScriptBuilder for PckArchiveBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PckArchive::new(reader, archive_encoding, config)?)) } @@ -197,12 +197,13 @@ impl Seek for Entry { #[derive(Debug)] /// PCK Archive -pub struct PckArchive { +pub struct PckArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { reader: Arc>, entries: Vec, + _mark: std::marker::PhantomData<&'b ()>, } -impl PckArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> PckArchive<'b, T> { /// Creates a new `PckArchive` from a reader. /// /// * `reader` - The reader to read the PCK archive from. @@ -253,11 +254,12 @@ impl PckArchive { Ok(Self { reader: Arc::new(Mutex::new(reader)), entries, + _mark: std::marker::PhantomData, }) } } -impl Script for PckArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for PckArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/circus/audio/pcm.rs b/src/scripts/circus/audio/pcm.rs index 7a7fa88..ca10200 100644 --- a/src/scripts/circus/audio/pcm.rs +++ b/src/scripts/circus/audio/pcm.rs @@ -52,15 +52,15 @@ impl ScriptBuilder for PcmBuilder { Ok(Box::new(Pcm::new(f, config)?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Pcm::new(reader, config)?)) } diff --git a/src/scripts/emote/pimg.rs b/src/scripts/emote/pimg.rs index d55f41d..77eeebc 100644 --- a/src/scripts/emote/pimg.rs +++ b/src/scripts/emote/pimg.rs @@ -60,15 +60,15 @@ impl ScriptBuilder for PImgBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PImg::new(reader, filename, config)?)) } diff --git a/src/scripts/emote/psb.rs b/src/scripts/emote/psb.rs index 7d5713f..38f2055 100644 --- a/src/scripts/emote/psb.rs +++ b/src/scripts/emote/psb.rs @@ -43,15 +43,15 @@ impl ScriptBuilder for PsbBuilder { Ok(Box::new(Psb::new(MemReader::new(buf), encoding, config)?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Psb::new(reader, encoding, config)?)) } diff --git a/src/scripts/escude/archive.rs b/src/scripts/escude/archive.rs index 32f4f12..8417624 100644 --- a/src/scripts/escude/archive.rs +++ b/src/scripts/escude/archive.rs @@ -72,15 +72,15 @@ impl ScriptBuilder for EscudeBinArchiveBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(EscudeBinArchive::new( reader, archive_encoding, @@ -165,14 +165,15 @@ impl ArchiveContent for Entry { #[derive(Debug)] /// Escu:de Binary Archive -pub struct EscudeBinArchive { +pub struct EscudeBinArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { reader: Arc>, file_count: u32, entries: Vec, archive_encoding: Encoding, + _mark: std::marker::PhantomData<&'b ()>, } -impl EscudeBinArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> EscudeBinArchive<'b, T> { /// Creates a new `EscudeBinArchive` from a reader /// /// * `reader` - The reader to read the archive from @@ -204,11 +205,12 @@ impl EscudeBinArchive { file_count, entries, archive_encoding, + _mark: std::marker::PhantomData, }) } } -impl Script for EscudeBinArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for EscudeBinArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/ex_hibit/arc/grp.rs b/src/scripts/ex_hibit/arc/grp.rs index 798989c..54f09d7 100644 --- a/src/scripts/ex_hibit/arc/grp.rs +++ b/src/scripts/ex_hibit/arc/grp.rs @@ -17,24 +17,6 @@ impl ExHibitGrpArchiveBuilder { pub const fn new() -> Self { Self {} } - - fn build_with_reader( - &self, - reader: T, - filename: &str, - archive_encoding: Encoding, - config: &ExtraConfig, - ) -> Result> - where - T: Read + Seek + Debug + 'static, - { - Ok(Box::new(ExHibitGrpArchive::new( - reader, - filename, - archive_encoding, - config, - )?)) - } } impl ScriptBuilder for ExHibitGrpArchiveBuilder { @@ -55,7 +37,12 @@ impl ScriptBuilder for ExHibitGrpArchiveBuilder { config: &ExtraConfig, _archive: Option<&Box>, ) -> Result> { - self.build_with_reader(MemReader::new(data), filename, archive_encoding, config) + Ok(Box::new(ExHibitGrpArchive::new( + MemReader::new(data), + filename, + archive_encoding, + config, + )?)) } fn build_script_from_file( @@ -74,19 +61,29 @@ impl ScriptBuilder for ExHibitGrpArchiveBuilder { let file = std::fs::File::open(filename) .with_context(|| format!("Failed to open '{}'.", filename))?; let reader = std::io::BufReader::new(file); - self.build_with_reader(reader, filename, archive_encoding, config) + Ok(Box::new(ExHibitGrpArchive::new( + reader, + filename, + archive_encoding, + config, + )?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { - self.build_with_reader(reader, filename, archive_encoding, config) + ) -> Result> { + Ok(Box::new(ExHibitGrpArchive::new( + reader, + filename, + archive_encoding, + config, + )?)) } fn extensions(&self) -> &'static [&'static str] { @@ -121,12 +118,13 @@ struct GrpFileEntry { #[derive(Debug)] /// ExHibit GRP archive instance. -pub struct ExHibitGrpArchive { +pub struct ExHibitGrpArchive<'b, T: Read + Seek + Debug + 'b> { reader: Arc>, entries: Vec, + _mark: std::marker::PhantomData<&'b ()>, } -impl ExHibitGrpArchive { +impl<'b, T: Read + Seek + Debug + 'b> ExHibitGrpArchive<'b, T> { fn new( mut reader: T, filename: &str, @@ -156,11 +154,12 @@ impl ExHibitGrpArchive { Ok(Self { reader: Arc::new(Mutex::new(reader)), entries, + _mark: std::marker::PhantomData, }) } } -impl Script for ExHibitGrpArchive { +impl<'b, T: Read + Seek + Debug + 'b> Script for ExHibitGrpArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/hexen_haus/archive/arcc.rs b/src/scripts/hexen_haus/archive/arcc.rs index 749a9e8..e4196a5 100644 --- a/src/scripts/hexen_haus/archive/arcc.rs +++ b/src/scripts/hexen_haus/archive/arcc.rs @@ -68,15 +68,15 @@ impl ScriptBuilder for HexenHausArccArchiveBuilder { )?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HexenHausArccArchive::new( reader, archive_encoding, @@ -114,12 +114,13 @@ struct HexenHausArccEntry { #[derive(Debug)] /// HexenHaus ARCC archive -pub struct HexenHausArccArchive { +pub struct HexenHausArccArchive<'a, T: Read + Seek + std::fmt::Debug + 'a> { reader: Arc>, entries: Vec, + _mark: std::marker::PhantomData<&'a ()>, } -impl HexenHausArccArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> HexenHausArccArchive<'b, T> { /// Creates a new `HexenHausArccArchive` pub fn new(mut reader: T, archive_encoding: Encoding, _config: &ExtraConfig) -> Result { reader.seek(SeekFrom::Start(0))?; @@ -207,11 +208,15 @@ impl HexenHausArccArchive { return Err(anyhow::anyhow!("ARCC archive contains no files")); } - Ok(HexenHausArccArchive { reader, entries }) + Ok(HexenHausArccArchive { + reader, + entries, + _mark: std::marker::PhantomData, + }) } } -impl Script for HexenHausArccArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for HexenHausArccArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/hexen_haus/archive/odio.rs b/src/scripts/hexen_haus/archive/odio.rs index 19f7b03..6944b29 100644 --- a/src/scripts/hexen_haus/archive/odio.rs +++ b/src/scripts/hexen_haus/archive/odio.rs @@ -74,15 +74,15 @@ impl ScriptBuilder for HexenHausOdioArchiveBuilder { )?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HexenHausOdioArchive::new( reader, archive_encoding, @@ -120,12 +120,13 @@ struct HexenHausOdioEntry { #[derive(Debug)] /// HexenHaus ODIO archive reader -pub struct HexenHausOdioArchive { +pub struct HexenHausOdioArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { reader: Arc>, entries: Vec, + _mark: std::marker::PhantomData<&'b ()>, } -impl HexenHausOdioArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> HexenHausOdioArchive<'b, T> { /// Creates a new `HexenHausOdioArchive` pub fn new(mut reader: T, _archive_encoding: Encoding, _config: &ExtraConfig) -> Result { reader.seek(SeekFrom::Start(0))?; @@ -221,11 +222,12 @@ impl HexenHausOdioArchive { Ok(HexenHausOdioArchive { reader: Arc::new(Mutex::new(reader)), entries, + _mark: std::marker::PhantomData, }) } } -impl Script for HexenHausOdioArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for HexenHausOdioArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/hexen_haus/archive/wag.rs b/src/scripts/hexen_haus/archive/wag.rs index 17ec956..bc9ddfc 100644 --- a/src/scripts/hexen_haus/archive/wag.rs +++ b/src/scripts/hexen_haus/archive/wag.rs @@ -75,15 +75,15 @@ impl ScriptBuilder for HexenHausWagArchiveBuilder { )?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(HexenHausWagArchive::new( reader, archive_encoding, @@ -121,13 +121,14 @@ struct HexenHausWagEntry { #[derive(Debug)] /// HexenHaus WAG archive reader -pub struct HexenHausWagArchive { +pub struct HexenHausWagArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { reader: Arc>, file_length: u64, entries: Vec, + _mark: std::marker::PhantomData<&'b ()>, } -impl HexenHausWagArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> HexenHausWagArchive<'b, T> { /// Creates a new `HexenHausWagArchive` pub fn new(mut reader: T, archive_encoding: Encoding, _config: &ExtraConfig) -> Result { reader.seek(SeekFrom::Start(0))?; @@ -318,6 +319,7 @@ impl HexenHausWagArchive { reader, file_length, entries, + _mark: std::marker::PhantomData, }) } @@ -334,7 +336,7 @@ impl HexenHausWagArchive { } } -impl Script for HexenHausWagArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for HexenHausWagArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/kirikiri/archive/xp3/archive.rs b/src/scripts/kirikiri/archive/xp3/archive.rs index 6049808..57d757d 100644 --- a/src/scripts/kirikiri/archive/xp3/archive.rs +++ b/src/scripts/kirikiri/archive/xp3/archive.rs @@ -114,8 +114,8 @@ impl ExtraProp { /// Represents the entire XP3 archive #[derive(Debug)] #[allow(dead_code)] -pub struct Xp3Archive { - pub inner: Arc>>, +pub struct Xp3Archive<'a> { + pub inner: Arc>>, pub crypt: Arc>, /// The offset which the archive file start. If the archive is embedded in another file (such as exe), this is the offset of the archive data within the larger file. pub base_offset: u64, diff --git a/src/scripts/kirikiri/archive/xp3/crypt/cx.rs b/src/scripts/kirikiri/archive/xp3/crypt/cx.rs index bbe6f35..62949cd 100644 --- a/src/scripts/kirikiri/archive/xp3/crypt/cx.rs +++ b/src/scripts/kirikiri/archive/xp3/crypt/cx.rs @@ -828,8 +828,8 @@ impl SenrenCxCrypt { }) } - fn read_yuzu_names( - reader: Box, + fn read_yuzu_names<'a>( + reader: Box, unpacked_size: u32, ) -> Result<(HashMap, HashMap)> { let mut decoded = MemWriter::with_capacity(unpacked_size as usize); @@ -866,9 +866,16 @@ impl SenrenCxCrypt { } } -fn read_yuzu_names(archive: &mut Xp3Archive, names_section_id: &str, convert: T) -> Result<()> +fn read_yuzu_names<'a, T>( + archive: &mut Xp3Archive<'a>, + names_section_id: &str, + convert: T, +) -> Result<()> where - T: FnOnce(Box, u32) -> Result<(HashMap, HashMap)>, + T: FnOnce( + Box, + u32, + ) -> Result<(HashMap, HashMap)>, { if let Some(section) = archive.extras.iter().find(|s| s.tag == names_section_id) { let mut sreader = MemReaderRef::new(§ion.data); @@ -1176,9 +1183,9 @@ impl NanaCxCrypt { })) } - fn read_yuzu_names( + fn read_yuzu_names<'a>( &self, - mut reader: Box, + mut reader: Box, unpacked_size: u32, ) -> Result<(HashMap, HashMap)> { let mut prefix = Vec::with_capacity(0x100); @@ -1421,9 +1428,9 @@ impl RiddleCxCrypt { ((hi as u64) << 32) | (lo as u64) } - fn read_yuzu_names( + fn read_yuzu_names<'a>( &self, - mut reader: Box, + mut reader: Box, unpacked_size: u32, ) -> Result<(HashMap, HashMap)> { let mut prefix = Vec::with_capacity(0x100); diff --git a/src/scripts/kirikiri/archive/xp3/crypt/cz.rs b/src/scripts/kirikiri/archive/xp3/crypt/cz.rs index c86d0b2..b5f97f3 100644 --- a/src/scripts/kirikiri/archive/xp3/crypt/cz.rs +++ b/src/scripts/kirikiri/archive/xp3/crypt/cz.rs @@ -38,17 +38,17 @@ fn cz_create_iv(seed: u32) -> [u8; 16] { } #[derive(Debug)] -struct AesDecryptor { +struct AesDecryptor<'a> { aes: Aes128CbcDec, - entry: StreamRegion, + entry: StreamRegion>, pos: u64, original_size: u64, } -impl AesDecryptor { +impl<'a> AesDecryptor<'a> { fn new( aes: Aes128CbcDec, - entry: StreamRegion, + entry: StreamRegion>, original_size: u64, ) -> AlignedReader<16, Self> { AlignedReader::new(Self { @@ -60,7 +60,7 @@ impl AesDecryptor { } } -impl Read for AesDecryptor { +impl<'a> Read for AesDecryptor<'a> { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { let readed = self.entry.read_most(buf)?; if readed % 16 != 0 { @@ -105,7 +105,7 @@ impl Crypt for KissCrypt { fn need_filter(&self, _filename: &str, buf: &[u8], buf_len: usize) -> bool { buf_len >= 4 && buf.starts_with(CZ_MAGIC) } - fn filter(&self, mut entry: Entry) -> Result> { + fn filter<'a>(&self, mut entry: Entry<'a>) -> Result> { let mut header = [0u8; 15]; entry.read_exact(&mut header)?; let typ = [header[4] ^ 0x11, header[5] ^ 0x7F, header[6] ^ 0x9A]; diff --git a/src/scripts/kirikiri/archive/xp3/crypt/mod.rs b/src/scripts/kirikiri/archive/xp3/crypt/mod.rs index f1634a3..2595ae9 100644 --- a/src/scripts/kirikiri/archive/xp3/crypt/mod.rs +++ b/src/scripts/kirikiri/archive/xp3/crypt/mod.rs @@ -119,14 +119,14 @@ pub trait Crypt: std::fmt::Debug { } /// Apply extra processing to the decrypted content of the file. - fn filter(&self, _entry: Entry) -> Result> { + fn filter<'a>(&self, _entry: Entry<'a>) -> Result> { Err(anyhow::anyhow!( "This crypt does not support content filter after decrypt" )) } /// Apply extra processing to the decrypted content of the file, with seek support. - fn filter_with_seek(&self, _entry: Entry) -> Result> { + fn filter_with_seek<'a>(&self, _entry: Entry<'a>) -> Result> { Err(anyhow::anyhow!( "This crypt does not support content filter with seek after decrypt" )) diff --git a/src/scripts/kirikiri/archive/xp3/mod.rs b/src/scripts/kirikiri/archive/xp3/mod.rs index c18ac32..a654c44 100644 --- a/src/scripts/kirikiri/archive/xp3/mod.rs +++ b/src/scripts/kirikiri/archive/xp3/mod.rs @@ -121,15 +121,15 @@ impl ScriptBuilder for Xp3ArchiveBuilder { Ok(Box::new(Xp3Archive::new(file, config, filename)?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(Xp3Archive::new(reader, config, filename)?)) } @@ -165,16 +165,16 @@ impl ScriptBuilder for Xp3ArchiveBuilder { #[derive(Debug)] /// Kirikiri XP3 Archive -pub struct Xp3Archive { - archive: archive::Xp3Archive, +pub struct Xp3Archive<'a> { + archive: archive::Xp3Archive<'a>, decrypt_simple_crypt: bool, decompress_mdf: bool, force_extract: bool, force_decrypt: bool, } -impl Xp3Archive { - pub fn new( +impl<'a> Xp3Archive<'a> { + pub fn new( stream: T, config: &ExtraConfig, filename: &str, @@ -202,7 +202,7 @@ impl Xp3Archive { } } -impl Script for Xp3Archive { +impl<'b> Script for Xp3Archive<'b> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } @@ -340,14 +340,14 @@ fn detect_script_type(filename: &str, buf: &[u8], buf_len: usize) -> Option>>, +struct Entry<'a> { + reader: Arc>>, index: archive::Xp3Entry, crypt: Arc>, /// used to cache segment reader that can't seek. Such as decompressor reader or some decrypter reader. - cache: Option>, + cache: Option>, /// used to store decrypted stream of current segment when the cryptor support seek when decrypting. - crypt_stream: Option>, + crypt_stream: Option>, pos: u64, base_offset: u64, entries_pos: Vec, @@ -357,7 +357,7 @@ struct Entry { } #[automatically_derived] -impl std::fmt::Debug for Entry { +impl<'a> std::fmt::Debug for Entry<'a> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Entry") .field("reader", &self.reader) @@ -374,9 +374,9 @@ impl std::fmt::Debug for Entry { } } -impl Entry { +impl<'a> Entry<'a> { fn new( - reader: Arc>>, + reader: Arc>>, index: archive::Xp3Entry, base_offset: u64, crypt: Arc>, @@ -409,7 +409,7 @@ impl Entry { } } -impl ArchiveContent for Entry { +impl<'b> ArchiveContent for Entry<'b> { fn name(&self) -> &str { &self.index.name } @@ -423,7 +423,7 @@ impl ArchiveContent for Entry { } } -impl Read for Entry { +impl<'a> Read for Entry<'a> { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { if self.pos >= self.index.original_size { self.cache.take(); @@ -549,7 +549,7 @@ impl Read for Entry { } } -impl Seek for Entry { +impl<'a> Seek for Entry<'a> { fn seek(&mut self, pos: SeekFrom) -> std::io::Result { let new_pos = match pos { SeekFrom::Start(p) => p, @@ -657,13 +657,13 @@ impl Seek for Entry { } } -struct SimpleCryptZlib { - inner: PrefixStream>>, +struct SimpleCryptZlib<'a> { + inner: PrefixStream>>>, index: archive::Xp3Entry, } -impl SimpleCryptZlib { - fn new(mut entry: Entry, index: archive::Xp3Entry) -> Result { +impl<'a> SimpleCryptZlib<'a> { + fn new(mut entry: Entry<'a>, index: archive::Xp3Entry) -> Result { entry.seek(SeekFrom::Start(0x15))?; let entry = StreamRegion::new(entry, 0x15, index.original_size)?; let inner = PrefixStream::new(vec![0xFF, 0xFE], ZlibDecoder::new(entry)); @@ -671,26 +671,26 @@ impl SimpleCryptZlib { } } -impl ArchiveContent for SimpleCryptZlib { +impl<'a> ArchiveContent for SimpleCryptZlib<'a> { fn name(&self) -> &str { &self.index.name } } -impl Read for SimpleCryptZlib { +impl<'a> Read for SimpleCryptZlib<'a> { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { self.inner.read(buf) } } #[derive(Debug)] -struct SimpleCryptInner { - inner: StreamRegion, +struct SimpleCryptInner<'a> { + inner: StreamRegion>, crypt: u8, } -impl SimpleCryptInner { - fn new(mut entry: Entry, crypt: u8) -> Result { +impl<'a> SimpleCryptInner<'a> { + fn new(mut entry: Entry<'a>, crypt: u8) -> Result { entry.seek(SeekFrom::Start(5))?; let size = entry.index.original_size; let entry = StreamRegion::new(entry, 5, size)?; @@ -701,7 +701,7 @@ impl SimpleCryptInner { } } -impl Read for SimpleCryptInner { +impl<'a> Read for SimpleCryptInner<'a> { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { let readed = self.inner.read(buf)?; match self.crypt { @@ -726,7 +726,7 @@ impl Read for SimpleCryptInner { } } -impl Seek for SimpleCryptInner { +impl<'a> Seek for SimpleCryptInner<'a> { fn seek(&mut self, pos: SeekFrom) -> std::io::Result { self.inner.seek(pos) } @@ -741,19 +741,19 @@ impl Seek for SimpleCryptInner { } #[derive(Debug)] -struct SimpleCrypt { - inner: PrefixStream, +struct SimpleCrypt<'a> { + inner: PrefixStream>, index: archive::Xp3Entry, } -impl SimpleCrypt { - fn new(entry: Entry, index: archive::Xp3Entry, crypt: u8) -> Result { +impl<'a> SimpleCrypt<'a> { + fn new(entry: Entry<'a>, index: archive::Xp3Entry, crypt: u8) -> Result { let inner = PrefixStream::new(vec![0xFF, 0xFE], SimpleCryptInner::new(entry, crypt)?); Ok(Self { inner, index }) } } -impl ArchiveContent for SimpleCrypt { +impl<'b> ArchiveContent for SimpleCrypt<'b> { fn name(&self) -> &str { &self.index.name } @@ -763,13 +763,13 @@ impl ArchiveContent for SimpleCrypt { } } -impl Read for SimpleCrypt { +impl<'a> Read for SimpleCrypt<'a> { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { self.inner.read(buf) } } -impl Seek for SimpleCrypt { +impl<'a> Seek for SimpleCrypt<'a> { fn seek(&mut self, pos: SeekFrom) -> std::io::Result { self.inner.seek(pos) } @@ -784,13 +784,13 @@ impl Seek for SimpleCrypt { } #[derive(Debug)] -struct MdfEntry { - inner: ZlibDecoder>, +struct MdfEntry<'a> { + inner: ZlibDecoder>>, index: archive::Xp3Entry, } -impl MdfEntry { - fn new(mut entry: Entry, index: archive::Xp3Entry) -> Result { +impl<'a> MdfEntry<'a> { + fn new(mut entry: Entry<'a>, index: archive::Xp3Entry) -> Result { entry.seek(SeekFrom::Start(8))?; let entry = StreamRegion::new(entry, 8, index.original_size)?; let inner = ZlibDecoder::new(entry); @@ -798,32 +798,32 @@ impl MdfEntry { } } -impl ArchiveContent for MdfEntry { +impl<'a> ArchiveContent for MdfEntry<'a> { fn name(&self) -> &str { &self.index.name } } -impl Read for MdfEntry { +impl<'a> Read for MdfEntry<'a> { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { self.inner.read(buf) } } #[derive(Debug)] -struct CustomFilterEntry { - inner: PrefixStream>, +struct CustomFilterEntry<'a> { + inner: PrefixStream>, index: archive::Xp3Entry, script_type: Option, } -impl Read for CustomFilterEntry { +impl<'a> Read for CustomFilterEntry<'a> { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { self.inner.read(buf) } } -impl ArchiveContent for CustomFilterEntry { +impl<'a> ArchiveContent for CustomFilterEntry<'a> { fn name(&self) -> &str { &self.index.name } @@ -834,19 +834,19 @@ impl ArchiveContent for CustomFilterEntry { } #[derive(Debug)] -struct CustomFilterWithSeekEntry { - inner: Box, +struct CustomFilterWithSeekEntry<'a> { + inner: Box, index: archive::Xp3Entry, script_type: Option, } -impl Read for CustomFilterWithSeekEntry { +impl<'a> Read for CustomFilterWithSeekEntry<'a> { fn read(&mut self, buf: &mut [u8]) -> std::io::Result { self.inner.read(buf) } } -impl Seek for CustomFilterWithSeekEntry { +impl<'a> Seek for CustomFilterWithSeekEntry<'a> { fn seek(&mut self, pos: SeekFrom) -> std::io::Result { self.inner.seek(pos) } @@ -860,7 +860,7 @@ impl Seek for CustomFilterWithSeekEntry { } } -impl ArchiveContent for CustomFilterWithSeekEntry { +impl<'b> ArchiveContent for CustomFilterWithSeekEntry<'b> { fn name(&self) -> &str { &self.index.name } diff --git a/src/scripts/kirikiri/archive/xp3/read.rs b/src/scripts/kirikiri/archive/xp3/read.rs index a80f5cd..bfa8239 100644 --- a/src/scripts/kirikiri/archive/xp3/read.rs +++ b/src/scripts/kirikiri/archive/xp3/read.rs @@ -7,8 +7,8 @@ use anyhow::Result; use std::io::{Read, Seek, SeekFrom}; use std::sync::{Arc, Mutex}; -impl Xp3Archive { - pub fn new( +impl<'a> Xp3Archive<'a> { + pub fn new( stream: T, config: &ExtraConfig, filename: &str, @@ -180,9 +180,9 @@ impl Xp3Archive { Ok(archive) } - fn get_index_stream<'a, T: Read + Seek + std::fmt::Debug + 'static>( - stream: &'a mut Box, - ) -> Result> { + fn get_index_stream<'c, 'b, T: Read + Seek + std::fmt::Debug + 'b>( + stream: &'c mut Box, + ) -> Result> { let index_type = stream.read_u8()?; Ok(match index_type { TVP_XP3_INDEX_ENCODE_RAW => { diff --git a/src/scripts/kirikiri/scn.rs b/src/scripts/kirikiri/scn.rs index 8e00a72..8cef46d 100644 --- a/src/scripts/kirikiri/scn.rs +++ b/src/scripts/kirikiri/scn.rs @@ -68,15 +68,15 @@ impl ScriptBuilder for ScnScriptBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, _archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ScnScript::new(reader, filename, config)?)) } diff --git a/src/scripts/musica/archive/paz.rs b/src/scripts/musica/archive/paz.rs index 62d4f6f..2eec13a 100644 --- a/src/scripts/musica/archive/paz.rs +++ b/src/scripts/musica/archive/paz.rs @@ -160,15 +160,15 @@ impl ScriptBuilder for PazArcBuilder { )?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(PazArc::new( reader, filename, @@ -240,8 +240,8 @@ impl PazEntry { } #[derive(Debug)] -pub struct PazArc { - stream: Arc>, +pub struct PazArc<'a> { + stream: Arc>>, schema: Schema, arc_key: ArcKey, entries: Vec, @@ -253,8 +253,8 @@ pub struct PazArc { const AUDIO_PAZ_NAMES: &[&str] = &["bgm", "se", "voice", "pmbgm", "pmse", "pmvoice"]; -impl PazArc { - pub fn new( +impl<'a> PazArc<'a> { + pub fn new( reader: T, filename: &str, archive_encoding: Encoding, @@ -389,7 +389,7 @@ impl PazArc { } } -impl Script for PazArc { +impl<'b> Script for PazArc<'b> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/qlie/archive/pack/mod.rs b/src/scripts/qlie/archive/pack/mod.rs index 8bd3927..5660b2a 100644 --- a/src/scripts/qlie/archive/pack/mod.rs +++ b/src/scripts/qlie/archive/pack/mod.rs @@ -78,15 +78,15 @@ impl ScriptBuilder for QliePackArchiveBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(QliePackArchive::new( reader, archive_encoding, @@ -145,16 +145,17 @@ pub fn is_this_format + ?Sized>(path: &P) -> Result { +pub struct QliePackArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { header: QlieHeader, encryption: Box, reader: Arc>, qkey: Option, entries: Vec, common_key: Option>, + _mark: std::marker::PhantomData<&'b ()>, } -impl QliePackArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> QliePackArchive<'b, T> { pub fn new( mut reader: T, archive_encoding: Encoding, @@ -253,6 +254,7 @@ impl QliePackArchive { qkey, entries, common_key, + _mark: std::marker::PhantomData, }) } @@ -299,7 +301,7 @@ impl QliePackArchive { } } -impl Script for QliePackArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for QliePackArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/softpal/arc/pac.rs b/src/scripts/softpal/arc/pac.rs index dd5f664..de9ee81 100644 --- a/src/scripts/softpal/arc/pac.rs +++ b/src/scripts/softpal/arc/pac.rs @@ -83,15 +83,15 @@ impl ScriptBuilder for SoftpalPacBuilder { )?)) } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(SoftpalPacArchive::new( reader, archive_encoding, @@ -138,12 +138,13 @@ struct SoftpalPacEntry { #[derive(Debug)] /// Softpal PAC archive reader. -pub struct SoftpalPacArchive { +pub struct SoftpalPacArchive<'a, T: Read + Seek + std::fmt::Debug + 'a> { reader: Arc>, entries: Vec, + _mark: std::marker::PhantomData<&'a ()>, } -impl SoftpalPacArchive { +impl<'a, T: Read + Seek + std::fmt::Debug + 'a> SoftpalPacArchive<'a, T> { fn new( mut reader: T, archive_encoding: Encoding, @@ -175,6 +176,7 @@ impl SoftpalPacArchive { return Ok(Self { reader: Arc::new(Mutex::new(reader)), entries: Vec::new(), + _mark: std::marker::PhantomData, }); } @@ -230,11 +232,12 @@ impl SoftpalPacArchive { Ok(Self { reader: Arc::new(Mutex::new(reader)), entries, + _mark: std::marker::PhantomData, }) } } -impl Script for SoftpalPacArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for SoftpalPacArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json } diff --git a/src/scripts/yaneurao/itufuru/archive.rs b/src/scripts/yaneurao/itufuru/archive.rs index 04552b1..c6a70ac 100644 --- a/src/scripts/yaneurao/itufuru/archive.rs +++ b/src/scripts/yaneurao/itufuru/archive.rs @@ -73,15 +73,15 @@ impl ScriptBuilder for ItufuruArchiveBuilder { } } - fn build_script_from_reader( + fn build_script_from_reader<'a>( &self, - reader: Box, + reader: Box, _filename: &str, _encoding: Encoding, archive_encoding: Encoding, config: &ExtraConfig, _archive: Option<&Box>, - ) -> Result> { + ) -> Result> { Ok(Box::new(ItufuruArchive::new( reader, archive_encoding, @@ -170,13 +170,14 @@ impl ArchiveContent for Entry { #[derive(Debug)] /// Yaneurao Itufuru Archive Script -pub struct ItufuruArchive { +pub struct ItufuruArchive<'b, T: Read + Seek + std::fmt::Debug + 'b> { reader: Arc>>, first_file_offset: u32, files: Vec, + _mark: std::marker::PhantomData<&'b ()>, } -impl ItufuruArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> ItufuruArchive<'b, T> { /// Creates a new `ItufuruArchive` /// /// * `reader` - The reader to read the archive data from @@ -219,11 +220,12 @@ impl ItufuruArchive { reader: Arc::new(Mutex::new(reader)), first_file_offset, files, + _mark: std::marker::PhantomData, }) } } -impl Script for ItufuruArchive { +impl<'b, T: Read + Seek + std::fmt::Debug + 'b> Script for ItufuruArchive<'b, T> { fn default_output_script_type(&self) -> OutputScriptType { OutputScriptType::Json }