From a2f4ee924be7c4ff5908f278d6aed2e1486e9edf Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Wed, 14 Jun 2023 13:24:07 +0200 Subject: [PATCH] feat(pgr): compatibility fixes Moved mfc140 to the core library, updated wincompatlib to resolve fonts installation issue --- Cargo.toml | 5 ++-- src/components/mfc140.rs | 63 ---------------------------------------- src/components/mod.rs | 1 - src/games/pgr/states.rs | 32 +++++++++++++++----- 4 files changed, 27 insertions(+), 74 deletions(-) delete mode 100644 src/components/mfc140.rs diff --git a/Cargo.toml b/Cargo.toml index 535ce93..f416825 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" [dependencies.anime-game-core] git = "https://github.com/an-anime-team/anime-game-core" -tag = "1.12.3" +tag = "1.12.4" features = ["all"] # path = "../anime-game-core" # ! for dev purposes only @@ -24,7 +24,7 @@ serde_json = { version = "1.0", optional = true } cached = { version = "0.44", features = ["proc_macro"] } enum-ordinalize = { version = "3.1", optional = true } -wincompatlib = { version = "0.7.2", features = ["all"], optional = true } +wincompatlib = { version = "0.7.3", features = ["all"], optional = true } lazy_static = { version = "1.4", optional = true } md-5 = { version = "0.10", features = ["asm"], optional = true } discord-rich-presence = { version = "0.2.3", optional = true } @@ -41,6 +41,7 @@ honkai-patch = [ "anime-game-core/patch-jadeite", "anime-game-core/patch-mfplat" ] +pgr-patch = ["anime-game-core/patch-mfc140"] # Common features states = [] diff --git a/src/components/mfc140.rs b/src/components/mfc140.rs deleted file mode 100644 index 554316f..0000000 --- a/src/components/mfc140.rs +++ /dev/null @@ -1,63 +0,0 @@ -use std::path::Path; -use std::process::Command; - -use anime_game_core::installer::downloader::Downloader; - -// Source: https://github.com/Winetricks/winetricks/blob/e9454179686b3659ad3f47a5d49e6e4e82862cd5/src/winetricks#L13206 - -const URL: &str = "https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe"; - -const LIBRARIES: &[&str] = &[ - "mfc140.dll", - "mfc140u.dll", - "mfcm140.dll", - "mfcm140u.dll" -]; - -pub fn is_installed(wine_prefix: impl AsRef) -> bool { - wine_prefix.as_ref().join("drive_c/windows/system32/mfc140.dll").exists() -} - -pub fn install(wine_prefix: impl AsRef) -> anyhow::Result<()> { - let vcredist = std::env::temp_dir().join("vcredist/vc_redist.x86.exe"); - let vcredist_extracted = std::env::temp_dir().join("vcredist/extracted"); - - Downloader::new(URL)? - .with_continue_downloading(false) - .download(&vcredist, |_, _| {})?; - - // w_try_cabextract --directory="${W_TMP}/win64" "${W_CACHE}"/vcrun2015/vc_redist.x64.exe -F 'a11' - let output = Command::new("cabextract") - .arg("-d") - .arg(&vcredist_extracted) - .arg(vcredist) - .arg("-F") - .arg("a11") - .spawn()? - .wait_with_output()?; - - if !output.status.success() { - anyhow::bail!("Failed to extract vcrun2015 (1): {}", String::from_utf8_lossy(&output.stderr)); - } - - // w_try_cabextract --directory="${W_TMP}/win64" "${W_TMP}/win64/a11" - let output = Command::new("cabextract") - .arg("-d") - .arg(&vcredist_extracted) - .arg(vcredist_extracted.join("a11")) - .spawn()? - .wait_with_output()?; - - if !output.status.success() { - anyhow::bail!("Failed to extract vcrun2015 (2): {}", String::from_utf8_lossy(&output.stderr)); - } - - // w_try_cp_dll "${W_TMP}/win64"/mfc140.dll "${W_SYSTEM64_DLLS}"/mfc140.dll - for lib in LIBRARIES { - let dest = wine_prefix.as_ref().join("drive_c/windows/system32").join(lib); - - std::fs::copy(vcredist_extracted.join(lib), dest)?; - } - - Ok(()) -} diff --git a/src/components/mod.rs b/src/components/mod.rs index b5ecb34..312593a 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,4 +1,3 @@ pub mod loader; pub mod wine; pub mod dxvk; -pub mod mfc140; diff --git a/src/games/pgr/states.rs b/src/games/pgr/states.rs index f7299f7..ab39ed9 100644 --- a/src/games/pgr/states.rs +++ b/src/games/pgr/states.rs @@ -1,12 +1,11 @@ use std::path::PathBuf; -use wincompatlib::wine::ext::Corefont; +use wincompatlib::wine::ext::Font; use anime_game_core::prelude::*; use anime_game_core::pgr::prelude::*; use crate::config::ConfigExt; -use crate::components::mfc140; #[derive(Debug, Clone)] pub enum LauncherState { @@ -18,7 +17,7 @@ pub enum LauncherState { PrefixNotExists, Mfc140NotInstalled, - CorefontsNotInstalled(Vec), + FontsNotInstalled(Vec), // Always contains `VersionDiff::Diff` GameUpdateAvailable(VersionDiff), @@ -57,16 +56,33 @@ impl LauncherState { return Ok(Self::Mfc140NotInstalled); } - let mut corefonts = Vec::new(); + let mut fonts = Vec::new(); - for font in Corefont::iterator() { + // In future, wincompatlib's Font might contain fonts that won't be actually needed + // That's why I listed only needed fonts here + const COREFONTS: &[Font] = &[ + Font::Andale, + Font::Arial, + Font::Courier, + Font::Georgia, + Font::Impact, + Font::Times, + Font::Trebuchet, + Font::Verdana, + Font::Webdings, + + // Who even needs it? + Font::ComicSans + ]; + + for font in COREFONTS.iter().copied() { if !font.is_installed(¶ms.wine_prefix) { - corefonts.push(font); + fonts.push(font); } } - if !corefonts.is_empty() { - return Ok(Self::CorefontsNotInstalled(corefonts)); + if !fonts.is_empty() { + return Ok(Self::FontsNotInstalled(fonts)); } // Check game installation status