From 07bbbbc5ed5fc73739d5b32b5a7b2c58f366f3f4 Mon Sep 17 00:00:00 2001 From: spuds <71292624+bananaturtlesandwich@users.noreply.github.com> Date: Wed, 11 Jan 2023 22:42:00 +0000 Subject: [PATCH] add version getting example --- examples/version.rs | 19 +++++++++++++++++++ src/error.rs | 7 +++++-- src/footer.rs | 5 ++++- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 examples/version.rs diff --git a/examples/version.rs b/examples/version.rs new file mode 100644 index 0000000..b69f457 --- /dev/null +++ b/examples/version.rs @@ -0,0 +1,19 @@ +fn main() -> Result<(), un_pak::Error> { + // drag onto or open any pak with the example + let path = std::env::args().nth(1).unwrap_or_default(); + for ver in un_pak::Version::iter() { + match un_pak::Pak::new( + std::io::BufReader::new(std::fs::OpenOptions::new().read(true).open(&path)?), + ver, + ) { + Ok(un_pak::Pak { version, .. }) | Err(un_pak::Error::Version { version, .. }) => { + println!("{}", version); + break; + } + _ => continue, + } + } + // so you can read the results + std::thread::sleep(std::time::Duration::from_secs(10)); + Ok(()) +} diff --git a/src/error.rs b/src/error.rs index aa43810..3648c6a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -12,8 +12,11 @@ pub enum Error { IntoInner(#[from] std::io::IntoInnerError>>), #[error("found magic of {0:#x} instead of {:#x}", super::MAGIC)] Magic(u32), - #[error("used version {0} but pak is version {1}")] - Version(super::Version, super::Version), + #[error("used version {used} but pak is version {version}")] + Version { + used: super::Version, + version: super::Version, + }, #[error("got {0}, which is not a boolean")] Bool(u8), #[error("{0}")] diff --git a/src/footer.rs b/src/footer.rs index 8f48e97..747fd84 100644 --- a/src/footer.rs +++ b/src/footer.rs @@ -57,7 +57,10 @@ impl Footer { return Err(super::Error::Magic(footer.magic)); } if version != footer.version { - return Err(super::Error::Version(version, footer.version)); + return Err(super::Error::Version { + used: version, + version: footer.version, + }); } Ok(footer) }