From 03dd3a63ed2bfb2563cd08a3a4b47d59e28d03a0 Mon Sep 17 00:00:00 2001 From: spuds <71292624+bananaturtlesandwich@users.noreply.github.com> Date: Sun, 27 Aug 2023 15:24:47 +0100 Subject: [PATCH] add method for known versions --- repak/src/pak.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/repak/src/pak.rs b/repak/src/pak.rs index 9c575b6..7b4a738 100644 --- a/repak/src/pak.rs +++ b/repak/src/pak.rs @@ -92,18 +92,21 @@ impl PakReader { for ver in Version::iter() { match Pak::read(&mut *reader, ver, key.as_ref()) { - Ok(pak) => { - return Ok(PakReader { pak, key }); - } - Err(err) => { - writeln!(log, "trying version {} failed: {}", ver, err)?; - continue; - } + Ok(pak) => return Ok(Self { pak, key }), + Err(err) => writeln!(log, "trying version {} failed: {}", ver, err)?, } } Err(super::Error::UnsuportedOrEncrypted(log)) } + pub fn new( + reader: &mut R, + version: super::Version, + key: Option, + ) -> Result { + Pak::read(reader, version, key.as_ref()).map(|pak| Self { pak, key }) + } + pub fn version(&self) -> super::Version { self.pak.version }