mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-20 03:37:47 +00:00
Overhaul patch test code to not be horrible
And now it checks boot patches too!
This commit is contained in:
parent
eebe89a4bd
commit
118d8404a4
1 changed files with 68 additions and 78 deletions
|
@ -1,7 +1,9 @@
|
|||
use std::collections::HashMap;
|
||||
use physis::index;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use hmac_sha512::Hash;
|
||||
use physis::installer::install_game;
|
||||
use physis::patch::apply_patch;
|
||||
use walkdir::WalkDir;
|
||||
|
@ -29,18 +31,11 @@ fn test_gamedata_extract() {
|
|||
assert!(gamedata.extract("exd/root.exl").is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[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();
|
||||
fn make_temp_install_dir(name: &str) -> String {
|
||||
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();
|
||||
game_dir.push("game_test");
|
||||
game_dir.push(name);
|
||||
|
||||
if std::fs::read_dir(&game_dir).ok().is_some() {
|
||||
std::fs::remove_dir_all(&game_dir).unwrap();
|
||||
|
@ -50,58 +45,13 @@ fn test_patching() {
|
|||
|
||||
install_game(&installer_exe, game_dir.as_path().to_str().unwrap()).ok().unwrap();
|
||||
|
||||
let mut xivlauncher_game_dir = env::temp_dir();
|
||||
xivlauncher_game_dir.push("game_test_xivlauncher");
|
||||
game_dir.as_path().to_str().unwrap().parse().unwrap()
|
||||
}
|
||||
|
||||
if std::fs::read_dir(&xivlauncher_game_dir).ok().is_some() {
|
||||
std::fs::remove_dir_all(&xivlauncher_game_dir).unwrap();
|
||||
}
|
||||
std::fs::create_dir_all(&xivlauncher_game_dir).unwrap();
|
||||
fn fill_dir_hash(game_dir: &str) -> HashMap<String, [u8; 64]> {
|
||||
let mut file_hashes : HashMap<String, [u8; 64]> = HashMap::new();
|
||||
|
||||
install_game(&installer_exe, xivlauncher_game_dir.as_path().to_str().unwrap()).ok().unwrap();
|
||||
|
||||
let xivlauncher_game_dir = xivlauncher_game_dir.as_path();
|
||||
let physis_game_dir = game_dir.as_path();
|
||||
|
||||
// TODO: only the first two patches are checked
|
||||
let patches = ["game/D2017.07.11.0000.0001.patch",
|
||||
"game/D2017.09.24.0000.0001.patch"];
|
||||
|
||||
println!("The game installation is now complete. Now testing game patching...");
|
||||
|
||||
// run it on xiv's patchinstaller first
|
||||
// TODO: check for windows systems
|
||||
for patch in patches {
|
||||
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,
|
||||
"install",
|
||||
&patch_path,
|
||||
&game_dir])
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
println!("{:#?}", output);
|
||||
}
|
||||
|
||||
// now run it on physis
|
||||
for patch in patches {
|
||||
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!("Game patching is now complete. Proceeding to checksum matching...");
|
||||
|
||||
let mut xivlauncher_files : HashMap<String, [u8; 64]> = HashMap::new();
|
||||
|
||||
println!("{:#?}", xivlauncher_game_dir);
|
||||
|
||||
// TODO: consolidate into a closure or generic function
|
||||
WalkDir::new(xivlauncher_game_dir)
|
||||
WalkDir::new(game_dir)
|
||||
.into_iter()
|
||||
.filter_map(Result::ok)
|
||||
.filter(|e| !e.file_type().is_dir())
|
||||
|
@ -113,31 +63,71 @@ fn test_patching() {
|
|||
let sha = hash.finalize();
|
||||
|
||||
let mut rel_path = x.path();
|
||||
rel_path = rel_path.strip_prefix(xivlauncher_game_dir).unwrap();
|
||||
rel_path = rel_path.strip_prefix(game_dir).unwrap();
|
||||
|
||||
xivlauncher_files.insert(rel_path.to_str().unwrap().to_string(), sha);
|
||||
});
|
||||
file_hashes.insert(rel_path.to_str().unwrap().to_string(), sha);
|
||||
});
|
||||
|
||||
let mut physis_files : HashMap<String, [u8; 64]> = HashMap::new();
|
||||
file_hashes
|
||||
}
|
||||
|
||||
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();
|
||||
fn physis_install_patch(game_directory: &str, data_directory: &str, patch_name : &str) {
|
||||
let patch_dir = env::var("FFXIV_PATCH_DIR").unwrap();
|
||||
|
||||
let mut hash = hmac_sha512::Hash::new();
|
||||
hash.update(&file);
|
||||
let sha = hash.finalize();
|
||||
let patch_path = format!("{}/{}", patch_dir, &patch_name);
|
||||
let data_dir = format!("{}/{}", game_directory, data_directory);
|
||||
|
||||
let mut rel_path = x.path();
|
||||
rel_path = rel_path.strip_prefix(physis_game_dir).unwrap();
|
||||
apply_patch(&data_dir, &patch_path).unwrap();
|
||||
}
|
||||
|
||||
physis_files.insert(rel_path.to_str().unwrap().to_string(), sha);
|
||||
}
|
||||
});
|
||||
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);
|
||||
|
||||
// TODO: check for windows systems
|
||||
Command::new("/usr/bin/wine")
|
||||
.args([&patcher_exe,
|
||||
"install",
|
||||
&patch_path,
|
||||
&game_dir])
|
||||
.output()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[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);
|
||||
}
|
||||
|
||||
let game_patches = ["game/D2017.07.11.0000.0001.patch",
|
||||
"game/D2017.09.24.0000.0001.patch"];
|
||||
|
||||
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...");
|
||||
|
||||
let xivlauncher_files = fill_dir_hash(&xivlauncher_dir);
|
||||
let physis_files = fill_dir_hash(&physis_dir);
|
||||
|
||||
assert_eq!(physis_files, xivlauncher_files);
|
||||
}
|
Loading…
Add table
Reference in a new issue