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