From 6e6aa896a66f5e9dff554b8b843a6db07a017239 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 25 Oct 2022 13:02:06 -0400 Subject: [PATCH] Run rustfmt --- build.rs | 2 +- src/common.rs | 2 +- src/crc.rs | 17 +++++++---------- src/fiin.rs | 2 +- src/gamedata.rs | 47 ++++++++++++++++++++++++++--------------------- src/repository.rs | 2 +- src/sha1.rs | 6 +++--- src/sqpack.rs | 4 ++-- 8 files changed, 42 insertions(+), 40 deletions(-) diff --git a/build.rs b/build.rs index 9953eea..eec6d52 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,3 @@ fn main() { system_deps::Config::new().probe().unwrap(); -} \ No newline at end of file +} diff --git a/src/common.rs b/src/common.rs index 70dc7a4..ac0b98d 100755 --- a/src/common.rs +++ b/src/common.rs @@ -1,6 +1,6 @@ +use binrw::binrw; use std::fs; use std::path::Path; -use binrw::binrw; #[binrw] #[brw(repr(u8))] diff --git a/src/crc.rs b/src/crc.rs index d987f1b..731b987 100644 --- a/src/crc.rs +++ b/src/crc.rs @@ -1,5 +1,5 @@ pub struct JAMCRC { - table: [u32; 256] + table: [u32; 256], } impl JAMCRC { @@ -24,13 +24,11 @@ impl JAMCRC { i += 1; } - Self { - table - } + Self { table } } pub(crate) fn checksum(&self, bytes: &[u8]) -> u32 { - let mut c : u32 = 0xFFFFFFFF; + let mut c: u32 = 0xFFFFFFFF; for byte in bytes { c = self.table[((c ^ *byte as u32) & 0xFF) as usize] ^ (c >> 8); } @@ -53,11 +51,10 @@ mod tests { const JAMCR: Crc = Crc::::new(&CRC_32_JAMCRC); - let bytes : [u8; 9] = [1, 1, 2, 4, 5, 6, 12, 12, 12]; + let bytes: [u8; 9] = [1, 1, 2, 4, 5, 6, 12, 12, 12]; - const crc : JAMCRC = JAMCRC::new(); + const crc: JAMCRC = JAMCRC::new(); - assert_eq!(JAMCR.checksum(&bytes), - crc.checksum(&bytes)) + assert_eq!(JAMCR.checksum(&bytes), crc.checksum(&bytes)) } -} \ No newline at end of file +} diff --git a/src/fiin.rs b/src/fiin.rs index ef943c4..fe04376 100644 --- a/src/fiin.rs +++ b/src/fiin.rs @@ -1,10 +1,10 @@ use crate::gamedata::MemoryBuffer; +use crate::sha1::Sha1; use binrw::BinRead; use binrw::{binrw, BinrwNamedArgs, NullString}; use std::ffi::CStr; use std::fs::read; use std::io::Cursor; -use crate::sha1::Sha1; #[binrw] #[brw(magic = b"FileInfo")] diff --git a/src/gamedata.rs b/src/gamedata.rs index 0f49283..98fd361 100755 --- a/src/gamedata.rs +++ b/src/gamedata.rs @@ -1,4 +1,4 @@ -use crate::common::{Language, read_version}; +use crate::common::{read_version, Language}; use crate::dat::DatFile; use crate::exd::EXD; use crate::exh::EXH; @@ -34,11 +34,11 @@ fn is_valid(path: &str) -> bool { #[derive(Debug)] pub enum RepairAction { VersionFileMissing, - VersionFileCanRestore + VersionFileCanRestore, } pub enum RepairError<'a> { - FailedRepair(&'a Repository) + FailedRepair(&'a Repository), } pub type MemoryBuffer = Vec; @@ -244,7 +244,7 @@ impl GameData { /// version files. /// If the repair is needed, a list of invalid repositories is given. pub fn needs_repair(&self) -> Option> { - let mut repositories : Vec<(&Repository, RepairAction)> = Vec::new(); + let mut repositories: Vec<(&Repository, RepairAction)> = Vec::new(); for repository in &self.repositories { if repository.version.is_none() { // Check to see if a .bck file is created, as we might be able to use that @@ -254,8 +254,8 @@ impl GameData { repository.name.clone(), format!("{}.bck", repository.name), ] - .iter() - .collect(); + .iter() + .collect(); let repair_action = if read_version(&ver_bak_path).is_some() { RepairAction::VersionFileCanRestore @@ -277,7 +277,10 @@ impl GameData { /// Performs the repair, assuming any damaging effects it may have /// Returns true only if all actions were taken are successful. /// NOTE: This is a destructive operation, especially for InvalidVersion errors. - pub fn perform_repair<'a>(&self, repositories: &Vec<(&'a Repository, RepairAction)>) -> Result<(), RepairError<'a>> { + pub fn perform_repair<'a>( + &self, + repositories: &Vec<(&'a Repository, RepairAction)>, + ) -> Result<(), RepairError<'a>> { for (repository, action) in repositories { let ver_path: PathBuf = [ self.game_directory.clone(), @@ -285,26 +288,28 @@ impl GameData { repository.name.clone(), format!("{}.ver", repository.name), ] - .iter() - .collect(); + .iter() + .collect(); - let new_version : String = match action { + let new_version: String = match action { RepairAction::VersionFileMissing => { let repo_path: PathBuf = [ self.game_directory.clone(), "sqpack".to_string(), - repository.name.clone() + repository.name.clone(), ] - .iter() - .collect(); + .iter() + .collect(); - std::fs::remove_dir_all(&repo_path).ok() + std::fs::remove_dir_all(&repo_path) + .ok() .ok_or(RepairError::FailedRepair(repository))?; - std::fs::create_dir_all(&repo_path).ok() + std::fs::create_dir_all(&repo_path) + .ok() .ok_or(RepairError::FailedRepair(repository))?; - "2012.01.01.0000.0000".to_string() // TODO: is this correct for expansions? + "2012.01.01.0000.0000".to_string() // TODO: is this correct for expansions? } RepairAction::VersionFileCanRestore => { let ver_bak_path: PathBuf = [ @@ -313,15 +318,15 @@ impl GameData { repository.name.clone(), format!("{}.bck", repository.name), ] - .iter() - .collect(); + .iter() + .collect(); - read_version(&ver_bak_path) - .ok_or(RepairError::FailedRepair(repository))? + read_version(&ver_bak_path).ok_or(RepairError::FailedRepair(repository))? } }; - std::fs::write(&ver_path, new_version).ok() + std::fs::write(&ver_path, new_version) + .ok() .ok_or(RepairError::FailedRepair(repository))?; } diff --git a/src/repository.rs b/src/repository.rs index cc6b6eb..226eb6d 100755 --- a/src/repository.rs +++ b/src/repository.rs @@ -1,9 +1,9 @@ +use crate::common::read_version; use crate::repository::RepositoryType::{Base, Expansion}; use std::cmp::Ordering; use std::cmp::Ordering::{Greater, Less}; use std::fs; use std::path::{Path, PathBuf}; -use crate::common::read_version; /// The type of repository, discerning game data from expansion data. #[derive(Debug, PartialEq, Eq, Copy, Clone)] diff --git a/src/sha1.rs b/src/sha1.rs index 1a1f948..bd97928 100644 --- a/src/sha1.rs +++ b/src/sha1.rs @@ -338,8 +338,8 @@ impl Digest { impl Blocks { fn input(&mut self, mut input: &[u8], mut f: F) - where - F: FnMut(&[u8; 64]), + where + F: FnMut(&[u8; 64]), { if self.len > 0 { let len = self.len as usize; @@ -700,4 +700,4 @@ impl fmt::Debug for Digest { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Digest {{ \"{}\" }}", self) } -} \ No newline at end of file +} diff --git a/src/sqpack.rs b/src/sqpack.rs index 5ca16eb..c9a32b4 100755 --- a/src/sqpack.rs +++ b/src/sqpack.rs @@ -1,10 +1,10 @@ use crate::compression::no_header_decompress; +use crate::crc::JAMCRC; use crate::dat::{BlockHeader, CompressionMode}; use binrw::BinRead; use std::io::{Read, Seek, SeekFrom}; -use crate::crc::JAMCRC; -const CRC : JAMCRC = JAMCRC::new(); +const CRC: JAMCRC = JAMCRC::new(); /// Calculates a hash for `index` files from a game path. pub fn calculate_hash(path: &str) -> u64 {