When failing to parse, show error for each checked version

This commit is contained in:
Truman Kilen 2023-04-13 11:09:50 -05:00
parent ad22ba9b1a
commit 2de7924198
2 changed files with 13 additions and 4 deletions

View file

@ -13,6 +13,9 @@ pub enum Error {
#[error("io error: {0}")] #[error("io error: {0}")]
Io(#[from] std::io::Error), Io(#[from] std::io::Error),
#[error("fmt error: {0}")]
Fmt(#[from] std::fmt::Error),
#[error("utf8 conversion: {0}")] #[error("utf8 conversion: {0}")]
Utf8(#[from] std::string::FromUtf8Error), Utf8(#[from] std::string::FromUtf8Error),
@ -68,8 +71,8 @@ pub enum Error {
#[error("error with OsString")] #[error("error with OsString")]
OsString(std::ffi::OsString), OsString(std::ffi::OsString),
#[error("version unsupported or is encrypted (possibly missing --aes-key?)")] #[error("{0}version unsupported or is encrypted (possibly missing --aes-key?)")]
UnsuportedOrEncrypted, UnsuportedOrEncrypted(String),
#[error("{0}")] #[error("{0}")]
Other(String), Other(String),

View file

@ -83,15 +83,21 @@ impl PakReader {
mut reader: R, mut reader: R,
key: Option<aes::Aes256>, key: Option<aes::Aes256>,
) -> Result<Self, super::Error> { ) -> Result<Self, super::Error> {
use std::fmt::Write;
let mut log = "\n".to_owned();
for ver in Version::iter() { for ver in Version::iter() {
match Pak::read(&mut reader, ver, key.clone()) { match Pak::read(&mut reader, ver, key.clone()) {
Ok(pak) => { Ok(pak) => {
return Ok(PakReader { pak, key }); return Ok(PakReader { pak, key });
} }
_ => continue, Err(err) => {
writeln!(log, "trying version {} failed: {}", ver, err)?;
continue;
}
} }
} }
Err(super::Error::UnsuportedOrEncrypted) Err(super::Error::UnsuportedOrEncrypted(log))
} }
pub fn version(&self) -> super::Version { pub fn version(&self) -> super::Version {