1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-20 03:37:47 +00:00

Add file info testing, fix parsing bug

This commit is contained in:
Joshua Goins 2022-10-20 11:44:54 -04:00
parent c7105e964d
commit ab10cf4975
4 changed files with 54 additions and 9 deletions

BIN
resources/tests/test.fiin Normal file

Binary file not shown.

1
resources/tests/test.txt Normal file
View file

@ -0,0 +1 @@
Hello!

View file

@ -1,8 +1,9 @@
use crate::gamedata::MemoryBuffer;
use binrw::binrw;
use binrw::{binrw, BinrwNamedArgs, NullString};
use binrw::BinRead;
use std::fs::read;
use std::io::Cursor;
use std::ffi::CStr;
#[binrw]
#[brw(magic = b"FileInfo")]
@ -10,7 +11,6 @@ use std::io::Cursor;
#[brw(little)]
pub struct FileInfo {
#[brw(pad_before = 16)]
#[br(ignore)]
#[bw(calc = 1024)]
unknown: i32,
@ -20,24 +20,24 @@ pub struct FileInfo {
#[brw(pad_before = 992)]
#[br(count = entries_size / 96)]
entries: Vec<FIINEntry>,
pub entries: Vec<FIINEntry>,
}
#[binrw]
#[derive(Debug)]
pub struct FIINEntry {
file_size: i32,
pub file_size: i32,
#[brw(pad_before = 4)]
#[br(count = 64)]
#[br(map = | x: Vec < u8 > | String::from_utf8(x).unwrap())]
#[bw(map = | x : &String | x.as_bytes().to_vec())]
#[bw(pad_size_to = 64)]
file_name: String,
#[bw(map = |x : &String | x.as_bytes())]
#[br(map = | x: Vec<u8> | String::from_utf8(x).unwrap().trim_matches(char::from(0)).to_string())]
pub file_name: String,
#[br(count = 24)]
#[bw(pad_size_to = 24)]
sha1: Vec<u8>,
pub sha1: Vec<u8>,
}
impl FileInfo {
@ -52,7 +52,7 @@ impl FileInfo {
/// hashes.
///
/// The new FileInfo structure can then be serialized back into retail-compatible form.
pub fn new(file_names: Vec<&str>) -> Option<FileInfo> {
pub fn new(file_names: &[&str]) -> Option<FileInfo> {
let mut entries = vec![];
for name in file_names {
@ -68,3 +68,31 @@ impl FileInfo {
Some(FileInfo { entries })
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs::read;
use std::path::PathBuf;
use crate::fiin::FileInfo;
fn common_setup() -> FileInfo {
let mut d = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
d.push("resources/tests");
d.push("test.fiin");
FileInfo::from_existing(&read(d).unwrap()).unwrap()
}
#[test]
fn basic_parsing() {
let fiin = common_setup();
assert_eq!(fiin.entries[0].file_name,
"test.txt");
assert_eq!(fiin.entries[1].file_name,
"test.exl");
}
}

View file

@ -1,11 +1,13 @@
use std::collections::HashMap;
use physis::index;
use std::env;
use std::fs::read;
use std::process::Command;
use hmac_sha512::Hash;
use physis::installer::install_game;
use physis::patch::apply_patch;
use walkdir::WalkDir;
use physis::fiin::FileInfo;
#[test]
#[cfg_attr(not(feature = "retail_game_testing"), ignore)]
@ -30,6 +32,20 @@ fn test_gamedata_extract() {
assert!(gamedata.extract("exd/root.exl").is_some());
}
#[test]
#[cfg_attr(not(feature = "retail_game_testing"), ignore)]
fn test_fiin() {
let game_dir = env::var("FFXIV_GAME_DIR").unwrap();
let fiin_path = format!("{game_dir}/boot/fileinfo.fiin");
let fiin = FileInfo::from_existing(&read(fiin_path).unwrap()).unwrap();
assert_eq!(fiin.entries[0].file_name,
"steam_api.dll");
assert_eq!(fiin.entries[1].file_name,
"steam_api64.dll");
}
fn make_temp_install_dir(name: &str) -> String {
let installer_exe = env::var("FFXIV_INSTALLER").unwrap();