From b61f8730ef2a425a1ee08c8c054bba90df1d4555 Mon Sep 17 00:00:00 2001 From: pizzaboxer <41478239+pizzaboxer@users.noreply.github.com> Date: Wed, 8 Mar 2023 22:08:04 +0000 Subject: [PATCH] Fix process detection also fixed a bug with reshade shader uninstalling --- Bloxstrap/App.xaml.cs | 2 - Bloxstrap/Bootstrapper.cs | 53 ++++++++++-------------- Bloxstrap/Helpers/Utilities.cs | 11 ++--- Bloxstrap/Integrations/RbxFpsUnlocker.cs | 2 +- Bloxstrap/Integrations/ReShade.cs | 10 +++-- 5 files changed, 36 insertions(+), 42 deletions(-) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index dfeaf49..588b1b5 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -187,10 +187,8 @@ namespace Bloxstrap mutex = new(true, "Bloxstrap_MenuMutex"); } -#if !DEBUG if (Utilities.GetProcessCount(ProjectName) > 1) ShowMessageBox($"{ProjectName} is currently running, likely as a background Roblox process. Please note that not all your changes will immediately apply until you close all currently open Roblox instances.", MessageBoxImage.Information); -#endif new MainWindow().ShowDialog(); } diff --git a/Bloxstrap/Bootstrapper.cs b/Bloxstrap/Bootstrapper.cs index 8d5c49e..8efda9d 100644 --- a/Bloxstrap/Bootstrapper.cs +++ b/Bloxstrap/Bootstrapper.cs @@ -145,7 +145,7 @@ namespace Bloxstrap CheckInstallMigration(); // if roblox needs updating but is running and we have multiple instances open, ignore update for now - if (App.IsFirstRun || _versionGuid != App.State.Prop.VersionGuid && Utilities.GetProcessCount("RobloxPlayerBeta") == 0) + if (App.IsFirstRun || _versionGuid != App.State.Prop.VersionGuid && !Utilities.CheckIfRobloxRunning()) await InstallLatestVersion(); // last time the version folder was set, it was set to the latest version guid @@ -299,34 +299,6 @@ namespace Bloxstrap App.Logger.WriteLine("[Bootstrapper::CheckInstallMigration] Finished migrating install location!"); } - private bool ShutdownIfRobloxRunning() - { - App.Logger.WriteLine($"[Bootstrapper::ShutdownIfRobloxRunning] Checking if Roblox is running..."); - - if (Utilities.GetProcessCount("RobloxPlayerBeta") == 0) - return false; - - App.Logger.WriteLine($"[Bootstrapper::ShutdownIfRobloxRunning] Attempting to shutdown Roblox..."); - - Dialog?.PromptShutdown(); - - try - { - foreach (Process process in Process.GetProcessesByName("RobloxPlayerBeta")) - { - process.CloseMainWindow(); - process.Close(); - } - } - catch (Exception ex) - { - App.Logger.WriteLine($"[Bootstrapper::ShutdownIfRobloxRunning] Failed to close process! {ex}"); - } - - App.Logger.WriteLine($"[Bootstrapper::ShutdownIfRobloxRunning] All Roblox processes closed"); - return true; - } - private async Task StartRoblox() { string startEventName = App.ProjectName.Replace(" ", "") + "StartEvent"; @@ -601,8 +573,29 @@ namespace Bloxstrap private void Uninstall() { - ShutdownIfRobloxRunning(); + // prompt to shutdown roblox if its currently running + if (Utilities.CheckIfRobloxRunning()) + { + App.Logger.WriteLine($"[Bootstrapper::Uninstall] Prompting to shut down all open Roblox instances"); + + Dialog?.PromptShutdown(); + try + { + foreach (Process process in Process.GetProcessesByName("RobloxPlayerBeta")) + { + process.CloseMainWindow(); + process.Close(); + } + } + catch (Exception ex) + { + App.Logger.WriteLine($"[Bootstrapper::ShutdownIfRobloxRunning] Failed to close process! {ex}"); + } + + App.Logger.WriteLine($"[Bootstrapper::Uninstall] All Roblox processes closed"); + } + SetStatus($"Uninstalling {App.ProjectName}..."); //App.Settings.ShouldSave = false; diff --git a/Bloxstrap/Helpers/Utilities.cs b/Bloxstrap/Helpers/Utilities.cs index 07c3c40..928e928 100644 --- a/Bloxstrap/Helpers/Utilities.cs +++ b/Bloxstrap/Helpers/Utilities.cs @@ -31,7 +31,7 @@ namespace Bloxstrap.Helpers if (log) App.Logger.WriteLine($"[Utilities::CheckIfProcessRunning] Checking if '{processName}' is running..."); - Process[] processes = Process.GetProcessesByName("RobloxPlayerBeta"); + Process[] processes = Process.GetProcessesByName(processName); if (log) App.Logger.WriteLine($"[Utilities::CheckIfProcessRunning] Found {processes.Length} process(es) running for '{processName}'"); @@ -39,10 +39,11 @@ namespace Bloxstrap.Helpers return processes.Length; } - public static void OpenWebsite(string website) - { - Process.Start(new ProcessStartInfo { FileName = website, UseShellExecute = true }); - } + public static bool CheckIfProcessRunning(string processName, bool log = true) => GetProcessCount(processName, log) >= 1; + + public static bool CheckIfRobloxRunning(bool log = true) => CheckIfProcessRunning("RobloxPlayerBeta", log); + + public static void OpenWebsite(string website) => Process.Start(new ProcessStartInfo { FileName = website, UseShellExecute = true }); public static async Task GetJson(string url) { diff --git a/Bloxstrap/Integrations/RbxFpsUnlocker.cs b/Bloxstrap/Integrations/RbxFpsUnlocker.cs index 49dd9d4..bb56886 100644 --- a/Bloxstrap/Integrations/RbxFpsUnlocker.cs +++ b/Bloxstrap/Integrations/RbxFpsUnlocker.cs @@ -64,7 +64,7 @@ namespace Bloxstrap.Integrations if (!App.Settings.Prop.RFUEnabled) { // don't delete rbxfpsunlocker if rbxfpsunlocker and roblox is currently running - if (Utilities.GetProcessCount(ApplicationName) > 0 && Utilities.GetProcessCount("RobloxPlayerBeta") > 0) + if (Utilities.CheckIfProcessRunning(ApplicationName) && Utilities.CheckIfRobloxRunning()) return; App.State.Prop.RbxFpsUnlockerVersion = ""; diff --git a/Bloxstrap/Integrations/ReShade.cs b/Bloxstrap/Integrations/ReShade.cs index f68cfbf..5931f1e 100644 --- a/Bloxstrap/Integrations/ReShade.cs +++ b/Bloxstrap/Integrations/ReShade.cs @@ -318,13 +318,15 @@ namespace Bloxstrap.Integrations if (shaderSearchPaths.Contains(name)) { string searchPath = GetSearchPath("Shaders", name); - data["GENERAL"]["EffectSearchPaths"] = shaderSearchPaths.Remove(shaderSearchPaths.IndexOf(searchPath), searchPath.Length); + if (shaderSearchPaths.Contains(searchPath)) + data["GENERAL"]["EffectSearchPaths"] = shaderSearchPaths.Remove(shaderSearchPaths.IndexOf(searchPath), searchPath.Length); } if (textureSearchPaths.Contains(name)) { string searchPath = GetSearchPath("Textures", name); - data["GENERAL"]["TextureSearchPaths"] = textureSearchPaths.Remove(textureSearchPaths.IndexOf(searchPath), searchPath.Length); + if (textureSearchPaths.Contains(searchPath)) + data["GENERAL"]["TextureSearchPaths"] = textureSearchPaths.Remove(textureSearchPaths.IndexOf(searchPath), searchPath.Length); } parser.WriteFile(ConfigLocation, data); @@ -381,7 +383,7 @@ namespace Bloxstrap.Integrations if (!App.Settings.Prop.UseReShadeExtraviPresets && !string.IsNullOrEmpty(App.State.Prop.ExtraviReShadePresetsVersion)) { - if (Utilities.GetProcessCount("RobloxPlayerBeta") > 0) + if (Utilities.CheckIfRobloxRunning()) return; UninstallExtraviPresets(); @@ -392,7 +394,7 @@ namespace Bloxstrap.Integrations if (!App.Settings.Prop.UseReShade) { - if (Utilities.GetProcessCount("RobloxPlayerBeta") > 0) + if (Utilities.CheckIfRobloxRunning()) return; App.Logger.WriteLine("[ReShade::CheckModifications] ReShade is not enabled");