From 73b149779dec6cb288c2a7adc4fd6ee0b9d64348 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Mon, 28 Aug 2023 11:05:00 -0400 Subject: [PATCH] fix version check not handling preview versions --- .../PreChecks/NetCore6PreCheck.cs | 31 ++++++++++--------- .../PreChecks/NetFramework472PreCheck.cs | 4 +-- SPTInstaller/SPTInstaller.csproj | 4 +-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/SPTInstaller/Installer Tasks/PreChecks/NetCore6PreCheck.cs b/SPTInstaller/Installer Tasks/PreChecks/NetCore6PreCheck.cs index 8afb81f..851ca69 100644 --- a/SPTInstaller/Installer Tasks/PreChecks/NetCore6PreCheck.cs +++ b/SPTInstaller/Installer Tasks/PreChecks/NetCore6PreCheck.cs @@ -1,5 +1,7 @@ -using SPTInstaller.Models; +using Serilog; +using SPTInstaller.Models; using System.Diagnostics; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace SPTInstaller.Installer_Tasks.PreChecks; @@ -44,7 +46,7 @@ public class NetCore6PreCheck : PreCheckBase } catch (Exception ex) { - // TODO: logging + Log.Error(ex, $"PreCheck::{Name}::Exception"); return PreCheckResult.FromException(ex); } @@ -52,20 +54,21 @@ public class NetCore6PreCheck : PreCheckBase foreach (var lineVersion in output) { - if (lineVersion.StartsWith("Microsoft.WindowsDesktop.App") && lineVersion.Split(" ").Length > 1) + 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) { - string stringVerion = lineVersion.Split(" ")[1]; - - var foundVersion = new Version(stringVerion); - - // waffle: not fully sure if we should only check for 6.x.x versions or if higher major versions are ok - 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.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); diff --git a/SPTInstaller/Installer Tasks/PreChecks/NetFramework472PreCheck.cs b/SPTInstaller/Installer Tasks/PreChecks/NetFramework472PreCheck.cs index 37bd4f2..e0c9b8f 100644 --- a/SPTInstaller/Installer Tasks/PreChecks/NetFramework472PreCheck.cs +++ b/SPTInstaller/Installer Tasks/PreChecks/NetFramework472PreCheck.cs @@ -1,4 +1,5 @@ using Microsoft.Win32; +using Serilog; using SPTInstaller.Models; using System.Diagnostics; using System.Threading.Tasks; @@ -55,8 +56,7 @@ public class NetFramework472PreCheck : PreCheckBase } catch (Exception ex) { - // TODO: log exceptions - + Log.Error(ex, $"PreCheck::{Name}::Exception"); return PreCheckResult.FromException(ex); } } diff --git a/SPTInstaller/SPTInstaller.csproj b/SPTInstaller/SPTInstaller.csproj index cf67dc2..3c33310 100644 --- a/SPTInstaller/SPTInstaller.csproj +++ b/SPTInstaller/SPTInstaller.csproj @@ -9,8 +9,8 @@ icon.ico Assets\icon.ico Debug;Release;TEST - 2.10 - 2.10 + 2.11 + 2.11