From 41dc6532d80a1eba5187fab204564f6043c6ab66 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Mon, 12 Sep 2022 00:00:17 +0200 Subject: [PATCH] Fixed downloading of fps unlocker and launcher hiding --- src/lib/fps_unlocker/mod.rs | 6 +++++- src/lib/game.rs | 18 +++++++++++++----- src/ui/main.rs | 4 +++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/lib/fps_unlocker/mod.rs b/src/lib/fps_unlocker/mod.rs index 25a135e..dbb3495 100644 --- a/src/lib/fps_unlocker/mod.rs +++ b/src/lib/fps_unlocker/mod.rs @@ -48,7 +48,11 @@ impl FpsUnlocker { } pub fn get_binary(&self) -> String { - format!("{}/unlocker.exe", self.dir) + Self::get_binary_in(&self.dir) + } + + pub fn get_binary_in(dir: T) -> String { + format!("{}/unlocker.exe", dir.to_string()) } pub fn dir(&self) -> &str { diff --git a/src/lib/game.rs b/src/lib/game.rs index bfc977a..1dd3eb8 100644 --- a/src/lib/game.rs +++ b/src/lib/game.rs @@ -90,11 +90,19 @@ pub fn run() -> anyhow::Result<()> { if config.game.enhancements.fps_unlocker.enabled { let unlocker = match FpsUnlocker::from_dir(&config.game.enhancements.fps_unlocker.path) { Ok(Some(unlocker)) => unlocker, - Ok(None) => match FpsUnlocker::download(&config.game.enhancements.fps_unlocker.path) { - Ok(unlocker) => unlocker, - Err(err) => return Err(anyhow::anyhow!("Failed to download FPS unlocker: {err}")) - }, - Err(err) => return Err(anyhow::anyhow!("Failed to load FPS unlocker: {err}")) + + other => { + // Ok(None) means unknown version, so we should delete it before downloading newer one + // because otherwise downloader will try to continue downloading "partially downloaded" file + if let Ok(None) = other { + std::fs::remove_file(FpsUnlocker::get_binary_in(&config.game.enhancements.fps_unlocker.path))?; + } + + match FpsUnlocker::download(&config.game.enhancements.fps_unlocker.path) { + Ok(unlocker) => unlocker, + Err(err) => return Err(anyhow::anyhow!("Failed to download FPS unlocker: {err}")) + } + } }; // Generate FPS unlocker config file diff --git a/src/ui/main.rs b/src/ui/main.rs index 7e9f174..f67e2b1 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -334,7 +334,9 @@ impl App { match Command::new("ps").arg("-A").stdout(Stdio::piped()).output() { Ok(output) => { - if !String::from_utf8_lossy(&output.stdout).contains("GenshinImpact.e") { + let output = String::from_utf8_lossy(&output.stdout); + + if !output.contains("GenshinImpact.e") && !output.contains("unlocker.exe") { break; } },