diff --git a/src/games/wuwa/config/mod.rs b/src/games/wuwa/config/mod.rs index 32e9af5..fa195a6 100644 --- a/src/games/wuwa/config/mod.rs +++ b/src/games/wuwa/config/mod.rs @@ -42,7 +42,7 @@ impl ConfigExt for Config { #[inline] fn get() -> anyhow::Result { unsafe { - match &CONFIG { + match CONFIG.as_ref() { Some(config) => Ok(config.clone()), None => Self::get_raw() } diff --git a/src/games/wuwa/config/schema/game/mod.rs b/src/games/wuwa/config/schema/game/mod.rs index 0e853ef..b1749c0 100644 --- a/src/games/wuwa/config/schema/game/mod.rs +++ b/src/games/wuwa/config/schema/game/mod.rs @@ -11,18 +11,20 @@ crate::config_impl_wine_schema!(launcher_dir); crate::config_impl_dxvk_schema!(launcher_dir); pub mod enhancements; +pub mod paths; pub mod prelude { pub use super::Wine; pub use super::Dxvk; pub use super::enhancements::Enhancements; + pub use super::paths::Paths; } use prelude::*; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Game { - pub path: PathBuf, + pub path: Paths, pub wine: Wine, pub dxvk: Dxvk, pub enhancements: Enhancements, @@ -33,10 +35,8 @@ pub struct Game { impl Default for Game { #[inline] fn default() -> Self { - let launcher_dir = launcher_dir().expect("Failed to get launcher dir"); - Self { - path: launcher_dir.join("Wuthering Waves"), + path: Paths::default(), wine: Wine::default(), dxvk: Dxvk::default(), enhancements: Enhancements::default(), @@ -51,13 +51,9 @@ impl From<&JsonValue> for Game { let default = Self::default(); Self { - path: match value.get("path") { - Some(value) => match value.as_str() { - Some(value) => PathBuf::from(value), - None => default.path - }, - None => default.path - }, + path: value.get("path") + .map(Paths::from) + .unwrap_or(default.path), wine: value.get("wine") .map(Wine::from) diff --git a/src/games/wuwa/config/schema/game/paths.rs b/src/games/wuwa/config/schema/game/paths.rs new file mode 100644 index 0000000..19ca01e --- /dev/null +++ b/src/games/wuwa/config/schema/game/paths.rs @@ -0,0 +1,60 @@ +use std::path::{Path, PathBuf}; + +use serde::{Serialize, Deserialize}; +use serde_json::Value as JsonValue; + +use anime_game_core::wuwa::consts::GameEdition; + +use crate::wuwa::consts::launcher_dir; + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct Paths { + pub global: PathBuf, + pub china: PathBuf +} + +impl Paths { + #[inline] + /// Get game path for given edition + pub fn for_edition(&self, edition: impl Into) -> &Path { + match edition.into() { + GameEdition::Global => self.global.as_path(), + GameEdition::China => self.china.as_path() + } + } +} + +impl Default for Paths { + fn default() -> Self { + let launcher_dir = launcher_dir().expect("Failed to get launcher dir"); + + Self { + global: launcher_dir.join("Wuthering Waves"), + china: launcher_dir.join("Wuthering Waves China") + } + } +} + +impl From<&JsonValue> for Paths { + fn from(value: &JsonValue) -> Self { + let default = Self::default(); + + Self { + global: match value.get("global") { + Some(value) => match value.as_str() { + Some(value) => PathBuf::from(value), + None => default.global + }, + None => default.global + }, + + china: match value.get("china") { + Some(value) => match value.as_str() { + Some(value) => PathBuf::from(value), + None => default.china + }, + None => default.china + } + } + } +} diff --git a/src/games/wuwa/config/schema/mod.rs b/src/games/wuwa/config/schema/mod.rs index 1e74b9e..b8bd1c4 100644 --- a/src/games/wuwa/config/schema/mod.rs +++ b/src/games/wuwa/config/schema/mod.rs @@ -19,7 +19,6 @@ use crate::components::{ pub mod launcher; pub mod game; -pub mod patch; #[cfg(feature = "components")] pub mod components; @@ -28,7 +27,6 @@ pub mod prelude { pub use super::launcher::prelude::*; pub use super::game::prelude::*; pub use super::game::*; - pub use super::patch::*; #[cfg(feature = "components")] pub use super::components::*; @@ -45,9 +43,7 @@ pub struct Schema { pub sandbox: Sandbox, #[cfg(feature = "components")] - pub components: Components, - - pub patch: Patch + pub components: Components } impl From<&JsonValue> for Schema { @@ -75,11 +71,6 @@ impl From<&JsonValue> for Schema { components: match value.get("components") { Some(value) => Components::from(value), None => default.components - }, - - patch: match value.get("patch") { - Some(value) => Patch::from(value), - None => default.patch } } } diff --git a/src/games/wuwa/config/schema/patch.rs b/src/games/wuwa/config/schema/patch.rs deleted file mode 100644 index 1b9cf42..0000000 --- a/src/games/wuwa/config/schema/patch.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::path::PathBuf; - -use serde::{Serialize, Deserialize}; -use serde_json::Value as JsonValue; - -use crate::wuwa::consts::launcher_dir; - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct Patch { - pub path: PathBuf -} - -impl Default for Patch { - #[inline] - fn default() -> Self { - let launcher_dir = launcher_dir().expect("Failed to get launcher dir"); - - Self { - path: launcher_dir.join("patch") - } - } -} - -impl From<&JsonValue> for Patch { - fn from(value: &JsonValue) -> Self { - let default = Self::default(); - - Self { - path: match value.get("path").and_then(|path| path.as_str()).map(PathBuf::from) { - Some(path) => path, - None => default.path - } - } - } -} diff --git a/src/games/wuwa/game.rs b/src/games/wuwa/game.rs index 80133e9..de80089 100644 --- a/src/games/wuwa/game.rs +++ b/src/games/wuwa/game.rs @@ -50,7 +50,7 @@ pub fn run() -> anyhow::Result<()> { let config = Config::get()?; - if !config.game.path.exists() { + if !config.game.path.for_edition(config.launcher.edition).exists() { return Err(anyhow::anyhow!("Game is not installed")); } @@ -63,7 +63,7 @@ pub fn run() -> anyhow::Result<()> { let mut folders = Folders { wine: config.game.wine.builds.join(&wine.name), prefix: config.game.wine.prefix.clone(), - game: config.game.path.clone(), + game: config.game.path.for_edition(config.launcher.edition).to_path_buf(), temp: config.launcher.temp.clone().unwrap_or(std::env::temp_dir()) }; @@ -232,7 +232,7 @@ pub fn run() -> anyhow::Result<()> { // We use real current dir here because sandboxed one // obviously doesn't exist - command.current_dir(&config.game.path) + command.current_dir(&config.game.path.for_edition(config.launcher.edition)) .spawn()?.wait_with_output()?; #[cfg(feature = "discord-rpc")] diff --git a/src/games/wuwa/states.rs b/src/games/wuwa/states.rs index a8a5622..c95b747 100644 --- a/src/games/wuwa/states.rs +++ b/src/games/wuwa/states.rs @@ -134,7 +134,7 @@ impl LauncherState { } Self::get(LauncherStateParams { - game_path: config.game.path.clone(), + game_path: config.game.path.for_edition(config.launcher.edition).to_path_buf(), game_edition: config.launcher.edition, wine_prefix: config.get_wine_prefix_path(),