Terraria ModLoader  0.11.6.2
A framework for Terraria mods
FrameworkVersion.cs
Go to the documentation of this file.
1 using Microsoft.Win32;
2 using ReLogic.OS;
3 using System;
4 using System.Reflection;
5 
6 namespace Terraria.ModLoader
7 {
8  public enum Framework
9  {
11  Mono,
12  Unknown
13  }
14 
15  public static class FrameworkVersion
16  {
17  public static readonly Framework Framework;
18  public static readonly Version Version;
19 
20  static FrameworkVersion() {
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 }
static readonly Framework Framework
static Version CheckFor45PlusVersion(int releaseKey)