From 57d13f0b21136956ec1838309014d5b15c962e71 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 15 Apr 2024 19:43:16 -0400 Subject: [PATCH] Remove hardcoded "win32" string in repository filename functions Second part to that recent refactor, so eventually it might be possible to read DATs from other platforms. --- src/common.rs | 8 ++++++++ src/patch.rs | 10 +--------- src/repository.rs | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/common.rs b/src/common.rs index 5a89059..b0a7b6f 100755 --- a/src/common.rs +++ b/src/common.rs @@ -66,3 +66,11 @@ pub enum Platform { PS3, PS4, } + +pub fn get_platform_string(id: &Platform) -> &'static str { + match &id { + Platform::Win32 => "win32", + Platform::PS3 => "ps3.d", + Platform::PS4 => "ps4.d", + } +} \ No newline at end of file diff --git a/src/patch.rs b/src/patch.rs index a0323f7..7dd44d1 100755 --- a/src/patch.rs +++ b/src/patch.rs @@ -12,7 +12,7 @@ use binrw::BinRead; use binrw::binrw; use tracing::{debug, warn}; -use crate::common::{Platform, Region}; +use crate::common::{get_platform_string, Platform, Region}; use crate::sqpack::read_data_block_patch; #[binread] @@ -263,14 +263,6 @@ struct SqpkFileOperationData { path: String, } -fn get_platform_string(id: &Platform) -> &'static str { - match &id { - Platform::Win32 => "win32", - Platform::PS3 => "ps3.d", - Platform::PS4 => "ps4.d", - } -} - #[derive(BinRead, PartialEq, Debug)] #[br(big)] struct SqpkTargetInfo { diff --git a/src/repository.rs b/src/repository.rs index 64ea430..f8edcc3 100755 --- a/src/repository.rs +++ b/src/repository.rs @@ -6,7 +6,7 @@ use std::cmp::Ordering::{Greater, Less}; use std::path::{Path, PathBuf}; use binrw::binrw; -use crate::common::{Platform, read_version}; +use crate::common::{get_platform_string, Platform, read_version}; use crate::repository::RepositoryType::{Base, Expansion}; /// The type of repository, discerning game data from expansion data. @@ -177,7 +177,7 @@ impl Repository { category as i32, self.expansion(), 0, - "win32" + get_platform_string(&self.platform) ) } @@ -193,7 +193,7 @@ impl Repository { pub fn dat_filename(&self, category: Category, data_file_id: u32) -> String { let expansion = self.expansion(); let chunk = 0; - let platform = "win32"; + let platform = get_platform_string(&self.platform); format!( "{:02x}{expansion:02}{chunk:02}.{platform}.dat{data_file_id}",