From 75380038ad4dd2cef147670bd121e4293714bea2 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Thu, 3 Jul 2025 16:33:41 +0200 Subject: [PATCH] wip: osu! updating --- src-tauri/src/commands.rs | 20 +++++++++++++++----- src-tauri/src/utils.rs | 11 +---------- src/lib/utils.ts | 4 +++- src/pages/Launch.svelte | 4 ++-- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 2532b73..d1ed917 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -224,11 +224,14 @@ pub fn set_osu_config_value( } #[tauri::command] -pub fn run_osu_updater(osu_path: String) -> Result<(), String> { - let mut updater_process = Command::new(osu_path.clone()) - .arg("-repair") - .spawn() - .map_err(|e| e.to_string())?; +pub fn run_osu_updater(folder: String) -> Result<(), String> { + let osu_exe_path = PathBuf::from(folder).join("osu!.exe"); + let mut updater_process = Command::new(osu_exe_path) + .arg("-repair") + .spawn() + .map_err(|e| e.to_string())?; + + thread::sleep(Duration::from_millis(500)); @@ -243,8 +246,15 @@ pub fn run_osu_updater(osu_path: String) -> Result<(), String> { let process_id = process.pid(); let window_title = get_window_title_by_pid(process_id); + println!("updater_process id: {}", updater_process.id()); + println!("process_id: {}", process_id.as_u32()); + + println!("found osu!.exe process with window title: {}", window_title); + if !window_title.is_empty() { + println!("Killing osu!.exe process"); if let Ok(_) = process.kill_and_wait() { + println!("osu!.exe process killed"); termination_thread_running = false; break; } diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index 228630b..af7efc4 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -4,10 +4,7 @@ use std::os::windows::ffi::OsStringExt; use std::path::Path; use std::ptr; use sysinfo::Pid; -use winapi::{ - shared::minwindef::LPARAM, - um::winuser::{FindWindowW, GetWindowTextW, GetWindowThreadProcessId}, -}; +use winapi::um::winuser::{FindWindowW, GetWindowTextW, GetWindowThreadProcessId}; pub fn check_folder_completeness>(folder_path: P, required_files: &[&str]) -> f32 { let mut found = 0; @@ -27,12 +24,10 @@ pub fn check_folder_completeness>(folder_path: P, required_files: pub fn get_osu_user_config>( osu_folder_path: P, ) -> Option> { - // Ensure the osu! folder path is valid if !osu_folder_path.as_ref().exists() { return None; } - // get the osu!{username}.cfg file from the osu! folder let current_user = std::env::var("USERNAME").unwrap_or_else(|_| "Admin".to_string()); let osu_config_path = osu_folder_path .as_ref() @@ -41,7 +36,6 @@ pub fn get_osu_user_config>( return None; } - // read the osu config and return it as a map, key and value are separated by ' = ' let mut config_map = std::collections::HashMap::new(); if let Ok(contents) = std::fs::read_to_string(osu_config_path) { for line in contents.lines() { @@ -97,18 +91,15 @@ pub fn set_osu_user_config_value( pub fn get_osu_config>( osu_folder_path: P, ) -> Option> { - // Ensure the osu! folder path is valid if !osu_folder_path.as_ref().exists() { return None; } - // get the osu!.cfg file from the osu! folder let osu_config_path = osu_folder_path.as_ref().join("osu!.cfg"); if !osu_config_path.exists() { return None; } - // read the osu config and return it as a map, key and value are separated by ' = ' let mut config_map = std::collections::HashMap::new(); if let Ok(contents) = std::fs::read_to_string(osu_config_path) { for line in contents.lines() { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 007b8d2..f61edb2 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -58,7 +58,9 @@ export const releaseStreamToReadable = (releaseStream: string) => { export const compareBuildNumbers = (current: string, target: string): number => { const parse = (version: string): [number, number] => { - const cleaned = version.split(/[^0-9.]/)[0]; + const cleaned = version.startsWith('b') + ? version.slice(1).split(/[^0-9.]/)[0] + : version.split(/[^0-9.]/)[0]; const [baseStr, hotfixStr] = cleaned.split('.'); const base = parseInt(baseStr, 10); diff --git a/src/pages/Launch.svelte b/src/pages/Launch.svelte index 29e8b3f..2b7186a 100644 --- a/src/pages/Launch.svelte +++ b/src/pages/Launch.svelte @@ -145,7 +145,6 @@ } const versions = compareBuildNumbers($osuBuild, streamInfo); - if (versions > 0) { launchInfo = 'Update found!'; await new Promise((res) => setTimeout(res, 1500)); @@ -154,7 +153,8 @@ } else { launchInfo = 'You are up to date!'; } - } catch { + } catch(err) { + console.log(err); toast.error('Hmmm...', { description: 'Failed to check for updates.', });