forked from lllsondowlll/botw-trainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetDotNetVersion.cs
77 lines (70 loc) · 2.34 KB
/
GetDotNetVersion.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Microsoft.Win32;
using System;
namespace BotwTrainer
{
public class GetDotNetVersion
{
public NetVersion Get45PlusFromRegistry()
{
var netVersion = new NetVersion();
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
{
if (ndpKey != null && ndpKey.GetValue("Release") != null)
{
netVersion.Details = ".NET Framework Version: " + CheckFor45PlusVersion((int)ndpKey.GetValue("Release"));
netVersion.Version = CheckFor45PlusVersion((int)ndpKey.GetValue("Release"));
netVersion.ReleaseKey = (int)ndpKey.GetValue("Release");
}
else
{
netVersion.Details = ".NET Framework Version 4.5 or later is not detected.";
netVersion.Version = null;
netVersion.ReleaseKey = 0;
}
}
return netVersion;
}
// Checking the version using >= will enable forward compatibility.
private static string CheckFor45PlusVersion(int releaseKey)
{
if (releaseKey >= 460798)
{
return "4.7 or later";
}
if (releaseKey >= 394802)
{
return "4.6.2";
}
if (releaseKey >= 394254)
{
return "4.6.1";
}
if (releaseKey >= 393295)
{
return "4.6";
}
if ((releaseKey >= 379893))
{
return "4.5.2";
}
if ((releaseKey >= 378675))
{
return "4.5.1";
}
if ((releaseKey >= 378389))
{
return "4.5";
}
// This code should never execute. A non-null release key should mean
// that 4.5 or later is installed.
return "No 4.5 or later version detected";
}
}
public class NetVersion
{
public string Version { get; set; }
public string Details { get; set; }
public int ReleaseKey { get; set; }
}
}