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::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use binrw::binrw;
|
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(repr(u8))]
|
#[brw(repr(u8))]
|
||||||
|
|
15
src/crc.rs
15
src/crc.rs
|
@ -1,5 +1,5 @@
|
||||||
pub struct JAMCRC {
|
pub struct JAMCRC {
|
||||||
table: [u32; 256]
|
table: [u32; 256],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JAMCRC {
|
impl JAMCRC {
|
||||||
|
@ -24,13 +24,11 @@ impl JAMCRC {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Self {
|
Self { table }
|
||||||
table
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn checksum(&self, bytes: &[u8]) -> u32 {
|
pub(crate) fn checksum(&self, bytes: &[u8]) -> u32 {
|
||||||
let mut c : u32 = 0xFFFFFFFF;
|
let mut c: u32 = 0xFFFFFFFF;
|
||||||
for byte in bytes {
|
for byte in bytes {
|
||||||
c = self.table[((c ^ *byte as u32) & 0xFF) as usize] ^ (c >> 8);
|
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);
|
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),
|
assert_eq!(JAMCR.checksum(&bytes), crc.checksum(&bytes))
|
||||||
crc.checksum(&bytes))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::gamedata::MemoryBuffer;
|
use crate::gamedata::MemoryBuffer;
|
||||||
|
use crate::sha1::Sha1;
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
use binrw::{binrw, BinrwNamedArgs, NullString};
|
use binrw::{binrw, BinrwNamedArgs, NullString};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::fs::read;
|
use std::fs::read;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use crate::sha1::Sha1;
|
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(magic = b"FileInfo")]
|
#[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::dat::DatFile;
|
||||||
use crate::exd::EXD;
|
use crate::exd::EXD;
|
||||||
use crate::exh::EXH;
|
use crate::exh::EXH;
|
||||||
|
@ -34,11 +34,11 @@ fn is_valid(path: &str) -> bool {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum RepairAction {
|
pub enum RepairAction {
|
||||||
VersionFileMissing,
|
VersionFileMissing,
|
||||||
VersionFileCanRestore
|
VersionFileCanRestore,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum RepairError<'a> {
|
pub enum RepairError<'a> {
|
||||||
FailedRepair(&'a Repository)
|
FailedRepair(&'a Repository),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type MemoryBuffer = Vec<u8>;
|
pub type MemoryBuffer = Vec<u8>;
|
||||||
|
@ -244,7 +244,7 @@ impl GameData {
|
||||||
/// version files.
|
/// version files.
|
||||||
/// If the repair is needed, a list of invalid repositories is given.
|
/// If the repair is needed, a list of invalid repositories is given.
|
||||||
pub fn needs_repair(&self) -> Option<Vec<(&Repository, RepairAction)>> {
|
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 {
|
for repository in &self.repositories {
|
||||||
if repository.version.is_none() {
|
if repository.version.is_none() {
|
||||||
// Check to see if a .bck file is created, as we might be able to use that
|
// 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(),
|
repository.name.clone(),
|
||||||
format!("{}.bck", repository.name),
|
format!("{}.bck", repository.name),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let repair_action = if read_version(&ver_bak_path).is_some() {
|
let repair_action = if read_version(&ver_bak_path).is_some() {
|
||||||
RepairAction::VersionFileCanRestore
|
RepairAction::VersionFileCanRestore
|
||||||
|
@ -277,7 +277,10 @@ impl GameData {
|
||||||
/// Performs the repair, assuming any damaging effects it may have
|
/// Performs the repair, assuming any damaging effects it may have
|
||||||
/// Returns true only if all actions were taken are successful.
|
/// Returns true only if all actions were taken are successful.
|
||||||
/// NOTE: This is a destructive operation, especially for InvalidVersion errors.
|
/// 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 {
|
for (repository, action) in repositories {
|
||||||
let ver_path: PathBuf = [
|
let ver_path: PathBuf = [
|
||||||
self.game_directory.clone(),
|
self.game_directory.clone(),
|
||||||
|
@ -285,26 +288,28 @@ impl GameData {
|
||||||
repository.name.clone(),
|
repository.name.clone(),
|
||||||
format!("{}.ver", repository.name),
|
format!("{}.ver", repository.name),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let new_version : String = match action {
|
let new_version: String = match action {
|
||||||
RepairAction::VersionFileMissing => {
|
RepairAction::VersionFileMissing => {
|
||||||
let repo_path: PathBuf = [
|
let repo_path: PathBuf = [
|
||||||
self.game_directory.clone(),
|
self.game_directory.clone(),
|
||||||
"sqpack".to_string(),
|
"sqpack".to_string(),
|
||||||
repository.name.clone()
|
repository.name.clone(),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
std::fs::remove_dir_all(&repo_path).ok()
|
std::fs::remove_dir_all(&repo_path)
|
||||||
|
.ok()
|
||||||
.ok_or(RepairError::FailedRepair(repository))?;
|
.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))?;
|
.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 => {
|
RepairAction::VersionFileCanRestore => {
|
||||||
let ver_bak_path: PathBuf = [
|
let ver_bak_path: PathBuf = [
|
||||||
|
@ -313,15 +318,15 @@ impl GameData {
|
||||||
repository.name.clone(),
|
repository.name.clone(),
|
||||||
format!("{}.bck", repository.name),
|
format!("{}.bck", repository.name),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
read_version(&ver_bak_path)
|
read_version(&ver_bak_path).ok_or(RepairError::FailedRepair(repository))?
|
||||||
.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))?;
|
.ok_or(RepairError::FailedRepair(repository))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
use crate::common::read_version;
|
||||||
use crate::repository::RepositoryType::{Base, Expansion};
|
use crate::repository::RepositoryType::{Base, Expansion};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::cmp::Ordering::{Greater, Less};
|
use std::cmp::Ordering::{Greater, Less};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use crate::common::read_version;
|
|
||||||
|
|
||||||
/// The type of repository, discerning game data from expansion data.
|
/// The type of repository, discerning game data from expansion data.
|
||||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
|
|
|
@ -338,8 +338,8 @@ impl Digest {
|
||||||
|
|
||||||
impl Blocks {
|
impl Blocks {
|
||||||
fn input<F>(&mut self, mut input: &[u8], mut f: F)
|
fn input<F>(&mut self, mut input: &[u8], mut f: F)
|
||||||
where
|
where
|
||||||
F: FnMut(&[u8; 64]),
|
F: FnMut(&[u8; 64]),
|
||||||
{
|
{
|
||||||
if self.len > 0 {
|
if self.len > 0 {
|
||||||
let len = self.len as usize;
|
let len = self.len as usize;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::compression::no_header_decompress;
|
use crate::compression::no_header_decompress;
|
||||||
|
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};
|
||||||
use crate::crc::JAMCRC;
|
|
||||||
|
|
||||||
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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue