mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 10:54:38 +00:00
code cleanup
This commit is contained in:
parent
c0a1c5154c
commit
5104b41878
6 changed files with 16 additions and 21 deletions
|
@ -11,7 +11,6 @@ edition = "2021"
|
|||
[dependencies]
|
||||
byteorder = "*"
|
||||
strum = { version = "*", features = ["derive"] }
|
||||
hashbrown = "*"
|
||||
thiserror = "*"
|
||||
|
||||
[profile.release]
|
||||
|
|
|
@ -8,7 +8,5 @@ fn main() -> Result<(), un_pak::Error> {
|
|||
Err(e) => println!("{e}"),
|
||||
}
|
||||
}
|
||||
Err(un_pak::Error::PakInvalid(
|
||||
"no version can parse".to_string(),
|
||||
))
|
||||
Err(un_pak::Error::Other("no version can parse".to_string()))
|
||||
}
|
||||
|
|
10
src/error.rs
10
src/error.rs
|
@ -1,13 +1,17 @@
|
|||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("error parsing pak: {0}")]
|
||||
PakInvalid(String),
|
||||
#[error("expected magic of {} but found {0}", super::MAGIC)]
|
||||
MagicMismatch(u32),
|
||||
#[error("parsed with {0} but pak was {0}")]
|
||||
VersionMismatch(super::Version, super::Version),
|
||||
#[error("error reading file: {0}")]
|
||||
IoError(#[from] std::io::Error),
|
||||
#[error("error converting to enum: {0}")]
|
||||
#[error("error converting enum: {0}")]
|
||||
StrumError(#[from] strum::ParseError),
|
||||
#[error("error converting to utf8: {0}")]
|
||||
Utf8Error(#[from] std::string::FromUtf8Error),
|
||||
#[error("error converting to utf16: {0}")]
|
||||
Utf16Error(#[from] std::string::FromUtf16Error),
|
||||
#[error("{0}")]
|
||||
Other(String),
|
||||
}
|
||||
|
|
|
@ -52,17 +52,10 @@ impl Footer {
|
|||
}),
|
||||
};
|
||||
if super::MAGIC != footer.magic {
|
||||
return Err(super::Error::PakInvalid(format!(
|
||||
"incorrect magic - expected {} but got {}",
|
||||
super::MAGIC,
|
||||
footer.magic
|
||||
)));
|
||||
return Err(super::Error::MagicMismatch(footer.magic));
|
||||
}
|
||||
if version != &footer.version {
|
||||
return Err(super::Error::PakInvalid(format!(
|
||||
"incorrect version - parsed with {} but is {}",
|
||||
version, footer.version
|
||||
)));
|
||||
return Err(super::Error::VersionMismatch(*version, footer.version));
|
||||
}
|
||||
Ok(footer)
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ pub const MAGIC: u32 = 0x5A6F12E1;
|
|||
#[repr(u32)]
|
||||
#[derive(
|
||||
Default,
|
||||
Copy,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
|
@ -38,14 +38,14 @@ pub enum Version {
|
|||
PathHashIndex, // more compression methods
|
||||
}
|
||||
|
||||
// strum shouldn't need to be installed
|
||||
// strum shouldn't need to be installed by users
|
||||
impl Version {
|
||||
pub fn iter() -> VersionIter {
|
||||
<Version as strum::IntoEnumIterator>::iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Copy, Clone, PartialEq, Eq, Debug, strum::Display, strum::EnumString)]
|
||||
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, strum::Display, strum::EnumString)]
|
||||
pub enum Compression {
|
||||
#[default]
|
||||
None,
|
||||
|
|
|
@ -5,7 +5,7 @@ use super::Version;
|
|||
pub struct Pak {
|
||||
pub version: Version,
|
||||
pub footer: super::Footer,
|
||||
pub entries: hashbrown::HashMap<String, super::Entry>,
|
||||
pub index: super::Index,
|
||||
}
|
||||
|
||||
impl Pak {
|
||||
|
@ -17,10 +17,11 @@ impl Pak {
|
|||
// parse footer info to get index offset
|
||||
let footer = super::Footer::new(&mut reader, &version)?;
|
||||
reader.seek(io::SeekFrom::Start(footer.offset))?;
|
||||
let index = super::Index::new(&mut reader, &version)?;
|
||||
Ok(Self {
|
||||
version,
|
||||
footer,
|
||||
entries: hashbrown::HashMap::new(),
|
||||
index,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue