From 67d2f035c3e7266f0e33df1b42f96eba20b4d1da Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 20 Oct 2022 11:45:55 -0400 Subject: [PATCH] Reformat code with rustfmt --- src/dat.rs | 2 +- src/fiin.rs | 13 ++++------- src/model.rs | 14 ++++++++---- src/mtrl.rs | 2 +- src/patch.rs | 41 +++++++++++++++++++++------------ src/tex.rs | 2 +- tests/integration_test.rs | 48 +++++++++++++++++++-------------------- 7 files changed, 68 insertions(+), 54 deletions(-) diff --git a/src/dat.rs b/src/dat.rs index 2f3efc3..687ccf6 100755 --- a/src/dat.rs +++ b/src/dat.rs @@ -1,9 +1,9 @@ use crate::gamedata::MemoryBuffer; use crate::model::ModelFileHeader; use crate::sqpack::read_data_block; -use binrw::{BinReaderExt, binrw}; use binrw::BinRead; use binrw::BinWrite; +use binrw::{binrw, BinReaderExt}; use std::io::Write; use std::io::{Cursor, Read, Seek, SeekFrom}; diff --git a/src/fiin.rs b/src/fiin.rs index db89e1e..d6be0f8 100644 --- a/src/fiin.rs +++ b/src/fiin.rs @@ -1,9 +1,9 @@ use crate::gamedata::MemoryBuffer; -use binrw::{binrw, BinrwNamedArgs, NullString}; use binrw::BinRead; +use binrw::{binrw, BinrwNamedArgs, NullString}; +use std::ffi::CStr; use std::fs::read; use std::io::Cursor; -use std::ffi::CStr; #[binrw] #[brw(magic = b"FileInfo")] @@ -72,9 +72,9 @@ impl FileInfo { #[cfg(test)] mod tests { use super::*; + use crate::fiin::FileInfo; 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")); @@ -88,11 +88,8 @@ mod tests { fn basic_parsing() { let fiin = common_setup(); - assert_eq!(fiin.entries[0].file_name, - "test.txt"); + assert_eq!(fiin.entries[0].file_name, "test.txt"); - assert_eq!(fiin.entries[1].file_name, - "test.exl"); + assert_eq!(fiin.entries[1].file_name, "test.exl"); } } - diff --git a/src/model.rs b/src/model.rs index 3f89aa7..c7e1b90 100755 --- a/src/model.rs +++ b/src/model.rs @@ -1,7 +1,7 @@ use crate::gamedata::MemoryBuffer; -use binrw::BinReaderExt; use binrw::binrw; use binrw::BinRead; +use binrw::BinReaderExt; use half::f16; use std::io::{Cursor, Seek, SeekFrom}; @@ -411,10 +411,12 @@ impl MDL { match element.vertex_usage { VertexUsage::Position => { - vertices[k as usize].position = cursor.read_le::<[f32; 3]>().ok()?; + vertices[k as usize].position = + cursor.read_le::<[f32; 3]>().ok()?; } VertexUsage::BlendWeights => { - vertices[k as usize].bone_weight = cursor.read_le::<[f32; 4]>().ok()?; + vertices[k as usize].bone_weight = + cursor.read_le::<[f32; 4]>().ok()?; } VertexUsage::BlendIndices => { vertices[k as usize].bone_id = cursor.read_le::<[u8; 4]>().ok()?; @@ -422,12 +424,14 @@ impl MDL { VertexUsage::Normal => { // TODO: normals are assumed to be half4 for i in 0..3 { - vertices[k as usize].normal[i] = f16::from_bits(cursor.read_le::().ok()?).to_f32(); + vertices[k as usize].normal[i] = + f16::from_bits(cursor.read_le::().ok()?).to_f32(); } } VertexUsage::UV => { for i in 0..2 { - vertices[k as usize].uv[i] = f16::from_bits(cursor.read_le::().ok()?).to_f32(); + vertices[k as usize].uv[i] = + f16::from_bits(cursor.read_le::().ok()?).to_f32(); } } VertexUsage::Tangent2 => {} diff --git a/src/mtrl.rs b/src/mtrl.rs index f88c919..0015569 100644 --- a/src/mtrl.rs +++ b/src/mtrl.rs @@ -1,5 +1,5 @@ use crate::gamedata::MemoryBuffer; -use binrw::{BinRead, binrw}; +use binrw::{binrw, BinRead}; use std::io::Cursor; #[binrw] diff --git a/src/patch.rs b/src/patch.rs index 2118c57..ca8b58d 100755 --- a/src/patch.rs +++ b/src/patch.rs @@ -163,7 +163,7 @@ enum SqpkFileOperation { #[br(magic = b'D')] DeleteFile, #[br(magic = b'M')] - MakeDirTree + MakeDirTree, } #[derive(BinRead, PartialEq, Debug)] @@ -389,9 +389,14 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { get_platform_string(&target_info.platform), file_id ); - let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder_sub(sub_id), &filename] - .iter() - .collect(); + let path: PathBuf = [ + data_dir, + "sqpack", + &get_expansion_folder_sub(sub_id), + &filename, + ] + .iter() + .collect(); path.to_str().unwrap().to_string() }; @@ -410,9 +415,14 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { filename += &*format!("{}", file_id); } - let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder_sub(sub_id), &filename] - .iter() - .collect(); + let path: PathBuf = [ + data_dir, + "sqpack", + &get_expansion_folder_sub(sub_id), + &filename, + ] + .iter() + .collect(); path.to_str().unwrap().to_string() }; @@ -531,8 +541,10 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { file.seek(SeekFrom::Current(4))?; // now apply the file! - let mut new_file = - OpenOptions::new().write(true).create(true).open(file_path)?; + let mut new_file = OpenOptions::new() + .write(true) + .create(true) + .open(file_path)?; if fop.offset == 0 { new_file.set_len(0)?; @@ -545,9 +557,10 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { fs::remove_file(file_path.as_str())?; } SqpkFileOperation::RemoveAll => { - let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder(fop.expansion_id)] - .iter() - .collect(); + let path: PathBuf = + [data_dir, "sqpack", &get_expansion_folder(fop.expansion_id)] + .iter() + .collect(); if fs::read_dir(&path).is_ok() { fs::remove_dir_all(&path)?; @@ -574,10 +587,10 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> { } ChunkType::AddDirectory(_) => { println!("PATCH: NOP AddDirectory"); - }, + } ChunkType::DeleteDirectory(_) => { println!("PATCH: NOP DeleteDirectory"); - }, + } ChunkType::EndOfFile => { return Ok(()); } diff --git a/src/tex.rs b/src/tex.rs index 4a112d9..47191dc 100644 --- a/src/tex.rs +++ b/src/tex.rs @@ -1,5 +1,5 @@ use crate::gamedata::MemoryBuffer; -use binrw::{binrw}; +use binrw::binrw; use binrw::BinRead; use bitflags::bitflags; use std::cmp::min; diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 412f48f..f6fa205 100755 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -1,13 +1,13 @@ -use std::collections::HashMap; +use hmac_sha512::Hash; +use physis::fiin::FileInfo; use physis::index; +use physis::installer::install_game; +use physis::patch::apply_patch; +use std::collections::HashMap; 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)] @@ -40,10 +40,8 @@ fn test_fiin() { 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"); + 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 { @@ -58,13 +56,15 @@ fn make_temp_install_dir(name: &str) -> String { std::fs::create_dir_all(&game_dir).unwrap(); - 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(); game_dir.as_path().to_str().unwrap().parse().unwrap() } fn fill_dir_hash(game_dir: &str) -> HashMap { - let mut file_hashes : HashMap = HashMap::new(); + let mut file_hashes: HashMap = HashMap::new(); WalkDir::new(game_dir) .into_iter() @@ -81,12 +81,12 @@ fn fill_dir_hash(game_dir: &str) -> HashMap { rel_path = rel_path.strip_prefix(game_dir).unwrap(); 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) { +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); @@ -95,7 +95,7 @@ fn physis_install_patch(game_directory: &str, data_directory: &str, patch_name : apply_patch(&data_dir, &patch_path).unwrap(); } -fn xivlauncher_install_patch(game_directory: &str, data_directory: &str, patch_name : &str) { +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(); @@ -104,10 +104,7 @@ fn xivlauncher_install_patch(game_directory: &str, data_directory: &str, patch_n // TODO: check for windows systems Command::new("/usr/bin/wine") - .args([&patcher_exe, - "install", - &patch_path, - &game_dir]) + .args([&patcher_exe, "install", &patch_path, &game_dir]) .output() .unwrap(); } @@ -120,8 +117,10 @@ fn test_patching() { 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"]; + 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 { @@ -129,8 +128,8 @@ fn test_patching() { physis_install_patch(&physis_dir, "boot", patch); } - let game_patches = - ["game/H2017.06.06.0000.0001a.patch", + let game_patches = [ + "game/H2017.06.06.0000.0001a.patch", "game/H2017.06.06.0000.0001b.patch", "game/H2017.06.06.0000.0001c.patch", "game/H2017.06.06.0000.0001d.patch", @@ -149,7 +148,8 @@ fn test_patching() { "ex1/H2017.06.01.0000.0001a.patch", "ex1/H2017.06.01.0000.0001b.patch", "ex1/H2017.06.01.0000.0001c.patch", - "ex1/H2017.06.01.0000.0001d.patch"]; + "ex1/H2017.06.01.0000.0001d.patch", + ]; println!("Boot patching is now complete. Now running game patching..."); @@ -172,4 +172,4 @@ fn test_patching() { } assert_eq!(physis_files, xivlauncher_files); -} \ No newline at end of file +}