Removed usage of config feature in some other features
This commit is contained in:
parent
875bce5dbd
commit
7143357a7b
5 changed files with 58 additions and 41 deletions
|
@ -22,7 +22,7 @@ md5 = { version = "0.7.0", optional = true }
|
||||||
states = []
|
states = []
|
||||||
config = ["dep:serde", "dep:serde_json"]
|
config = ["dep:serde", "dep:serde_json"]
|
||||||
components = ["dep:wincompatlib", "dep:lazy_static"]
|
components = ["dep:wincompatlib", "dep:lazy_static"]
|
||||||
game = ["components"]
|
game = ["components", "config"]
|
||||||
fps-unlocker = ["dep:md5"]
|
fps-unlocker = ["dep:md5"]
|
||||||
|
|
||||||
default = ["all"]
|
default = ["all"]
|
||||||
|
|
|
@ -4,8 +4,6 @@ use std::path::PathBuf;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use wincompatlib::prelude::*;
|
use wincompatlib::prelude::*;
|
||||||
|
|
||||||
use crate::config;
|
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref GROUPS: Vec<Group> = vec![
|
static ref GROUPS: Vec<Group> = vec![
|
||||||
Group {
|
Group {
|
||||||
|
@ -45,20 +43,13 @@ impl Version {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply current dxvk to specified wine prefix
|
/// Apply current dxvk to specified wine prefix
|
||||||
pub fn apply<T: Into<PathBuf>>(&self, dxvks_folder: T, prefix_path: T) -> anyhow::Result<Output> {
|
///
|
||||||
|
/// If `wine_info` is `None`, then default system binaries will tried to be used
|
||||||
|
pub fn apply<T: Into<PathBuf>>(&self, dxvks_folder: T, prefix_path: T, wine: Option<Wine>) -> anyhow::Result<Output> {
|
||||||
let apply_path = dxvks_folder.into().join(&self.name).join("setup_dxvk.sh");
|
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() {
|
let (wine_path, wineserver_path, wineboot_path) = match wine {
|
||||||
Some(wine) => {
|
Some(wine) => (wine.binary(), wine.wineserver(), wine.wineboot()),
|
||||||
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)
|
|
||||||
},
|
|
||||||
None => (PathBuf::from("wine64"), PathBuf::from("wineserver"), PathBuf::from("wineboot"))
|
None => (PathBuf::from("wine64"), PathBuf::from("wineserver"), PathBuf::from("wineboot"))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,13 +51,17 @@ impl Version {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert current wine struct to one from `wincompatlib`
|
/// 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<T: Into<PathBuf>>(&self, wine_folder: Option<T>) -> Wine {
|
||||||
|
let wine_folder = wine_folder.map(|folder| folder.into()).unwrap_or_default();
|
||||||
|
|
||||||
Wine::new(
|
Wine::new(
|
||||||
&self.files.wine64,
|
wine_folder.join(&self.files.wine64),
|
||||||
None,
|
None,
|
||||||
Some(WineArch::Win64),
|
Some(WineArch::Win64),
|
||||||
Some(&self.files.wineboot),
|
Some(wine_folder.join(&self.files.wineboot)),
|
||||||
Some(&self.files.wineserver),
|
Some(wine_folder.join(&self.files.wineserver)),
|
||||||
WineLoader::Current
|
WineLoader::Current
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ use anime_game_core::genshin::telemetry;
|
||||||
|
|
||||||
use super::consts;
|
use super::consts;
|
||||||
use super::config;
|
use super::config;
|
||||||
|
|
||||||
|
#[cfg(feature = "fps-unlocker")]
|
||||||
use super::fps_unlocker::FpsUnlocker;
|
use super::fps_unlocker::FpsUnlocker;
|
||||||
|
|
||||||
/// Try to run the game
|
/// Try to run the game
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anime_game_core::prelude::*;
|
use anime_game_core::prelude::*;
|
||||||
use anime_game_core::genshin::prelude::*;
|
use anime_game_core::genshin::prelude::*;
|
||||||
|
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
use crate::consts;
|
use crate::consts;
|
||||||
use crate::config;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum LauncherState {
|
pub enum LauncherState {
|
||||||
|
@ -56,44 +57,39 @@ pub enum StateUpdating {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LauncherState {
|
impl LauncherState {
|
||||||
pub fn get<T: Fn(StateUpdating)>(status: T) -> anyhow::Result<Self> {
|
pub fn get<T, F, S>(wine_prefix: T, game_path: T, voices: Vec<VoiceLocale>, patch_servers: Vec<S>, status: F) -> anyhow::Result<Self>
|
||||||
let config = config::get()?;
|
where
|
||||||
|
T: Into<PathBuf>,
|
||||||
// Check wine existence
|
F: Fn(StateUpdating),
|
||||||
#[cfg(feature = "components")]
|
S: ToString
|
||||||
{
|
{
|
||||||
if config.try_get_wine_executable().is_none() {
|
let wine_prefix = wine_prefix.into();
|
||||||
return Ok(Self::WineNotInstalled);
|
let game_path = game_path.into();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check prefix existence
|
// Check prefix existence
|
||||||
if !config.game.wine.prefix.join("drive_c").exists() {
|
if !wine_prefix.join("drive_c").exists() {
|
||||||
return Ok(Self::PrefixNotExists);
|
return Ok(Self::PrefixNotExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check game installation status
|
// Check game installation status
|
||||||
status(StateUpdating::Game);
|
status(StateUpdating::Game);
|
||||||
|
|
||||||
let game = Game::new(&config.game.path);
|
let game = Game::new(&game_path);
|
||||||
let diff = game.try_get_diff()?;
|
let diff = game.try_get_diff()?;
|
||||||
|
|
||||||
Ok(match diff {
|
Ok(match diff {
|
||||||
VersionDiff::Latest(_) | VersionDiff::Predownload { .. } => {
|
VersionDiff::Latest(_) | VersionDiff::Predownload { .. } => {
|
||||||
let mut predownload_voice = Vec::new();
|
let mut predownload_voice = Vec::new();
|
||||||
|
|
||||||
for voice_package in &config.game.voices {
|
for locale in voices {
|
||||||
let mut voice_package = VoicePackage::with_locale(match VoiceLocale::from_str(voice_package) {
|
let mut voice_package = VoicePackage::with_locale(locale)?;
|
||||||
Some(locale) => locale,
|
|
||||||
None => return Err(anyhow::anyhow!("Incorrect voice locale \"{}\" specified in the config", voice_package))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
status(StateUpdating::Voice(voice_package.locale()));
|
status(StateUpdating::Voice(voice_package.locale()));
|
||||||
|
|
||||||
// Replace voice package struct with the one constructed in the game's folder
|
// 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"
|
// so it'll properly calculate its difference instead of saying "not installed"
|
||||||
if voice_package.is_installed_in(&config.game.path) {
|
if voice_package.is_installed_in(&game_path) {
|
||||||
voice_package = match VoicePackage::new(get_voice_package_path(&config.game.path, voice_package.locale())) {
|
voice_package = match VoicePackage::new(get_voice_package_path(&game_path, voice_package.locale())) {
|
||||||
Some(locale) => locale,
|
Some(locale) => locale,
|
||||||
None => return Err(anyhow::anyhow!("Failed to load {} voice package", voice_package.locale().to_name()))
|
None => return Err(anyhow::anyhow!("Failed to load {} voice package", voice_package.locale().to_name()))
|
||||||
};
|
};
|
||||||
|
@ -113,9 +109,9 @@ impl LauncherState {
|
||||||
|
|
||||||
status(StateUpdating::Patch);
|
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 {
|
if let VersionDiff::Predownload { .. } = diff {
|
||||||
Self::PredownloadAvailable {
|
Self::PredownloadAvailable {
|
||||||
game: diff,
|
game: diff,
|
||||||
|
@ -138,4 +134,28 @@ impl LauncherState {
|
||||||
VersionDiff::NotInstalled { .. } => Self::GameNotInstalled(diff)
|
VersionDiff::NotInstalled { .. } => Self::GameNotInstalled(diff)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "config")]
|
||||||
|
pub fn get_from_config<T: Fn(StateUpdating)>(status: T) -> anyhow::Result<Self> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue