From df3303d150a04cc4fb22c98a690be1bc7a8b9b57 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Sat, 23 Mar 2024 18:44:27 -0400 Subject: [PATCH] re-add net 6 precheck until 3.8.0 drops --- .../PreChecks/NetCore6PreCheck.cs | 74 +++++++++++++++++++ SPTInstaller/Program.cs | 1 + SPTInstaller/SPTInstaller.csproj | 4 +- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 SPTInstaller/Installer Tasks/PreChecks/NetCore6PreCheck.cs diff --git a/SPTInstaller/Installer Tasks/PreChecks/NetCore6PreCheck.cs b/SPTInstaller/Installer Tasks/PreChecks/NetCore6PreCheck.cs new file mode 100644 index 0000000..856d457 --- /dev/null +++ b/SPTInstaller/Installer Tasks/PreChecks/NetCore6PreCheck.cs @@ -0,0 +1,74 @@ +using Serilog; +using SPTInstaller.Models; +using System.Diagnostics; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using SPTInstaller.Helpers; + +namespace SPTInstaller.Installer_Tasks.PreChecks; + +public class NetCore6PreCheck : PreCheckBase +{ + public NetCore6PreCheck() : base(".Net Core 6 Desktop Runtime", true) + { + } + + public override async Task CheckOperation() + { + var minRequiredVersion = new Version("6.0.0"); + string[] output; + + var failedButtonText = "Download .Net Core 6 Desktop Runtime"; + + var failedButtonAction = () => + { + Process.Start(new ProcessStartInfo + { + FileName = "cmd.exe", + UseShellExecute = true, + WindowStyle = ProcessWindowStyle.Hidden, + ArgumentList = { "/C", "start", "https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-6.0.4-windows-x64-installer" } + }); + }; + + try + { + var result = ProcessHelper.RunAndReadProcessOutputs("dotnet", "--list-runtimes"); + + if (!result.Succeeded) + { + return PreCheckResult.FromError(result.Message + "\n\nYou most likely don't have .net 6 installed", failedButtonText, failedButtonAction); + } + + output = result.StdOut.Split("\r\n"); + } + catch (Exception ex) + { + Log.Error(ex, $"PreCheck::{Name}::Exception"); + return PreCheckResult.FromException(ex); + } + + var highestFoundVersion = new Version("0.0.0"); + + foreach (var lineVersion in output) + { + var regex = Regex.Match(lineVersion, @"Microsoft.WindowsDesktop.App (\d\.\d\.\d)"); + + if (!regex.Success || regex.Groups.Count < 1) + continue; + + var stringVersion = regex.Groups[1].Value; + + var foundVersion = new Version(stringVersion); + + if (foundVersion >= minRequiredVersion) + { + return PreCheckResult.FromSuccess($".Net Core {minRequiredVersion} Desktop Runtime or higher is installed.\n\nInstalled Version: {foundVersion}"); + } + + highestFoundVersion = foundVersion > highestFoundVersion ? foundVersion : highestFoundVersion; + } + + return PreCheckResult.FromError($".Net Core Desktop Runtime version {minRequiredVersion} or higher is required.\n\nHighest Version Found: {(highestFoundVersion > new Version("0.0.0") ? highestFoundVersion : "Not Found")}\n\nThis is required to play SPT, but you can install it later if and shouldn't affect the SPT install process.", failedButtonText, failedButtonAction); + } +} \ No newline at end of file diff --git a/SPTInstaller/Program.cs b/SPTInstaller/Program.cs index c1bb4d9..5441b16 100644 --- a/SPTInstaller/Program.cs +++ b/SPTInstaller/Program.cs @@ -44,6 +44,7 @@ internal class Program #if !TEST ServiceHelper.Register(); + ServiceHelper.Register(); ServiceHelper.Register(); ServiceHelper.Register(); ServiceHelper.Register(); diff --git a/SPTInstaller/SPTInstaller.csproj b/SPTInstaller/SPTInstaller.csproj index 92cd3ea..4a702e0 100644 --- a/SPTInstaller/SPTInstaller.csproj +++ b/SPTInstaller/SPTInstaller.csproj @@ -9,8 +9,8 @@ icon.ico Assets\icon.ico Debug;Release;TEST - 2.43 - 2.43 + 2.44 + 2.44 SPT-AKI