Skip to content

Commit

Permalink
feat: better osu! restarting
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Apr 19, 2024
1 parent 52f00c9 commit 7638e94
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ seahorse = "2.2.0"
whoami = "1.5.1"
rust-ini = "0.21.0"
lazy_static = "1.4.0"
powershell_script = "1.1.0"
osu-db = { version = "0.3.0", default-features = false }
20 changes: 8 additions & 12 deletions src/osu_util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::process;
use std::thread::sleep;
use std::time::Duration;

pub fn edit_db(osu_db: &String, username: &String) {
let mut db = osu_db::Listing::from_file(&osu_db)
Expand All @@ -11,17 +9,15 @@ pub fn edit_db(osu_db: &String, username: &String) {
}

pub fn restart_osu(osu_exe: &String, server: &String) {
let output = process::Command::new("taskkill")
.args(&[
"/IM",
"osu!.exe"
])
.output()
.expect("Failed to kill osu");
let powershell_cmd: &str = "\
$p = Get-Process -Name osu! -ErrorAction SilentlyContinue; \
if (!$p) { Exit 0; }; \
Stop-Process -Force -InputObject $p -ErrorAction Stop; \
Wait-Process -InputObject $p";

if output.stdout.starts_with("SUCCESS".as_bytes()) {
println!("Killed running osu!.exe, restarting...");
sleep(Duration::from_secs(1));
match powershell_script::run(powershell_cmd) {
Err(e) => panic!("Failed to kill osu!:\n{e}"),
_ => println!("Killed running osu!.exe, restarting..."),
}

let server = if server == "osu.ppy.sh" { "" } else { server };
Expand Down

0 comments on commit 7638e94

Please sign in to comment.