From 493d425ee7fb27c026931688dcbf921734968ea3 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Fri, 4 Jul 2025 09:16:07 +0200 Subject: [PATCH] chore: force release stream to stable, connecting to ezppfarm does now work --- src-tauri/src/commands.rs | 156 ++++++++++++++++++++++---------------- src-tauri/src/lib.rs | 7 +- src/lib/osuUtil.ts | 4 +- src/pages/Launch.svelte | 60 +++++++-------- 4 files changed, 120 insertions(+), 107 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index d342268..dea52a0 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -216,13 +216,6 @@ pub fn get_osu_release_stream(folder: String) -> String { .unwrap_or_else(|| "Stable40".to_string()); } -#[tauri::command] -pub fn get_osu_previous_release_stream(folder: String) -> Option { - let path = PathBuf::from(folder); - let osu_config = get_osu_config(path.clone()); - osu_config.and_then(|config| config.get("_PreviousReleaseStream").cloned()) -} - #[derive(serde::Deserialize)] pub struct ConfigEntry { pub key: String, @@ -261,77 +254,106 @@ pub fn set_osu_config_values( #[tauri::command] pub fn run_osu_updater(folder: String) -> Result<(), String> { + let osu_exe_path = PathBuf::from(folder.clone()).join("osu!.exe"); + #[cfg(windows)] + const DETACHED_PROCESS: u32 = 0x00000008; + #[cfg(windows)] + const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200; + + let handle = thread::spawn(move || { + #[cfg(windows)] + let mut updater_process = Command::new(&osu_exe_path) + .arg("-repair") + .creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP) + .spawn() + .ok()?; // Ignore error, just exit thread + + #[cfg(not(windows))] + let mut updater_process = Command::new(&osu_exe_path).arg("-repair").spawn().ok()?; // Ignore error, just exit thread + + thread::sleep(Duration::from_millis(500)); + + let mut sys = System::new_all(); + sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true); + + let mut termination_thread_running = true; + + while termination_thread_running { + for (_, process) in sys.processes() { + if process.name() == "osu!.exe" { + let process_id = process.pid(); + let window_title = get_window_title_by_pid(process_id); + + if !window_title.is_empty() && !window_title.contains("updater") { + if let Ok(_) = process.kill_and_wait() { + termination_thread_running = false; + break; + } + } + } + } + + if !termination_thread_running { + break; + } + + thread::sleep(Duration::from_millis(500)); + sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true); + } + + let _ = updater_process.wait(); + + let force_update_files = [".require_update", "help.txt", "_pending"]; + + for update_file_name in &force_update_files { + let update_file = PathBuf::from(&folder).join(update_file_name); + if update_file.exists() { + let metadata = std::fs::symlink_metadata(&update_file); + if let Ok(meta) = metadata { + let result = if meta.is_dir() { + std::fs::remove_dir_all(&update_file) + } else { + std::fs::remove_file(&update_file) + }; + if let Err(e) = result { + eprintln!( + "Failed to remove force update file {:?}: {}", + update_file, e + ); + } + } + } + } + + Some(()) + }); + + handle.join().map_err(|_| "Thread panicked".to_string())?; + Ok(()) +} + +#[tauri::command] +pub fn run_osu(folder: String) -> Result<(), String> { let osu_exe_path = PathBuf::from(folder).join("osu!.exe"); #[cfg(windows)] const DETACHED_PROCESS: u32 = 0x00000008; #[cfg(windows)] const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200; - #[cfg(windows)] - let mut updater_process = Command::new(osu_exe_path) - .arg("-repair") - .creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP) - .spawn() - .map_err(|e| e.to_string())?; - - #[cfg(not(windows))] - let mut updater_process = Command::new(osu_exe_path) - .arg("-repair") - .spawn() - .map_err(|e| e.to_string())?; - - thread::sleep(Duration::from_millis(500)); - - let mut sys = System::new_all(); - sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true); - - let mut termination_thread_running = true; - - while termination_thread_running { - for (_, process) in sys.processes() { - if process.name() == "osu!.exe" { - let process_id = process.pid(); - let window_title = get_window_title_by_pid(process_id); - - if !window_title.is_empty() && !window_title.contains("updater") { - if let Ok(_) = process.kill_and_wait() { - termination_thread_running = false; - break; - } - } - } - } - - if !termination_thread_running { - break; - } - sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true); - thread::sleep(Duration::from_millis(500)); - } - - updater_process.wait().map_err(|e| e.to_string())?; - - Ok(()) -} - -#[tauri::command] -pub fn run_osu(folder: String) -> Result<(), String> { - let osu_exe_path = PathBuf::from(folder).join("osu!.exe"); - #[cfg(windows)] - const DETACHED_PROCESS: u32 = 0x00000008; - #[cfg(windows)] - const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200; - #[cfg(windows)] let mut game_process = Command::new(osu_exe_path) - .creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP) - .spawn() - .map_err(|e| e.to_string())?; + .creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP) + .arg("-devserver") + .arg("ez-pp.farm") + .spawn() + .map_err(|e| e.to_string())?; #[cfg(not(windows))] let mut game_process = Command::new(osu_exe_path) - .spawn() - .map_err(|e| e.to_string())?; + .arg("-devserver") + .arg("ez-pp.farm") + .spawn() + .map_err(|e| e.to_string())?; game_process.wait().map_err(|e| e.to_string())?; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index e94c833..13f1e13 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -4,9 +4,9 @@ use tauri::Manager; pub mod commands; pub mod utils; use crate::commands::{ - find_osu_installation, get_beatmapsets_count, get_hwid, get_osu_previous_release_stream, - get_osu_release_stream, get_osu_version, get_skins_count, run_osu, run_osu_updater, - set_osu_config_values, set_osu_user_config_values, valid_osu_folder, + find_osu_installation, get_beatmapsets_count, get_hwid, get_osu_release_stream, + get_osu_version, get_skins_count, run_osu, run_osu_updater, set_osu_config_values, + set_osu_user_config_values, valid_osu_folder, }; #[cfg_attr(mobile, tauri::mobile_entry_point)] @@ -32,7 +32,6 @@ pub fn run() { get_skins_count, get_osu_version, get_osu_release_stream, - get_osu_previous_release_stream, set_osu_config_values, set_osu_user_config_values, run_osu_updater, diff --git a/src/lib/osuUtil.ts b/src/lib/osuUtil.ts index aec5fc3..364d24e 100644 --- a/src/lib/osuUtil.ts +++ b/src/lib/osuUtil.ts @@ -18,7 +18,7 @@ export const setConfigValues = async ( entries, }); -export const getPreviousReleaseStream = async (folder: string) => { - const result = await invoke('get_osu_previous_release_stream', { folder }); +export const getReleaseStream = async (folder: string) => { + const result = await invoke('get_osu_release_stream', { folder }); return typeof result === 'string' ? result : undefined; }; diff --git a/src/pages/Launch.svelte b/src/pages/Launch.svelte index a590d2f..ec8f622 100644 --- a/src/pages/Launch.svelte +++ b/src/pages/Launch.svelte @@ -67,7 +67,7 @@ } from '@/gamemode'; import { currentUserInfo } from '@/data'; import { osuapi } from '@/api/osuapi'; - import { getPreviousReleaseStream, setConfigValues, setUserConfigValues } from '@/osuUtil'; + import { getReleaseStream, setConfigValues, setUserConfigValues } from '@/osuUtil'; import { getCurrentWindow } from '@tauri-apps/api/window'; let selectedTab = $state('home'); @@ -125,7 +125,7 @@ }; const launch = async (offline: boolean) => { - if (!$osuBuild || !$osuStream) { + if (!$osuBuild) { toast.error('Hmmm...', { description: 'There was an issue detecting your installed osu! version', }); @@ -145,7 +145,7 @@ } try { - const streamInfo = await osuapi.latestBuildVersion($osuStream ?? 'stable40'); + const streamInfo = await osuapi.latestBuildVersion('stable40'); if (!streamInfo) { toast.error('Hmmm...', { description: 'Failed to check for updates.', @@ -154,17 +154,37 @@ return; } - const previousReleaseStream = await getPreviousReleaseStream(osuPath); - let forceUpdate = previousReleaseStream && previousReleaseStream !== $osuStream; + const releaseStream = await getReleaseStream(osuPath); + let forceUpdate = releaseStream && releaseStream.toLowerCase() !== 'stable40'; const versions = compareBuildNumbers($osuBuild, streamInfo); if (versions > 0 || forceUpdate) { launchInfo = 'Update found!'; await new Promise((res) => setTimeout(res, 1500)); launchInfo = 'Running osu! updater...'; - await setUserConfigValues(osuPath, [{ key: 'LastVersion', value: streamInfo }]); + await setUserConfigValues(osuPath, [ + { + key: 'LastVersion', + value: `b${streamInfo}`, + }, + ]); + await setConfigValues(osuPath, [ + { + key: '_ReleaseStream', + value: 'Stable40', + }, + ]); + osuStream.set('Stable40'); + osuBuild.set(`b${streamInfo}`); await invoke('run_osu_updater', { folder: osuPath }); launchInfo = 'osu! is now up to date!'; + if (forceUpdate) + await setConfigValues(osuPath, [ + { + key: '_UpdateFailCount', + value: '0', + }, + ]); } else { launchInfo = 'You are up to date!'; } @@ -764,34 +784,6 @@ onclick={browse_osu_installation}>Browse -
- -
The release stream of your osu! client
-
-
- { - const oldStream = $osuStream; - osuStream.set(newStream); - await setConfigValues($osuInstallationPath, [ - { key: '_ReleaseStream', value: newStream }, - { key: '_PreviousReleaseStream', value: oldStream ?? newStream }, - ]); - }} - > - -
- {releaseStreamToReadable($osuStream ?? 'Stable40')} -
-
- - Stable - Cutting Edge - -
-
{/if}