mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +00:00
add version getting example
This commit is contained in:
parent
774be9ecb0
commit
07bbbbc5ed
3 changed files with 28 additions and 3 deletions
19
examples/version.rs
Normal file
19
examples/version.rs
Normal file
|
@ -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(())
|
||||||
|
}
|
|
@ -12,8 +12,11 @@ pub enum Error {
|
||||||
IntoInner(#[from] std::io::IntoInnerError<std::io::BufWriter<Vec<u8>>>),
|
IntoInner(#[from] std::io::IntoInnerError<std::io::BufWriter<Vec<u8>>>),
|
||||||
#[error("found magic of {0:#x} instead of {:#x}", super::MAGIC)]
|
#[error("found magic of {0:#x} instead of {:#x}", super::MAGIC)]
|
||||||
Magic(u32),
|
Magic(u32),
|
||||||
#[error("used version {0} but pak is version {1}")]
|
#[error("used version {used} but pak is version {version}")]
|
||||||
Version(super::Version, super::Version),
|
Version {
|
||||||
|
used: super::Version,
|
||||||
|
version: super::Version,
|
||||||
|
},
|
||||||
#[error("got {0}, which is not a boolean")]
|
#[error("got {0}, which is not a boolean")]
|
||||||
Bool(u8),
|
Bool(u8),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
|
|
|
@ -57,7 +57,10 @@ impl Footer {
|
||||||
return Err(super::Error::Magic(footer.magic));
|
return Err(super::Error::Magic(footer.magic));
|
||||||
}
|
}
|
||||||
if version != footer.version {
|
if version != footer.version {
|
||||||
return Err(super::Error::Version(version, footer.version));
|
return Err(super::Error::Version {
|
||||||
|
used: version,
|
||||||
|
version: footer.version,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Ok(footer)
|
Ok(footer)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue