diff --git a/rust/src/appdata.rs b/rust/src/appdata.rs index d7d686f..21c6abd 100644 --- a/rust/src/appdata.rs +++ b/rust/src/appdata.rs @@ -1,7 +1,8 @@ use std::hash::{DefaultHasher, Hash, Hasher}; +use std::path::Path; use std::time::SystemTime; use crate::model::config::GlobalConfig; -use crate::model::patch::PatchFileVec; +use crate::model::patch::{PatchFileVec, PatchList}; use crate::pkg::{Feature, Status}; use crate::profiles::types::Profile; use crate::{model::misc::Game, pkg::PkgKey}; @@ -165,4 +166,22 @@ impl AppData { panic!("unable to initialize the logger? {:?}", e); } } + + pub fn patches_enabled(&self, game_target: impl AsRef, amd_target: impl AsRef) -> Result> { + let ch1 = sha256::try_digest(game_target.as_ref())?; + let ch2 = sha256::try_digest(amd_target.as_ref())?; + + let mut res = Vec::new(); + for pfile in &self.patch_vec.0 { + for plist in &pfile.0 { + let this_hash = plist.sha256.to_ascii_lowercase(); + log::debug!("checking {}", this_hash); + if this_hash == ch1 || this_hash == ch2 { + log::debug!("enabling {this_hash}"); + res.push(plist); + } + } + } + Ok(res) + } } diff --git a/rust/src/cmd.rs b/rust/src/cmd.rs index 3f835f3..6e1cb36 100644 --- a/rust/src/cmd.rs +++ b/rust/src/cmd.rs @@ -69,9 +69,15 @@ pub async fn startline(app: AppHandle, refresh: bool) -> Result<(), String> { } if let Some(p) = &appd.profile { log::debug!("{}", hash); + + let patches_enabled = appd.patches_enabled( + &p.data.sgt.target, + &p.data.sgt.target.parent().unwrap().join("amdaemon.exe") + ).map_err(|e| e.to_string())?; + let info = p.prepare_display() .map_err(|e| e.to_string())?; - let lineup_res = p.line_up(hash, refresh, &appd.patch_vec).await + let lineup_res = p.line_up(hash, refresh, patches_enabled).await .map_err(|e| e.to_string()); #[cfg(target_os = "windows")] diff --git a/rust/src/modules/mempatcher.rs b/rust/src/modules/mempatcher.rs index 51080d9..0183362 100644 --- a/rust/src/modules/mempatcher.rs +++ b/rust/src/modules/mempatcher.rs @@ -1,25 +1,23 @@ use std::path::Path; use anyhow::Result; -use crate::model::patch::{Patch, PatchData, PatchFileVec, PatchSelection, PatchSelectionData}; +use crate::model::patch::{Patch, PatchData, PatchList, PatchSelection, PatchSelectionData}; impl PatchSelection { pub async fn render_to_file( &self, filename: &str, - patches: &PatchFileVec, + patch_lists: &Vec<&PatchList>, path: impl AsRef ) -> Result<()> { let mut res = "".to_owned(); - for file in &patches.0 { - for list in &file.0 { - if list.filename != filename { - continue; - } - for patch in &list.patches { - if let Some(selection) = self.0.get(&patch.id) { - res += &Self::render(filename, patch, selection); - } + for list in patch_lists { + if list.filename != filename { + continue; + } + for patch in &list.patches { + if let Some(selection) = self.0.get(&patch.id) { + res += &Self::render(filename, patch, selection); } } } diff --git a/rust/src/patcher.rs b/rust/src/patcher.rs index 7ade0b5..03aafab 100644 --- a/rust/src/patcher.rs +++ b/rust/src/patcher.rs @@ -30,20 +30,21 @@ impl PatchFileVec { pub fn find_patches(&self, target: impl AsRef) -> Result> { let checksum = try_digest(target.as_ref())?; - let mut res = Vec::new(); + let mut res_patches = Vec::new(); for pfile in &self.0 { for plist in &pfile.0 { - log::debug!("checking {}", plist.sha256.to_ascii_lowercase()); - if plist.sha256.to_ascii_lowercase() == checksum { + let this_hash = plist.sha256.to_ascii_lowercase(); + log::debug!("checking {}", this_hash); + if this_hash == checksum { let mut cloned = plist.clone().patches; - res.append(&mut cloned); + res_patches.append(&mut cloned); } } } - if res.len() == 0 { + if res_patches.len() == 0 { log::warn!("no matching patchset for {:?} ({})", target.as_ref(), checksum); } - Ok(res) + Ok(res_patches) } } \ No newline at end of file diff --git a/rust/src/profiles/mod.rs b/rust/src/profiles/mod.rs index dde67f4..bc1a306 100644 --- a/rust/src/profiles/mod.rs +++ b/rust/src/profiles/mod.rs @@ -1,6 +1,6 @@ pub use types::{Profile, ProfileData, ProfileMeta, ProfilePaths, StartPayload}; use std::{collections::{BTreeMap, BTreeSet}, path::{Path, PathBuf}}; -use crate::{model::{misc::Game, patch::{PatchFileVec, PatchSelection}, profile::{Aime, ChunithmKeyboard, IOSelection, Keyboard, Mu3Ini, OngekiKeyboard, ProfileModule}}, modules::{display_windows::DisplayInfo, package::prepare_packages}, pkg::PkgKey, pkg_store::PackageStore, util}; +use crate::{model::{misc::Game, patch::{PatchList, PatchSelection}, profile::{Aime, ChunithmKeyboard, IOSelection, Keyboard, Mu3Ini, OngekiKeyboard, ProfileModule}}, modules::{display_windows::DisplayInfo, package::prepare_packages}, pkg::PkgKey, pkg_store::PackageStore, util}; use tauri::Emitter; use std::process::Stdio; use crate::model::profile::BepInEx; @@ -186,7 +186,7 @@ impl Profile { Ok(info) } - pub async fn line_up(&self, pkg_hash: String, refresh: bool, patch_files: &PatchFileVec) -> Result<()> { + pub async fn line_up(&self, pkg_hash: String, refresh: bool, patchlists_enabled: Vec<&PatchList>) -> Result<()> { if !self.data_dir().exists() { tokio::fs::create_dir(self.data_dir()).await?; } @@ -226,8 +226,8 @@ impl Profile { if let Some(patches) = &self.data.patches { futures::try_join!( - patches.render_to_file("amdaemon.exe", patch_files, self.data_dir().join("patch-amd.mph")), - patches.render_to_file("chusanApp.exe", patch_files, self.data_dir().join("patch-game.mph")) + patches.render_to_file("amdaemon.exe", &patchlists_enabled, self.data_dir().join("patch-amd.mph")), + patches.render_to_file("chusanApp.exe", &patchlists_enabled, self.data_dir().join("patch-game.mph")) )?; }