1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-20 19:57:45 +00:00

Minor formatting and linter fixes

This commit is contained in:
Joshua Goins 2022-12-17 08:23:19 -05:00
parent 6a94215af9
commit dfda25111a
5 changed files with 19 additions and 25 deletions

View file

@ -1,8 +1,8 @@
pub struct JAMCRC { pub struct Jamcrc {
table: [u32; 256], table: [u32; 256],
} }
impl JAMCRC { impl Jamcrc {
pub(crate) const fn new() -> Self { pub(crate) const fn new() -> Self {
let mut table: [u32; 256] = [0u32; 256]; let mut table: [u32; 256] = [0u32; 256];
@ -40,21 +40,17 @@ impl JAMCRC {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::fiin::FileInfo;
use std::fs::read;
use std::path::PathBuf;
#[test] #[test]
fn basic_parsing() { fn check_library() {
use crc::{Crc, CRC_32_JAMCRC}; use crc::{Crc, CRC_32_JAMCRC};
use std::io::{Read, Seek, SeekFrom};
const JAMCR: Crc<u32> = Crc::<u32>::new(&CRC_32_JAMCRC); const JAMCR: Crc<u32> = Crc::<u32>::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))
} }
} }

View file

@ -1,7 +1,7 @@
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
use crate::sha1::Sha1; use crate::sha1::Sha1;
use binrw::BinRead;
use binrw::binrw; use binrw::binrw;
use binrw::BinRead;
use std::fs::read; use std::fs::read;
use std::io::Cursor; use std::io::Cursor;
@ -71,7 +71,6 @@ impl FileInfo {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*;
use crate::fiin::FileInfo; use crate::fiin::FileInfo;
use std::fs::read; use std::fs::read;
use std::path::PathBuf; use std::path::PathBuf;

View file

@ -175,7 +175,7 @@ impl GameData {
let slice = index_file.entries.iter().find(|s| s.hash == hash); let slice = index_file.entries.iter().find(|s| s.hash == hash);
match slice { match slice {
Some(entry) => { Some(entry) => {
let mut dat_file = self.get_dat_file(path, entry.bitfield.data_file_id().into())?; let mut dat_file = self.get_dat_file(path, entry.bitfield.data_file_id())?;
dat_file.read_from_offset(entry.bitfield.offset()) dat_file.read_from_offset(entry.bitfield.offset())
} }
@ -301,11 +301,11 @@ impl GameData {
.iter() .iter()
.collect(); .collect();
std::fs::remove_dir_all(&repo_path) fs::remove_dir_all(&repo_path)
.ok() .ok()
.ok_or(RepairError::FailedRepair(repository))?; .ok_or(RepairError::FailedRepair(repository))?;
std::fs::create_dir_all(&repo_path) fs::create_dir_all(&repo_path)
.ok() .ok()
.ok_or(RepairError::FailedRepair(repository))?; .ok_or(RepairError::FailedRepair(repository))?;
@ -325,7 +325,7 @@ impl GameData {
} }
}; };
std::fs::write(&ver_path, new_version) fs::write(&ver_path, new_version)
.ok() .ok()
.ok_or(RepairError::FailedRepair(repository))?; .ok_or(RepairError::FailedRepair(repository))?;
} }

View file

@ -24,12 +24,12 @@ pub trait SimdExt {
fn simd_eq(self, rhs: Self) -> Self; fn simd_eq(self, rhs: Self) -> Self;
} }
impl SimdExt for fake::u32x4 { impl SimdExt for u32x4 {
fn simd_eq(self, rhs: Self) -> Self { fn simd_eq(self, rhs: Self) -> Self {
if self == rhs { if self == rhs {
fake::u32x4(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff) u32x4(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff)
} else { } else {
fake::u32x4(0, 0, 0, 0) u32x4(0, 0, 0, 0)
} }
} }
} }
@ -204,7 +204,7 @@ const DEFAULT_STATE: Sha1State = Sha1State {
#[inline(always)] #[inline(always)]
fn as_block(input: &[u8]) -> &[u8; 64] { fn as_block(input: &[u8]) -> &[u8; 64] {
unsafe { unsafe {
assert!(input.len() == 64); assert_eq!(input.len(), 64);
let arr: &[u8; 64] = &*(input.as_ptr() as *const [u8; 64]); let arr: &[u8; 64] = &*(input.as_ptr() as *const [u8; 64]);
arr arr
} }
@ -663,9 +663,8 @@ impl str::FromStr for Digest {
} }
let mut rv: Digest = Default::default(); let mut rv: Digest = Default::default();
for idx in 0..5 { for idx in 0..5 {
rv.data.state[idx] = rv.data.state[idx] = u32::from_str_radix(&s[idx * 8..idx * 8 + 8], 16)
r#try!(u32::from_str_radix(&s[idx * 8..idx * 8 + 8], 16) .map_err(|_| DigestParseError(()))?;
.map_err(|_| DigestParseError(())));
} }
Ok(rv) Ok(rv)
} }
@ -674,7 +673,7 @@ impl str::FromStr for Digest {
impl fmt::Display for Digest { impl fmt::Display for Digest {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for i in self.data.state.iter() { for i in self.data.state.iter() {
r#try!(write!(f, "{:08x}", i)); write!(f, "{:08x}", i)?;
} }
Ok(()) Ok(())
} }

View file

@ -1,10 +1,10 @@
use crate::compression::no_header_decompress; use crate::compression::no_header_decompress;
use crate::crc::JAMCRC; use crate::crc::Jamcrc;
use crate::dat::{BlockHeader, CompressionMode}; use crate::dat::{BlockHeader, CompressionMode};
use binrw::BinRead; use binrw::BinRead;
use std::io::{Read, Seek, SeekFrom}; use std::io::{Read, Seek, SeekFrom};
const CRC: JAMCRC = JAMCRC::new(); const CRC: Jamcrc = Jamcrc::new();
/// Calculates a hash for `index` files from a game path. /// Calculates a hash for `index` files from a game path.
pub fn calculate_hash(path: &str) -> u64 { pub fn calculate_hash(path: &str) -> u64 {