2023-05-11 23:11:39 -04:00
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
using SPTInstaller.Models;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
namespace SPTInstaller.Installer_Tasks.PreChecks;
|
|
|
|
|
|
|
|
|
|
public class NetFramework472PreCheck : PreCheckBase
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public NetFramework472PreCheck() : base(".Net Framework 4.7.2", false)
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public override async Task<bool> CheckOperation()
|
|
|
|
|
{
|
|
|
|
|
try
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var minRequiredVersion = new Version("4.7.2");
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full");
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
if (key == null)
|
|
|
|
|
{
|
2023-05-11 23:11:39 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
|
|
|
|
|
var value = key.GetValue("Version");
|
|
|
|
|
|
|
|
|
|
if (value != null && value is string versionString)
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var installedVersion = new Version(versionString);
|
2023-05-11 23:11:39 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
return installedVersion > minRequiredVersion;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
// TODO: log exceptions
|
|
|
|
|
|
|
|
|
|
return false;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-12 09:19:33 +02:00
|
|
|
|
}
|