From 5b7cf1d6a370e704ce9c7b7e92e312501190cdb9 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 6 Aug 2022 20:38:15 -0400 Subject: [PATCH] Add support for reading the file info format I revisited this format, and discovered a lot of stuff I did wrong the first time around when writing libxiv. Now that's fixed! --- src/fiin.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/lib.rs | 5 ++++- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/fiin.rs diff --git a/src/fiin.rs b/src/fiin.rs new file mode 100644 index 0000000..65b0481 --- /dev/null +++ b/src/fiin.rs @@ -0,0 +1,39 @@ +use std::ffi::CString; +use std::io::Cursor; +use binrw::binread; +use crate::gamedata::MemoryBuffer; +use binrw::BinRead; + +#[binread] +#[br(magic = b"FileInfo")] +#[derive(Debug)] +pub struct FileInfo { + #[br(pad_before = 20)] + #[br(temp)] + entries_size : i32, + + #[br(pad_before = 992)] + #[br(count = entries_size / 96)] + entries : Vec +} + +#[binread] +#[derive(Debug)] +pub struct FIINEntry { + file_size : i32, + + #[br(pad_before = 4)] + #[br(count = 64)] + #[br(map = | x: Vec < u8 > | String::from_utf8(x).unwrap())] + file_name: String, + + #[br(count = 24)] + sha1 : Vec +} + +impl FileInfo { + pub fn from_existing(buffer : &MemoryBuffer) -> Option { + let mut cursor = Cursor::new(buffer); + Some(FileInfo::read(&mut cursor).ok()?) + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index f05255a..e69877a 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,4 +52,7 @@ pub mod exh; pub mod exd; // Reading Havok XML sidecar files. -pub mod skeleton; \ No newline at end of file +pub mod skeleton; + +// Reading file into files (FIIN). +pub mod fiin; \ No newline at end of file