Removed usage of config feature in some other features

This commit is contained in:
Observer KRypt0n_ 2022-11-12 09:51:35 +02:00
parent 875bce5dbd
commit 7143357a7b
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
5 changed files with 58 additions and 41 deletions

View file

@ -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"]

View file

@ -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<Group> = vec![
Group {
@ -45,20 +43,13 @@ impl Version {
}
/// 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 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"))
};

View file

@ -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<T: Into<PathBuf>>(&self, wine_folder: Option<T>) -> 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
)
}

View file

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

View file

@ -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<T: Fn(StateUpdating)>(status: T) -> anyhow::Result<Self> {
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<T, F, S>(wine_prefix: T, game_path: T, voices: Vec<VoiceLocale>, patch_servers: Vec<S>, status: F) -> anyhow::Result<Self>
where
T: Into<PathBuf>,
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<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)
}
}