fix: wait spawning patcher until osu is spawned

This commit is contained in:
HorizonCode committed 2026-05-21 08:18:50 +02:00
1 parent e76d67f3a8
commit eca08f16c5
1 file changed
+36 -4
+36 -4
View File
@@ -169,7 +169,12 @@ pub async fn get_beatmapsets_count(folder: String) -> Option<u64> {
} }
let osu_db_bytes = fs::read(osu_db_path).await.ok()?; let osu_db_bytes = fs::read(osu_db_path).await.ok()?;
let osu_db = parse_osudb(osu_db_bytes).ok()?; let osu_db = parse_osudb(osu_db_bytes).ok()?;
let beatmap_sets = osu_db.beatmaps.iter().map(|b| b.beatmapset_id).collect::<HashSet<_>>().len(); let beatmap_sets = osu_db
.beatmaps
.iter()
.map(|b| b.beatmapset_id)
.collect::<HashSet<_>>()
.len();
Some(beatmap_sets as u64) Some(beatmap_sets as u64)
} }
@@ -248,7 +253,7 @@ pub async fn get_skins_count(folder: String) -> Option<u64> {
let skins_folder = path.join("Skins"); let skins_folder = path.join("Skins");
if !skins_folder.exists() { if !skins_folder.exists() {
return None; return Some(0);
} }
let mut count = 0; let mut count = 0;
@@ -437,9 +442,9 @@ pub async fn run_osu(folder: String, patch: bool) -> Result<(), String> {
} }
}; };
#[cfg(windows)]
{
if patch { if patch {
sleep(Duration::from_secs(3)).await;
let patcher_exe_path = PathBuf::from(&folder) let patcher_exe_path = PathBuf::from(&folder)
.join("EZPPLauncher") .join("EZPPLauncher")
.join("patcher") .join("patcher")
@@ -448,6 +453,32 @@ pub async fn run_osu(folder: String, patch: bool) -> Result<(), String> {
if patcher_exe_path.exists() { if patcher_exe_path.exists() {
#[cfg(windows)] #[cfg(windows)]
{ {
let mut sys = System::new_all();
loop {
sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
let mut found = false;
for (_pid, process) in sys.processes() {
if process.name() == "osu!.exe" {
let pid = process.pid();
let title = get_window_title_by_pid(pid);
if !title.is_empty() && !title.contains("updater") {
found = true;
break;
}
}
}
if found {
break;
}
sleep(Duration::from_millis(500)).await;
}
let _ = Command::new(&patcher_exe_path) let _ = Command::new(&patcher_exe_path)
.creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP) .creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP)
.spawn() .spawn()
@@ -455,6 +486,7 @@ pub async fn run_osu(folder: String, patch: bool) -> Result<(), String> {
} }
} }
} }
}
game_process.wait().await.map_err(|e| e.to_string())?; game_process.wait().await.map_err(|e| e.to_string())?;
Ok(()) Ok(())