56 lines
1.5 KiB
C#
Raw Normal View History

2023-05-11 23:11:39 -04:00
using SPTInstaller.Models;
using System.Diagnostics;
using System.Threading.Tasks;
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
public override async Task<bool> CheckOperation()
{
var minRequiredVersion = new Version("6.0.0");
string[] output;
2023-05-11 23:11:39 -04:00
try
{
var proc = Process.Start(new ProcessStartInfo()
2023-05-11 23:11:39 -04:00
{
FileName = "dotnet",
Arguments = "--list-runtimes",
RedirectStandardOutput = true,
CreateNoWindow = true
});
2023-05-11 23:11:39 -04:00
proc.WaitForExit();
2023-05-11 23:11:39 -04:00
output = proc.StandardOutput.ReadToEnd().Split("\r\n");
}
catch (Exception ex)
{
// TODO: logging
return false;
}
2023-05-11 23:11:39 -04:00
foreach (var lineVersion in output)
{
if (lineVersion.StartsWith("Microsoft.WindowsDesktop.App") && lineVersion.Split(" ").Length > 1)
2023-05-11 23:11:39 -04:00
{
string stringVerion = lineVersion.Split(" ")[1];
2023-05-11 23:11:39 -04:00
var foundVersion = new Version(stringVerion);
2023-05-11 23:11:39 -04:00
// not fully sure if we should only check for 6.x.x versions or if higher major versions are ok -waffle
if (foundVersion >= minRequiredVersion)
{
return true;
2023-05-11 23:11:39 -04:00
}
}
}
return false;
2023-05-11 23:11:39 -04:00
}
}