forked from neophoenix236/INVedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatform.cs
56 lines (47 loc) · 1.1 KB
/
Platform.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
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace INVedit
{
public class Platform
{
#region Static members
static Platform()
{
if (IsWindows()) Current = Windows;
else if (IsMac()) Current = Mac;
else Current = Unix;
}
public static Platform Windows = new Platform("Windows");
public static Platform Unix = new Platform("Unix");
public static Platform Mac = new Platform("Mac");
public static Platform Current { get; private set; }
static bool IsWindows()
{
return (Path.DirectorySeparatorChar == '\\');
}
static bool IsMac()
{
IntPtr buf = IntPtr.Zero;
try {
buf = Marshal.AllocHGlobal(8192);
if (uname(buf) == 0)
if (Marshal.PtrToStringAnsi(buf) == "Darwin") return true;
} catch { }
finally { if (buf != IntPtr.Zero) Marshal.FreeHGlobal(buf); }
return false;
}
[DllImport("libc")]
static extern int uname(IntPtr buf);
#endregion
public string Name { get; private set; }
public Platform(string name)
{
Name = name;
}
public override string ToString()
{
return Name;
}
}
}