add eft launcher closed precheck

This commit is contained in:
IsWaffle 2023-11-09 10:32:52 -05:00
parent ad37a15a92
commit a54bee78e1
2 changed files with 44 additions and 1 deletions

View File

@ -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<PreCheckResult> 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();
});
}
}

View File

@ -34,8 +34,8 @@ internal class Program
#if !TEST
ServiceHelper.Register<PreCheckBase, NetFramework472PreCheck>();
ServiceHelper.Register<PreCheckBase, NetCore6PreCheck>();
ServiceHelper.Register<PreCheckBase, FreeSpacePreCheck>();
ServiceHelper.Register<PreCheckBase, EftLauncherPreCheck>();
ServiceHelper.Register<InstallerTaskBase, InitializationTask>();
ServiceHelper.Register<InstallerTaskBase, ReleaseCheckTask>();