mirror of
https://github.com/redstrate/Physis.git
synced 2025-04-23 05:07:46 +00:00
Run rustfmt
This commit is contained in:
parent
827e971035
commit
6e6aa896a6
8 changed files with 42 additions and 40 deletions
|
@ -1,6 +1,6 @@
|
|||
use binrw::binrw;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use binrw::binrw;
|
||||
|
||||
#[binrw]
|
||||
#[brw(repr(u8))]
|
||||
|
|
15
src/crc.rs
15
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<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))
|
||||
}
|
||||
}
|
|
@ -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")]
|
||||
|
|
|
@ -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<u8>;
|
||||
|
@ -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<Vec<(&Repository, RepairAction)>> {
|
||||
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))?;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -338,8 +338,8 @@ impl Digest {
|
|||
|
||||
impl Blocks {
|
||||
fn input<F>(&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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue