Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbo: don't require vers header #830

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions libs/pbo/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ pub enum Error {
/// [`std::io::Error`]
Io(#[from] std::io::Error),

#[error("Missing Vers header")]
/// Missing Vers header
NoVersHeader,
#[error("HEMTT does not support the encountered PBO Mime type: {0}")]
/// HEMTT does not support the encountered PBO Mime type
UnsupportedMime(u32),
Expand Down
8 changes: 4 additions & 4 deletions libs/pbo/src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
/// An existing PBO file that can be read from
pub struct ReadablePbo<I: Seek + Read> {
properties: IndexMap<String, String>,
vers_header: Header,
vers_header: Option<Header>,
headers: Vec<Header>,
checksum: Checksum,
input: I,
Expand Down Expand Up @@ -54,8 +54,6 @@ impl<I: Seek + Read> ReadablePbo<I> {
}
}

let vers_header = vers_header.ok_or(Error::NoVersHeader)?;

for header in &headers {
input.seek(SeekFrom::Current(i64::from(header.size())))?;
}
Expand Down Expand Up @@ -177,7 +175,9 @@ impl<I: Seek + Read> ReadablePbo<I> {
/// if a file does not exist, but a header for it does
pub fn gen_checksum(&mut self) -> Result<Checksum, Error> {
let mut headers: Cursor<Vec<u8>> = Cursor::new(Vec::new());
self.vers_header.write_pbo(&mut headers)?;
if let Some(vers_header) = &self.vers_header {
vers_header.write_pbo(&mut headers)?;
}

if let Some(prefix) = self.properties.get("prefix") {
headers.write_cstring(b"prefix")?;
Expand Down
8 changes: 4 additions & 4 deletions libs/pbo/tests/ace_weather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ fn ace_weather_cba6f72c() {
41,
true,
3,
"cba6f72c",
"z\\ace\\addons\\weather",
Some("cba6f72c"),
Some("z\\ace\\addons\\weather"),
checksum,
checksum,
);
Expand Down Expand Up @@ -146,8 +146,8 @@ fn ace_weather_8bd4922f() {
45,
false,
3,
"8bd4922f",
"z\\ace\\addons\\weather",
Some("8bd4922f"),
Some("z\\ace\\addons\\weather"),
Checksum::from_bytes([
182, 44, 18, 201, 133, 232, 236, 162, 127, 37, 203, 45, 42, 137, 130, 36, 120, 104,
187, 203,
Expand Down
Binary file added libs/pbo/tests/exported_mission.VR.pbo
Binary file not shown.
24 changes: 24 additions & 0 deletions libs/pbo/tests/exported_mission.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![allow(clippy::unwrap_used)]

mod utils;
use std::fs::File;

use hemtt_pbo::Checksum;
use utils::*;

#[test]
fn exported_mission() {
let checksum = Checksum::from_bytes([
26, 16, 177, 232, 100, 38, 220, 28, 108, 190, 133, 74, 93, 171, 69, 59, 116, 181, 149, 252,
]);
let _ = pbo(
File::open("tests/exported_mission.VR.pbo").unwrap(),
9,
true,
0,
None,
None,
checksum,
checksum,
);
}
21 changes: 15 additions & 6 deletions libs/pbo/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,33 @@ pub fn pbo(
file_count: usize,
sorted: bool,
property_count: usize,
version: &str,
prefix: &str,
version: Option<&str>,
prefix: Option<&str>,
checksum: Checksum,
gen_checksum: Checksum,
) -> ReadablePbo<File> {
let mut pbo = ReadablePbo::from(file).unwrap();
assert_eq!(pbo.files().len(), file_count);
assert_eq!(pbo.properties().len(), property_count);
assert_eq!(pbo.is_sorted().is_ok(), sorted);
assert_eq!(pbo.properties().get("version"), Some(&version.to_string()));
assert_eq!(pbo.properties().get("prefix"), Some(&prefix.to_string()));
assert_eq!(
pbo.properties().get("version"),
version.map(std::string::ToString::to_string).as_ref()
);
assert_eq!(
pbo.properties().get("prefix"),
prefix.map(std::string::ToString::to_string).as_ref()
);
assert!(pbo.file("not_real").unwrap().is_none());
assert!(pbo.header("not_real").is_none());
if sorted {
assert_eq!(pbo.checksum(), &checksum);
}
assert!(Checksum::from_bytes(*pbo.gen_checksum().unwrap().as_bytes()) == gen_checksum);
assert_eq!(pbo.gen_checksum().unwrap(), gen_checksum);
// TODO hemtt can't do this correctly right now?
if prefix.is_some() {
assert!(Checksum::from_bytes(*pbo.gen_checksum().unwrap().as_bytes()) == gen_checksum);
assert_eq!(pbo.gen_checksum().unwrap(), gen_checksum);
}
pbo
}

Expand Down
Loading