feat(wuwa): return back editions support

This commit is contained in:
Nikita Podvirnyi 2024-06-28 17:01:26 +02:00
parent 1e94edd76e
commit 8a00674501
No known key found for this signature in database
GPG key ID: 859D416E5142AFF3
7 changed files with 73 additions and 61 deletions

View file

@ -42,7 +42,7 @@ impl ConfigExt for Config {
#[inline] #[inline]
fn get() -> anyhow::Result<Self::Schema> { fn get() -> anyhow::Result<Self::Schema> {
unsafe { unsafe {
match &CONFIG { match CONFIG.as_ref() {
Some(config) => Ok(config.clone()), Some(config) => Ok(config.clone()),
None => Self::get_raw() None => Self::get_raw()
} }

View file

@ -11,18 +11,20 @@ crate::config_impl_wine_schema!(launcher_dir);
crate::config_impl_dxvk_schema!(launcher_dir); crate::config_impl_dxvk_schema!(launcher_dir);
pub mod enhancements; pub mod enhancements;
pub mod paths;
pub mod prelude { pub mod prelude {
pub use super::Wine; pub use super::Wine;
pub use super::Dxvk; pub use super::Dxvk;
pub use super::enhancements::Enhancements; pub use super::enhancements::Enhancements;
pub use super::paths::Paths;
} }
use prelude::*; use prelude::*;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Game { pub struct Game {
pub path: PathBuf, pub path: Paths,
pub wine: Wine, pub wine: Wine,
pub dxvk: Dxvk, pub dxvk: Dxvk,
pub enhancements: Enhancements, pub enhancements: Enhancements,
@ -33,10 +35,8 @@ pub struct Game {
impl Default for Game { impl Default for Game {
#[inline] #[inline]
fn default() -> Self { fn default() -> Self {
let launcher_dir = launcher_dir().expect("Failed to get launcher dir");
Self { Self {
path: launcher_dir.join("Wuthering Waves"), path: Paths::default(),
wine: Wine::default(), wine: Wine::default(),
dxvk: Dxvk::default(), dxvk: Dxvk::default(),
enhancements: Enhancements::default(), enhancements: Enhancements::default(),
@ -51,13 +51,9 @@ impl From<&JsonValue> for Game {
let default = Self::default(); let default = Self::default();
Self { Self {
path: match value.get("path") { path: value.get("path")
Some(value) => match value.as_str() { .map(Paths::from)
Some(value) => PathBuf::from(value), .unwrap_or(default.path),
None => default.path
},
None => default.path
},
wine: value.get("wine") wine: value.get("wine")
.map(Wine::from) .map(Wine::from)

View file

@ -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<GameEdition>) -> &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
}
}
}
}

View file

@ -19,7 +19,6 @@ use crate::components::{
pub mod launcher; pub mod launcher;
pub mod game; pub mod game;
pub mod patch;
#[cfg(feature = "components")] #[cfg(feature = "components")]
pub mod components; pub mod components;
@ -28,7 +27,6 @@ pub mod prelude {
pub use super::launcher::prelude::*; pub use super::launcher::prelude::*;
pub use super::game::prelude::*; pub use super::game::prelude::*;
pub use super::game::*; pub use super::game::*;
pub use super::patch::*;
#[cfg(feature = "components")] #[cfg(feature = "components")]
pub use super::components::*; pub use super::components::*;
@ -45,9 +43,7 @@ pub struct Schema {
pub sandbox: Sandbox, pub sandbox: Sandbox,
#[cfg(feature = "components")] #[cfg(feature = "components")]
pub components: Components, pub components: Components
pub patch: Patch
} }
impl From<&JsonValue> for Schema { impl From<&JsonValue> for Schema {
@ -75,11 +71,6 @@ impl From<&JsonValue> for Schema {
components: match value.get("components") { components: match value.get("components") {
Some(value) => Components::from(value), Some(value) => Components::from(value),
None => default.components None => default.components
},
patch: match value.get("patch") {
Some(value) => Patch::from(value),
None => default.patch
} }
} }
} }

View file

@ -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
}
}
}
}

View file

@ -50,7 +50,7 @@ pub fn run() -> anyhow::Result<()> {
let config = Config::get()?; 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")); return Err(anyhow::anyhow!("Game is not installed"));
} }
@ -63,7 +63,7 @@ pub fn run() -> anyhow::Result<()> {
let mut folders = Folders { let mut folders = Folders {
wine: config.game.wine.builds.join(&wine.name), wine: config.game.wine.builds.join(&wine.name),
prefix: config.game.wine.prefix.clone(), 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()) 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 // We use real current dir here because sandboxed one
// obviously doesn't exist // 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()?; .spawn()?.wait_with_output()?;
#[cfg(feature = "discord-rpc")] #[cfg(feature = "discord-rpc")]

View file

@ -134,7 +134,7 @@ impl LauncherState {
} }
Self::get(LauncherStateParams { 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, game_edition: config.launcher.edition,
wine_prefix: config.get_wine_prefix_path(), wine_prefix: config.get_wine_prefix_path(),