From 7143357a7bfbc568f535faf6cf4665abb7da2a2e Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Sat, 12 Nov 2022 09:51:35 +0200 Subject: [PATCH] Removed usage of config feature in some other features --- Cargo.toml | 2 +- src/components/dxvk.rs | 19 ++++--------- src/components/wine.rs | 12 +++++--- src/game/mod.rs | 2 ++ src/states/mod.rs | 64 +++++++++++++++++++++++++++--------------- 5 files changed, 58 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ae0a8a..b705019 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ md5 = { version = "0.7.0", optional = true } states = [] config = ["dep:serde", "dep:serde_json"] components = ["dep:wincompatlib", "dep:lazy_static"] -game = ["components"] +game = ["components", "config"] fps-unlocker = ["dep:md5"] default = ["all"] diff --git a/src/components/dxvk.rs b/src/components/dxvk.rs index f8ffd4e..3c07e19 100644 --- a/src/components/dxvk.rs +++ b/src/components/dxvk.rs @@ -4,8 +4,6 @@ use std::path::PathBuf; use serde::{Serialize, Deserialize}; use wincompatlib::prelude::*; -use crate::config; - lazy_static::lazy_static! { static ref GROUPS: Vec = vec![ Group { @@ -45,20 +43,13 @@ impl Version { } /// Apply current dxvk to specified wine prefix - pub fn apply>(&self, dxvks_folder: T, prefix_path: T) -> anyhow::Result { + /// + /// If `wine_info` is `None`, then default system binaries will tried to be used + pub fn apply>(&self, dxvks_folder: T, prefix_path: T, wine: Option) -> anyhow::Result { let apply_path = dxvks_folder.into().join(&self.name).join("setup_dxvk.sh"); - let config = config::get()?; - let (wine_path, wineserver_path, wineboot_path) = match config.try_get_selected_wine_info() { - Some(wine) => { - let wine_folder = config.game.wine.builds.join(wine.name); - - let wine_path = wine_folder.join(wine.files.wine64); - let wineserver_path = wine_folder.join(wine.files.wineserver); - let wineboot_path = wine_folder.join(wine.files.wineboot); - - (wine_path, wineserver_path, wineboot_path) - }, + let (wine_path, wineserver_path, wineboot_path) = match wine { + Some(wine) => (wine.binary(), wine.wineserver(), wine.wineboot()), None => (PathBuf::from("wine64"), PathBuf::from("wineserver"), PathBuf::from("wineboot")) }; diff --git a/src/components/wine.rs b/src/components/wine.rs index 4f5fd8a..75302f2 100644 --- a/src/components/wine.rs +++ b/src/components/wine.rs @@ -51,13 +51,17 @@ impl Version { } /// Convert current wine struct to one from `wincompatlib` - pub fn to_wine(&self) -> Wine { + /// + /// `wine_folder` should point to the folder with wine binaries, so e.g. `/path/to/runners/wine-proton-ge-7.11` + pub fn to_wine>(&self, wine_folder: Option) -> Wine { + let wine_folder = wine_folder.map(|folder| folder.into()).unwrap_or_default(); + Wine::new( - &self.files.wine64, + wine_folder.join(&self.files.wine64), None, Some(WineArch::Win64), - Some(&self.files.wineboot), - Some(&self.files.wineserver), + Some(wine_folder.join(&self.files.wineboot)), + Some(wine_folder.join(&self.files.wineserver)), WineLoader::Current ) } diff --git a/src/game/mod.rs b/src/game/mod.rs index cb2c7a7..e8494a5 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -4,6 +4,8 @@ use anime_game_core::genshin::telemetry; use super::consts; use super::config; + +#[cfg(feature = "fps-unlocker")] use super::fps_unlocker::FpsUnlocker; /// Try to run the game diff --git a/src/states/mod.rs b/src/states/mod.rs index 3780c71..f8f3481 100644 --- a/src/states/mod.rs +++ b/src/states/mod.rs @@ -1,10 +1,11 @@ +use std::path::PathBuf; + use anime_game_core::prelude::*; use anime_game_core::genshin::prelude::*; use serde::{Serialize, Deserialize}; use crate::consts; -use crate::config; #[derive(Debug, Clone, Serialize, Deserialize)] pub enum LauncherState { @@ -56,44 +57,39 @@ pub enum StateUpdating { } impl LauncherState { - pub fn get(status: T) -> anyhow::Result { - let config = config::get()?; - - // Check wine existence - #[cfg(feature = "components")] - { - if config.try_get_wine_executable().is_none() { - return Ok(Self::WineNotInstalled); - } - } + pub fn get(wine_prefix: T, game_path: T, voices: Vec, patch_servers: Vec, status: F) -> anyhow::Result + where + T: Into, + F: Fn(StateUpdating), + S: ToString + { + let wine_prefix = wine_prefix.into(); + let game_path = game_path.into(); // Check prefix existence - if !config.game.wine.prefix.join("drive_c").exists() { + if !wine_prefix.join("drive_c").exists() { return Ok(Self::PrefixNotExists); } // Check game installation status status(StateUpdating::Game); - let game = Game::new(&config.game.path); + let game = Game::new(&game_path); let diff = game.try_get_diff()?; Ok(match diff { VersionDiff::Latest(_) | VersionDiff::Predownload { .. } => { let mut predownload_voice = Vec::new(); - for voice_package in &config.game.voices { - let mut voice_package = VoicePackage::with_locale(match VoiceLocale::from_str(voice_package) { - Some(locale) => locale, - None => return Err(anyhow::anyhow!("Incorrect voice locale \"{}\" specified in the config", voice_package)) - })?; + for locale in voices { + let mut voice_package = VoicePackage::with_locale(locale)?; status(StateUpdating::Voice(voice_package.locale())); // Replace voice package struct with the one constructed in the game's folder // so it'll properly calculate its difference instead of saying "not installed" - if voice_package.is_installed_in(&config.game.path) { - voice_package = match VoicePackage::new(get_voice_package_path(&config.game.path, voice_package.locale())) { + if voice_package.is_installed_in(&game_path) { + voice_package = match VoicePackage::new(get_voice_package_path(&game_path, voice_package.locale())) { Some(locale) => locale, None => return Err(anyhow::anyhow!("Failed to load {} voice package", voice_package.locale().to_name())) }; @@ -113,9 +109,9 @@ impl LauncherState { status(StateUpdating::Patch); - let patch = Patch::try_fetch(config.patch.servers.clone(), consts::PATCH_FETCHING_TIMEOUT)?; + let patch = Patch::try_fetch(patch_servers, consts::PATCH_FETCHING_TIMEOUT)?; - if patch.is_applied(&config.game.path)? { + if patch.is_applied(&game_path)? { if let VersionDiff::Predownload { .. } = diff { Self::PredownloadAvailable { game: diff, @@ -138,4 +134,28 @@ impl LauncherState { VersionDiff::NotInstalled { .. } => Self::GameNotInstalled(diff) }) } + + #[cfg(feature = "config")] + pub fn get_from_config(status: T) -> anyhow::Result { + let config = crate::config::get()?; + + // Check wine existence + #[cfg(feature = "components")] + { + if config.try_get_wine_executable().is_none() { + return Ok(Self::WineNotInstalled); + } + } + + let mut voices = Vec::with_capacity(config.game.voices.len()); + + for voice in config.game.voices { + voices.push(match VoiceLocale::from_str(&voice) { + Some(locale) => locale, + None => return Err(anyhow::anyhow!("Incorrect voice locale \"{}\" specified in the config", voice)) + }); + } + + Self::get(config.game.wine.prefix, config.game.path, voices, config.patch.servers, status) + } }