Philipp Heenemann
a8b91f4ee6
Updated the existing C# code into a more modern, imperative and top-level statements style. This involves shortening the code by removing unnecessary parts like additional brackets and explicit namespace declarations. It's done to improve clarity and readability.
44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
using Microsoft.Win32;
|
|
using SPTInstaller.Models;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SPTInstaller.Installer_Tasks.PreChecks;
|
|
|
|
public class NetFramework472PreCheck : PreCheckBase
|
|
{
|
|
public NetFramework472PreCheck() : base(".Net Framework 4.7.2", false)
|
|
{
|
|
}
|
|
|
|
public override async Task<bool> CheckOperation()
|
|
{
|
|
try
|
|
{
|
|
var minRequiredVersion = new Version("4.7.2");
|
|
|
|
var key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full");
|
|
|
|
if (key == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var value = key.GetValue("Version");
|
|
|
|
if (value != null && value is string versionString)
|
|
{
|
|
var installedVersion = new Version(versionString);
|
|
|
|
return installedVersion > minRequiredVersion;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// TODO: log exceptions
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |