This repository was archived by the owner on Nov 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathRuntimeInfo.cs
50 lines (43 loc) · 1.54 KB
/
RuntimeInfo.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
using System;
using System.Diagnostics;
using System.IO;
namespace TrueCraft.Core
{
public static class RuntimeInfo
{
public static bool Is32Bit { get; private set; }
public static bool Is64Bit { get; private set; }
public static bool IsMono { get; private set; }
public static bool IsWindows { get; private set; }
public static bool IsUnix { get; private set; }
public static bool IsLinux { get; private set; }
public static bool IsMacOSX { get; private set; }
static RuntimeInfo()
{
IsMono = Type.GetType("Mono.Runtime") != null;
int p = (int)Environment.OSVersion.Platform;
IsUnix = (p == 4) || (p == 6) || (p == 128);
IsWindows = Path.DirectorySeparatorChar == '\\';
Is32Bit = IntPtr.Size == 4;
Is64Bit = IntPtr.Size == 8;
if (IsUnix)
{
Process uname = new Process();
uname.StartInfo.FileName = "uname";
uname.StartInfo.UseShellExecute = false;
uname.StartInfo.RedirectStandardOutput = true;
uname.Start();
string output = uname.StandardOutput.ReadToEnd();
uname.WaitForExit();
output = output.ToUpper().Replace("\n", "").Trim();
IsMacOSX = output == "DARWIN";
IsLinux = output == "LINUX";
}
else
{
IsMacOSX = false;
IsLinux = false;
}
}
}
}