This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
forked from ryancheung/MonoGame.IMEHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrentPlatform.cs
104 lines (92 loc) · 2.96 KB
/
CurrentPlatform.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
#if !WINDOWSDX
using System.Runtime.InteropServices;
using System;
namespace MonoGame.IMEHelper
{
internal enum OS
{
Windows,
Linux,
MacOSX,
Unknown
}
internal static class CurrentPlatform
{
private static bool init = false;
private static OS os;
[DllImport ("libc")]
static extern int uname (IntPtr buf);
private static void Init()
{
if (!init)
{
PlatformID pid = Environment.OSVersion.Platform;
switch (pid)
{
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
os = OS.Windows;
break;
case PlatformID.MacOSX:
os = OS.MacOSX;
break;
case PlatformID.Unix:
// Mac can return a value of Unix sometimes, We need to double check it.
IntPtr buf = IntPtr.Zero;
try
{
buf = Marshal.AllocHGlobal (8192);
if (uname (buf) == 0) {
string sos = Marshal.PtrToStringAnsi (buf);
if (sos == "Darwin")
{
os = OS.MacOSX;
return;
}
}
} catch {
} finally {
if (buf != IntPtr.Zero)
Marshal.FreeHGlobal (buf);
}
os = OS.Linux;
break;
default:
os = OS.Unknown;
break;
}
init = true;
}
}
public static OS OS
{
get
{
Init();
return os;
}
}
public static string Rid
{
get
{
if (CurrentPlatform.OS == OS.Windows && Environment.Is64BitProcess)
return "win-x64";
else if (CurrentPlatform.OS == OS.Windows && !Environment.Is64BitProcess)
return "win-x86";
else if (CurrentPlatform.OS == OS.Linux)
return "linux-x64";
else if (CurrentPlatform.OS == OS.MacOSX)
return "osx";
else
return "unknown";
}
}
}
}
#endif