74 lines
2.6 KiB
C#
Raw Normal View History

using Serilog;
using SPTInstaller.Models;
2023-05-11 23:11:39 -04:00
using System.Diagnostics;
using System.Text.RegularExpressions;
2023-05-11 23:11:39 -04:00
using System.Threading.Tasks;
2023-11-22 09:32:18 -05:00
using SPTInstaller.Helpers;
2023-05-11 23:11:39 -04:00
namespace SPTInstaller.Installer_Tasks.PreChecks;
public class NetCore6PreCheck : PreCheckBase
2023-05-11 23:11:39 -04:00
{
public NetCore6PreCheck() : base(".Net Core 6 Desktop Runtime", false)
2023-05-11 23:11:39 -04:00
{
}
2023-05-11 23:11:39 -04:00
2023-07-29 14:26:55 -04:00
public override async Task<PreCheckResult> CheckOperation()
{
var minRequiredVersion = new Version("6.0.0");
string[] output;
2023-05-11 23:11:39 -04:00
2023-07-29 14:26:55 -04:00
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
{
2023-11-22 09:32:18 -05:00
var result = ProcessHelper.RunAndReadProcessOutputs("dotnet", "--list-runtimes");
2023-05-11 23:11:39 -04:00
2023-11-22 09:32:18 -05:00
if (!result.Succeeded)
{
return PreCheckResult.FromError(result.Message);
}
2023-05-11 23:11:39 -04:00
2023-11-22 09:32:18 -05:00
output = result.StdOut.Split("\r\n");
}
catch (Exception ex)
{
Log.Error(ex, $"PreCheck::{Name}::Exception");
2023-07-29 14:26:55 -04:00
return PreCheckResult.FromException(ex);
}
2023-05-11 23:11:39 -04:00
2023-07-29 14:26:55 -04:00
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;
2023-05-11 23:11:39 -04:00
var stringVersion = regex.Groups[1].Value;
2023-05-11 23:11:39 -04:00
var foundVersion = new Version(stringVersion);
2023-07-29 14:26:55 -04:00
if (foundVersion >= minRequiredVersion)
{
return PreCheckResult.FromSuccess($".Net Core {minRequiredVersion} Desktop Runtime or higher is installed.\n\nInstalled Version: {foundVersion}");
2023-05-11 23:11:39 -04:00
}
highestFoundVersion = foundVersion > highestFoundVersion ? foundVersion : highestFoundVersion;
2023-05-11 23:11:39 -04:00
}
2023-07-29 14:26:55 -04:00
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);
2023-05-11 23:11:39 -04:00
}
}