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))]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
pub struct JAMCRC {
|
pub struct JAMCRC {
|
||||||
table: [u32; 256]
|
table: [u32; 256],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl JAMCRC {
|
impl JAMCRC {
|
||||||
|
@ -24,9 +24,7 @@ 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 {
|
||||||
|
@ -57,7 +55,6 @@ mod tests {
|
||||||
|
|
||||||
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>;
|
||||||
|
@ -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(),
|
||||||
|
@ -293,15 +296,17 @@ impl GameData {
|
||||||
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?
|
||||||
|
@ -316,12 +321,12 @@ impl GameData {
|
||||||
.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)]
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
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();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue