diff --git a/libs/pbo/src/error.rs b/libs/pbo/src/error.rs index 3944536a..641d2295 100644 --- a/libs/pbo/src/error.rs +++ b/libs/pbo/src/error.rs @@ -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), diff --git a/libs/pbo/src/read.rs b/libs/pbo/src/read.rs index 978ecfd0..2090b8d7 100644 --- a/libs/pbo/src/read.rs +++ b/libs/pbo/src/read.rs @@ -15,7 +15,7 @@ use crate::{ /// An existing PBO file that can be read from pub struct ReadablePbo { properties: IndexMap, - vers_header: Header, + vers_header: Option
, headers: Vec
, checksum: Checksum, input: I, @@ -54,8 +54,6 @@ impl ReadablePbo { } } - let vers_header = vers_header.ok_or(Error::NoVersHeader)?; - for header in &headers { input.seek(SeekFrom::Current(i64::from(header.size())))?; } @@ -177,7 +175,9 @@ impl ReadablePbo { /// if a file does not exist, but a header for it does pub fn gen_checksum(&mut self) -> Result { let mut headers: Cursor> = 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")?; diff --git a/libs/pbo/tests/ace_weather.rs b/libs/pbo/tests/ace_weather.rs index bbca179a..8e81c68d 100644 --- a/libs/pbo/tests/ace_weather.rs +++ b/libs/pbo/tests/ace_weather.rs @@ -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, ); @@ -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, diff --git a/libs/pbo/tests/exported_mission.VR.pbo b/libs/pbo/tests/exported_mission.VR.pbo new file mode 100644 index 00000000..021891ff Binary files /dev/null and b/libs/pbo/tests/exported_mission.VR.pbo differ diff --git a/libs/pbo/tests/exported_mission.rs b/libs/pbo/tests/exported_mission.rs new file mode 100644 index 00000000..69666b69 --- /dev/null +++ b/libs/pbo/tests/exported_mission.rs @@ -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, + ); +} diff --git a/libs/pbo/tests/utils.rs b/libs/pbo/tests/utils.rs index f62bdff2..1eae32c0 100644 --- a/libs/pbo/tests/utils.rs +++ b/libs/pbo/tests/utils.rs @@ -13,8 +13,8 @@ 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 { @@ -22,15 +22,24 @@ pub fn pbo( 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 }