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

Overhaul patch test code to not be horrible

And now it checks boot patches too!
This commit is contained in:
Joshua Goins 2022-10-17 15:03:07 -04:00
parent eebe89a4bd
commit 118d8404a4

View file

@ -1,7 +1,9 @@
use std::collections::HashMap; use std::collections::HashMap;
use physis::index; use physis::index;
use std::env; use std::env;
use std::path::Path;
use std::process::Command; use std::process::Command;
use hmac_sha512::Hash;
use physis::installer::install_game; use physis::installer::install_game;
use physis::patch::apply_patch; use physis::patch::apply_patch;
use walkdir::WalkDir; use walkdir::WalkDir;
@ -29,18 +31,11 @@ fn test_gamedata_extract() {
assert!(gamedata.extract("exd/root.exl").is_some()); assert!(gamedata.extract("exd/root.exl").is_some());
} }
#[test] fn make_temp_install_dir(name: &str) -> String {
#[cfg_attr(not(feature = "patch_testing"), ignore)]
fn test_patching() {
let patch_dir = env::var("FFXIV_PATCH_DIR").unwrap();
let patcher_exe = env::var("FFXIV_XIV_LAUNCHER_PATCHER").unwrap();
let installer_exe = env::var("FFXIV_INSTALLER").unwrap(); let installer_exe = env::var("FFXIV_INSTALLER").unwrap();
println!("Beginning game installation...");
// FIXME: lmao what is going on here
let mut game_dir = env::temp_dir(); let mut game_dir = env::temp_dir();
game_dir.push("game_test"); game_dir.push(name);
if std::fs::read_dir(&game_dir).ok().is_some() { if std::fs::read_dir(&game_dir).ok().is_some() {
std::fs::remove_dir_all(&game_dir).unwrap(); std::fs::remove_dir_all(&game_dir).unwrap();
@ -50,94 +45,89 @@ fn test_patching() {
install_game(&installer_exe, game_dir.as_path().to_str().unwrap()).ok().unwrap(); install_game(&installer_exe, game_dir.as_path().to_str().unwrap()).ok().unwrap();
let mut xivlauncher_game_dir = env::temp_dir(); game_dir.as_path().to_str().unwrap().parse().unwrap()
xivlauncher_game_dir.push("game_test_xivlauncher"); }
if std::fs::read_dir(&xivlauncher_game_dir).ok().is_some() { fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> {
std::fs::remove_dir_all(&xivlauncher_game_dir).unwrap(); let mut file_hashes : HashMap<String, [u8; 64]> = HashMap::new();
}
std::fs::create_dir_all(&xivlauncher_game_dir).unwrap();
install_game(&installer_exe, xivlauncher_game_dir.as_path().to_str().unwrap()).ok().unwrap(); WalkDir::new(game_dir)
.into_iter()
.filter_map(Result::ok)
.filter(|e| !e.file_type().is_dir())
.for_each(|x| {
let file = std::fs::read(x.path()).unwrap();
let xivlauncher_game_dir = xivlauncher_game_dir.as_path(); let mut hash = hmac_sha512::Hash::new();
let physis_game_dir = game_dir.as_path(); hash.update(&file);
let sha = hash.finalize();
// TODO: only the first two patches are checked let mut rel_path = x.path();
let patches = ["game/D2017.07.11.0000.0001.patch", rel_path = rel_path.strip_prefix(game_dir).unwrap();
"game/D2017.09.24.0000.0001.patch"];
println!("The game installation is now complete. Now testing game patching..."); file_hashes.insert(rel_path.to_str().unwrap().to_string(), sha);
});
file_hashes
}
fn physis_install_patch(game_directory: &str, data_directory: &str, patch_name : &str) {
let patch_dir = env::var("FFXIV_PATCH_DIR").unwrap();
let patch_path = format!("{}/{}", patch_dir, &patch_name);
let data_dir = format!("{}/{}", game_directory, data_directory);
apply_patch(&data_dir, &patch_path).unwrap();
}
fn xivlauncher_install_patch(game_directory: &str, data_directory: &str, patch_name : &str) {
let patch_dir = env::var("FFXIV_PATCH_DIR").unwrap();
let patcher_exe = env::var("FFXIV_XIV_LAUNCHER_PATCHER").unwrap();
let patch_path = format!("Z:\\{}\\{}", patch_dir, &patch_name);
let game_dir = format!("Z:\\{}\\{}", game_directory, data_directory);
// run it on xiv's patchinstaller first
// TODO: check for windows systems // TODO: check for windows systems
for patch in patches { Command::new("/usr/bin/wine")
let patch_path = format!("Z:\\{}\\{}", patch_dir, &patch);
let game_dir = format!("Z:\\{}\\game", xivlauncher_game_dir.to_str().unwrap());
let output = Command::new("/usr/bin/wine")
.args([&patcher_exe, .args([&patcher_exe,
"install", "install",
&patch_path, &patch_path,
&game_dir]) &game_dir])
.output() .output()
.unwrap(); .unwrap();
}
println!("{:#?}", output); #[test]
#[cfg_attr(not(feature = "patch_testing"), ignore)]
fn test_patching() {
println!("Beginning game installation...");
let physis_dir = make_temp_install_dir("game_test");
let xivlauncher_dir = make_temp_install_dir("game_test_xivlauncher");
let boot_patches = ["boot/2022.03.25.0000.0001.patch",
"boot/2022.08.05.0000.0001.patch"];
println!("The game installation is now complete. Now running boot patching...");
for patch in boot_patches {
xivlauncher_install_patch(&xivlauncher_dir, "boot", patch);
physis_install_patch(&physis_dir, "boot", patch);
} }
// now run it on physis let game_patches = ["game/D2017.07.11.0000.0001.patch",
for patch in patches { "game/D2017.09.24.0000.0001.patch"];
let patch_path = format!("{}/{}", patch_dir, &patch);
let data_dir = format!("{}/{}", physis_game_dir.to_str().unwrap(), "game");
apply_patch(&data_dir, &patch_path).unwrap(); println!("Boot patching is now complete. Now running game patching...");
for patch in game_patches {
xivlauncher_install_patch(&xivlauncher_dir, "game", patch);
physis_install_patch(&physis_dir, "game", patch);
} }
println!("Game patching is now complete. Proceeding to checksum matching..."); println!("Game patching is now complete. Proceeding to checksum matching...");
let mut xivlauncher_files : HashMap<String, [u8; 64]> = HashMap::new(); let xivlauncher_files = fill_dir_hash(&xivlauncher_dir);
let physis_files = fill_dir_hash(&physis_dir);
println!("{:#?}", xivlauncher_game_dir);
// TODO: consolidate into a closure or generic function
WalkDir::new(xivlauncher_game_dir)
.into_iter()
.filter_map(Result::ok)
.filter(|e| !e.file_type().is_dir())
.for_each(|x| {
let file = std::fs::read(x.path()).unwrap();
let mut hash = hmac_sha512::Hash::new();
hash.update(&file);
let sha = hash.finalize();
let mut rel_path = x.path();
rel_path = rel_path.strip_prefix(xivlauncher_game_dir).unwrap();
xivlauncher_files.insert(rel_path.to_str().unwrap().to_string(), sha);
});
let mut physis_files : HashMap<String, [u8; 64]> = HashMap::new();
WalkDir::new(physis_game_dir)
.into_iter()
.filter_map(Result::ok)
.filter(|e| !e.file_type().is_dir())
.for_each(|x| {
if !x.file_type().is_dir() {
let file = std::fs::read(x.path()).unwrap();
let mut hash = hmac_sha512::Hash::new();
hash.update(&file);
let sha = hash.finalize();
let mut rel_path = x.path();
rel_path = rel_path.strip_prefix(physis_game_dir).unwrap();
physis_files.insert(rel_path.to_str().unwrap().to_string(), sha);
}
});
assert_eq!(physis_files, xivlauncher_files); assert_eq!(physis_files, xivlauncher_files);
} }