From 719fbb898e03c1e89a5cd9159053a26ba7b01b42 Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Fri, 30 Aug 2024 00:51:58 +0100 Subject: [PATCH] Fix custom integration autoclosing not working --- Bloxstrap/Resources/Strings.Designer.cs | 11 +--- Bloxstrap/Resources/Strings.resx | 5 +- .../Settings/Pages/IntegrationsPage.xaml | 4 +- Bloxstrap/Watcher.cs | 51 ++++++++----------- 4 files changed, 26 insertions(+), 45 deletions(-) diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index b70ee99..28c8fc2 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -2528,15 +2528,6 @@ namespace Bloxstrap.Resources { } } - /// - /// Looks up a localized string similar to e.g. C:\Windows\System32\cmd.exe. - /// - public static string Menu_Integrations_Custom_AppLocation_Placeholder { - get { - return ResourceManager.GetString("Menu.Integrations.Custom.AppLocation.Placeholder", resourceCulture); - } - } - /// /// Looks up a localized string similar to Auto close when Roblox closes. /// @@ -2565,7 +2556,7 @@ namespace Bloxstrap.Resources { } /// - /// Looks up a localized string similar to e.g. /k echo Roblox is running!. + /// Looks up a localized string similar to Roblox is running!. /// public static string Menu_Integrations_Custom_LaunchArgs_Placeholder { get { diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index 301c5c9..6f57c25 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -727,9 +727,6 @@ Selecting 'No' will ignore this warning and continue installation. Application Location - - e.g. C:\Windows\System32\cmd.exe - Auto close when Roblox closes @@ -740,7 +737,7 @@ Selecting 'No' will ignore this warning and continue installation. Launch Arguments - e.g. /k echo Roblox is running! + Roblox is running! New Integration diff --git a/Bloxstrap/UI/Elements/Settings/Pages/IntegrationsPage.xaml b/Bloxstrap/UI/Elements/Settings/Pages/IntegrationsPage.xaml index ef3c0f0..bf8a959 100644 --- a/Bloxstrap/UI/Elements/Settings/Pages/IntegrationsPage.xaml +++ b/Bloxstrap/UI/Elements/Settings/Pages/IntegrationsPage.xaml @@ -95,11 +95,11 @@ - + - + diff --git a/Bloxstrap/Watcher.cs b/Bloxstrap/Watcher.cs index 652675e..9b14f88 100644 --- a/Bloxstrap/Watcher.cs +++ b/Bloxstrap/Watcher.cs @@ -1,6 +1,4 @@ using Bloxstrap.Integrations; -using System.CodeDom; -using System.Security.Permissions; namespace Bloxstrap { @@ -54,7 +52,7 @@ namespace Bloxstrap if (split.Length >= 2) { - foreach (string strPid in split[0].Split(';')) + foreach (string strPid in split[1].Split(',')) { if (int.TryParse(strPid, out int pid) && pid != 0) _autoclosePids.Add(pid); @@ -86,38 +84,33 @@ namespace Bloxstrap _notifyIcon = new(this); } - public void KillRobloxProcess() => KillProcess(_gameClientPid); + public void KillRobloxProcess() => CloseProcess(_gameClientPid, true); - public void KillProcess(int pid) + public void CloseProcess(int pid, bool force = false) { - using var process = Process.GetProcessById(pid); - - App.Logger.WriteLine("Watcher::KillProcess", $"Killing process '{process.ProcessName}' (PID {process.Id})"); - - if (process.HasExited) + const string LOG_IDENT = "Watcher::CloseProcess"; + try { - App.Logger.WriteLine("Watcher::KillProcess", $"PID {process.Id} has already exited"); - return; + using var process = Process.GetProcessById(pid); + + App.Logger.WriteLine(LOG_IDENT, $"Killing process '{process.ProcessName}' (pid={pid}, force={force})"); + + if (process.HasExited) + { + App.Logger.WriteLine(LOG_IDENT, $"PID {pid} has already exited"); + return; + } + + if (force) + process.Kill(); + else + process.CloseMainWindow(); } - - process.Kill(); - process.Close(); - } - - public void CloseProcess(int pid) - { - using var process = Process.GetProcessById(pid); - - App.Logger.WriteLine("Watcher::CloseProcess", $"Closing process '{process.ProcessName}' (PID {process.Id})"); - - if (process.HasExited) + catch (Exception ex) { - App.Logger.WriteLine("Watcher::CloseProcess", $"PID {process.Id} has already exited"); - return; + App.Logger.WriteLine(LOG_IDENT, $"PID {pid} could not be closed"); + App.Logger.WriteException(LOG_IDENT, ex); } - - process.CloseMainWindow(); - process.Close(); } public async Task Run()