From a54bee78e1847ae0b92ffc09e11fb7811898d75a Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Thu, 9 Nov 2023 10:32:52 -0500 Subject: [PATCH] add eft launcher closed precheck --- .../PreChecks/EftLauncherPreCheck.cs | 43 +++++++++++++++++++ SPTInstaller/Program.cs | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 SPTInstaller/Installer Tasks/PreChecks/EftLauncherPreCheck.cs diff --git a/SPTInstaller/Installer Tasks/PreChecks/EftLauncherPreCheck.cs b/SPTInstaller/Installer Tasks/PreChecks/EftLauncherPreCheck.cs new file mode 100644 index 0000000..f80a919 --- /dev/null +++ b/SPTInstaller/Installer Tasks/PreChecks/EftLauncherPreCheck.cs @@ -0,0 +1,43 @@ +using System.Diagnostics; +using System.Threading.Tasks; +using Serilog; +using SPTInstaller.Models; + +namespace SPTInstaller.Installer_Tasks.PreChecks; + +public class EftLauncherPreCheck : PreCheckBase +{ + public EftLauncherPreCheck() : base("EFT Launcher Closed", true) + { + } + + public async override Task CheckOperation() + { + var eftLauncherProcs = Process.GetProcessesByName("BsgLauncher"); + + return eftLauncherProcs.Length == 0 + ? PreCheckResult.FromSuccess("Eft launcher is closed") + : PreCheckResult.FromError("Eft launcher is open. Please close it to install SPT", + "Kill EFT Launcher Processes", + () => + { + var bsgLauncherProcs = Process.GetProcessesByName("BsgLauncher"); + + foreach (var proc in bsgLauncherProcs) + { + try + { + proc.Kill(); + proc.WaitForExit(); + Log.Information($"Killed Proc: {proc.ProcessName}#{proc.Id}"); + } + catch (Exception ex) + { + Log.Error(ex, $"Failed to kill proc: {proc.ProcessName}#{proc.Id}"); + } + } + + RequestReevaluation(); + }); + } +} \ No newline at end of file diff --git a/SPTInstaller/Program.cs b/SPTInstaller/Program.cs index 8b99ec6..2734524 100644 --- a/SPTInstaller/Program.cs +++ b/SPTInstaller/Program.cs @@ -34,8 +34,8 @@ internal class Program #if !TEST ServiceHelper.Register(); ServiceHelper.Register(); - ServiceHelper.Register(); + ServiceHelper.Register(); ServiceHelper.Register(); ServiceHelper.Register();