From 1194366bd12d33229111f8d360959eb2c0241ee4 Mon Sep 17 00:00:00 2001 From: Nikita Podvirnyi Date: Fri, 28 Jun 2024 23:55:59 +0200 Subject: [PATCH] feat(wuwa): removed sessions manager Game doesn't have login sessions at all lmao --- src/games/wuwa/game.rs | 16 ------- src/games/wuwa/mod.rs | 3 -- src/games/wuwa/sessions.rs | 95 -------------------------------------- 3 files changed, 114 deletions(-) delete mode 100644 src/games/wuwa/sessions.rs diff --git a/src/games/wuwa/game.rs b/src/games/wuwa/game.rs index 27acb78..77544bb 100644 --- a/src/games/wuwa/game.rs +++ b/src/games/wuwa/game.rs @@ -18,12 +18,6 @@ use crate::wuwa::consts; #[cfg(feature = "discord-rpc")] use crate::discord_rpc::*; -#[cfg(feature = "sessions")] -use crate::{ - sessions::SessionsExt, - wuwa::sessions::Sessions -}; - #[derive(Debug, Clone)] struct Folders { pub wine: PathBuf, @@ -216,11 +210,6 @@ pub fn run() -> anyhow::Result<()> { command.envs(&config.game.environment); - #[cfg(feature = "sessions")] - if let Some(current) = Sessions::get_current()? { - Sessions::apply(current, config.get_wine_prefix_path())?; - } - // Run command let variables = command @@ -268,10 +257,5 @@ pub fn run() -> anyhow::Result<()> { rpc.update(RpcUpdates::Disconnect)?; } - #[cfg(feature = "sessions")] - if let Some(current) = Sessions::get_current()? { - Sessions::update(current, config.get_wine_prefix_path())?; - } - Ok(()) } diff --git a/src/games/wuwa/mod.rs b/src/games/wuwa/mod.rs index de66d04..6138c07 100644 --- a/src/games/wuwa/mod.rs +++ b/src/games/wuwa/mod.rs @@ -8,6 +8,3 @@ pub mod states; #[cfg(feature = "game")] pub mod game; - -#[cfg(feature = "sessions")] -pub mod sessions; diff --git a/src/games/wuwa/sessions.rs b/src/games/wuwa/sessions.rs deleted file mode 100644 index 9d93b81..0000000 --- a/src/games/wuwa/sessions.rs +++ /dev/null @@ -1,95 +0,0 @@ -use std::path::{Path, PathBuf}; - -use serde::{Serialize, Deserialize}; - -use crate::sessions::{ - SessionsExt, - Sessions as SessionsDescriptor -}; - -use super::consts::launcher_dir; - -/// Get default sessions file path -/// -/// `$HOME/.local/share/wavey-launcher/sessions.json` -#[inline] -pub fn sessions_file() -> anyhow::Result { - launcher_dir().map(|dir| dir.join("sessions.json")) -} - -// FIXME: update registry entries names - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct SessionData { - // [Software\\kurogame\\PGR] - pub game_reg: String -} - -pub struct Sessions; - -impl SessionsExt for Sessions { - type SessionData = SessionData; - - fn get_sessions() -> anyhow::Result> { - let path = sessions_file()?; - - if !path.exists() { - tracing::warn!("Session file doesn't exist. Returning default value"); - - return Ok(SessionsDescriptor::default()); - } - - Ok(serde_json::from_slice(&std::fs::read(path)?)?) - } - - fn set_sessions(sessions: SessionsDescriptor) -> anyhow::Result<()> { - Ok(std::fs::write(sessions_file()?, serde_json::to_string_pretty(&sessions)?)?) - } - - fn update(name: String, prefix: impl AsRef) -> anyhow::Result<()> { - let mut sessions = Self::get_sessions()?; - - tracing::info!("Updating session '{name}' from prefix: {:?}", prefix.as_ref()); - - let mut new_session = Self::SessionData { - game_reg: String::new() - }; - - for entry in std::fs::read_to_string(prefix.as_ref().join("user.reg"))?.split("\n\n") { - if entry.starts_with("[Software\\\\kurogame\\\\PGR]") { - new_session.game_reg = entry.to_owned(); - } - } - - sessions.sessions.insert(name, new_session); - - Self::set_sessions(sessions) - } - - fn apply(name: String, prefix: impl AsRef) -> anyhow::Result<()> { - let sessions = Self::get_sessions()?; - - let Some(session) = sessions.sessions.get(&name) else { - anyhow::bail!("Session with given name doesn't exist"); - }; - - tracing::info!("Applying session '{name}' to prefix: {:?}", prefix.as_ref()); - - let entries: String = std::fs::read_to_string(prefix.as_ref().join("user.reg"))? - .split("\n\n") - .map(|entry| { - let new_entry = if entry.starts_with("[Software\\\\kurogame\\\\PGR]") { - session.game_reg.clone() - } - - else { - entry.to_owned() - }; - - new_entry + "\n\n" - }) - .collect(); - - Ok(std::fs::write(prefix.as_ref().join("user.reg"), format!("{}\n", entries.trim_end()))?) - } -}