Skip to content

Commit

Permalink
Fix launching game when paths differ
Browse files Browse the repository at this point in the history
I noticed that one issue on Grasscutters#7 was probably caused by anime-launcher-sdk trying to run the wrong version of the game (the one specified in aagl).
It's fixed now.
  • Loading branch information
fnr1r committed Dec 24, 2023
1 parent ebb7616 commit e961811
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src-tauri/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ async fn shutdown_signal() {
static SERVER: Lazy<Mutex<String>> = Lazy::new(|| Mutex::new("http://localhost:443".to_string()));
static REDIRECT_MORE: Lazy<Mutex<bool>> = Lazy::new(|| Mutex::new(false));

#[cfg(target_os = "linux")]
static PREVIOUS_PATH: Lazy<Mutex<Option<PathBuf>>> = Lazy::new(Mutex::default);

#[derive(Clone)]
struct ProxyHandler;

Expand Down Expand Up @@ -288,6 +291,16 @@ pub fn connect_to_proxy(proxy_port: u16) {
println!("Connected to the proxy.");
}

#[cfg(target_os = "linux")]
#[inline]
fn get_aagl_game_path(config: &mut anime_launcher_sdk::genshin::config::Schema) -> &mut PathBuf {
use anime_launcher_sdk::anime_game_core::genshin::prelude::GameEdition as E;
match config.launcher.edition {
E::Global => &mut config.game.path.global,
E::China => &mut config.game.path.china,
}
}

#[cfg(target_os = "linux")]
pub fn connect_to_proxy(proxy_port: u16) {
let mut config = Config::get().unwrap();
Expand All @@ -304,6 +317,25 @@ pub fn connect_to_proxy(proxy_port: u16) {
.environment
.insert("https_proxy".to_string(), proxy_addr);
}
// TODO: Move this to an appropreately named function
'ensurepath: {
let aagl_gamepath = get_aagl_game_path(&mut config);
let cult_config = get_config();
let Some(cult_gamepath) = cult_config.game_install_path else {
break 'ensurepath;
};
let Some(cult_gamepath) = Path::new(&cult_gamepath).parent() else {
break 'ensurepath;
};
if aagl_gamepath == cult_gamepath {
break 'ensurepath;
}
PREVIOUS_PATH
.lock()
.unwrap()
.replace(aagl_gamepath.to_owned());
*aagl_gamepath = cult_gamepath.to_owned();
}
Config::update(config);
}

Expand Down Expand Up @@ -340,6 +372,12 @@ pub fn disconnect_from_proxy() {
if config.game.environment.contains_key("https_proxy") {
config.game.environment.remove("https_proxy");
}
// TODO: Move this to an appropreately named function
// Also, this could probably be removed since we never run update_raw,
// which writes the changes to the file.
if let Some(prev_game_path) = PREVIOUS_PATH.lock().unwrap().take() {
*get_aagl_game_path(&mut config) = prev_game_path;
};
Config::update(config);
}

Expand Down

0 comments on commit e961811

Please sign in to comment.