forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOSHelper.cs
More file actions
81 lines (76 loc) · 2.04 KB
/
Copy pathOSHelper.cs
File metadata and controls
81 lines (76 loc) · 2.04 KB
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
using System;
using System.Runtime.InteropServices;
namespace PluginCore
{
public static class OSHelper
{
public static readonly APIUtils API;
static OSHelper()
{
switch (Platform)
{
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
API = new WinAPI();
break;
case PlatformID.MacOSX:
API = new MacAPI();
break;
case PlatformID.Unix:
API = new LinuxAPI();
break;
default: throw new Exception(Environment.OSVersion.ToString());
}
}
// Summary:
// Gets a System.PlatformID enumeration value that identifies the operating
// system platform.
//
// Returns:
// One of the System.PlatformID values.
public static PlatformID Platform
{
get
{
PlatformID id = Environment.OSVersion.Platform;
switch (id)
{
case PlatformID.Unix: return IsRunningOnMac() ? PlatformID.MacOSX : PlatformID.Unix;
default: return id;
}
}
}
[DllImport("libc")]
static extern int uname(IntPtr buf);
// Mono returns PlatformID.Unix for MacOSX so we should test platform by other ways
// "Notice that as of Mono 2.2 the version returned on MacOS X is still 4 for legacy reasons,
// too much code was written between the time that the MacOSX value was introduced and the
// time that we wrote this text which has lead to a lot of user code in the wild to not cope with
// the newly introduced value."
// http://www.mono-project.com/docs/faq/technical/
public static bool IsRunningOnMac()
{
IntPtr buf = IntPtr.Zero;
try
{
buf = Marshal.AllocHGlobal(8192);
if (uname(buf) == 0)
{
string os = Marshal.PtrToStringAnsi(buf);
return os.Contains("Darwin");
}
}
catch
{
// don't do anything
}
finally
{
if (buf != IntPtr.Zero) Marshal.FreeHGlobal(buf);
}
return false;
}
}
}