tModLoader v0.11.8.9
A mod to make and play Terraria mods
FrameworkVersion.cs
Go to the documentation of this file.
1using Microsoft.Win32;
2using ReLogic.OS;
3using System;
4using System.Reflection;
5
6namespace Terraria.ModLoader
7{
8 public enum Framework
9 {
11 Mono,
13 }
14
15 public static class FrameworkVersion
16 {
17 public static readonly Framework Framework;
18 public static readonly Version Version;
19
21 var monoRuntimeType = Type.GetType("Mono.Runtime");
22 if (monoRuntimeType != null) {
23 string displayName = (string)monoRuntimeType.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, null);
24 Framework = Framework.Mono;
25 Version = new Version(displayName.Substring(0, displayName.IndexOf(' ')));
26 return;
27 }
28
29 if (!Platform.IsWindows)
30 Framework = Framework.Unknown;
31
32 Framework = Framework.NetFramework;
33
34 const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
35 using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
36 if (ndpKey != null && ndpKey.GetValue("Release") is int releaseKey)
37 Version = CheckFor45PlusVersion(releaseKey);
38
39 if (Version == null)
40 Version = new Version(4, 0);
41 }
42
43 // Checking the version using >= will enable forward compatibility.
44 private static Version CheckFor45PlusVersion(int releaseKey) {
45 if (releaseKey >= 528040)
46 return new Version("4.8");
47 if (releaseKey >= 461808)
48 return new Version("4.7.2");
49 if (releaseKey >= 461308)
50 return new Version("4.7.1");
51 if (releaseKey >= 460798)
52 return new Version("4.7");
53 if (releaseKey >= 394802)
54 return new Version("4.6.2");
55 if (releaseKey >= 394254)
56 return new Version("4.6.1");
57 if (releaseKey >= 393295)
58 return new Version("4.6");
59 if (releaseKey >= 379893)
60 return new Version("4.5.2");
61 if (releaseKey >= 378675)
62 return new Version("4.5.1");
63 if (releaseKey >= 378389)
64 return new Version("4.5");
65
66 throw new Exception("No 4.5 or later version detected");
67 }
68 }
69}
System.Version Version
Definition: ModLoader.cs:21
static Version CheckFor45PlusVersion(int releaseKey)
static readonly Framework Framework