Coding standard

This commit is contained in:
Latif Khalifa
2013-12-03 17:21:43 +01:00
parent 41f85e1b59
commit 151267655a
3 changed files with 112 additions and 94 deletions

View File

@@ -3,39 +3,45 @@ using System.IO;
namespace GridProxyGUI
{
public static class PlatformDetection
{
public readonly static bool IsWindows;
public readonly static bool IsMac;
static PlatformDetection ()
{
IsWindows = Path.DirectorySeparatorChar == '\\';
IsMac = !IsWindows && IsRunningOnMac();
}
//From Managed.Windows.Forms/XplatUI
static bool IsRunningOnMac ()
{
IntPtr buf = IntPtr.Zero;
try {
buf = System.Runtime.InteropServices.Marshal.AllocHGlobal (8192);
// This is a hacktastic way of getting sysname from uname ()
if (uname (buf) == 0) {
string os = System.Runtime.InteropServices.Marshal.PtrToStringAnsi (buf);
if (os == "Darwin")
return true;
}
} catch {
} finally {
if (buf != IntPtr.Zero)
System.Runtime.InteropServices.Marshal.FreeHGlobal (buf);
}
return false;
}
[System.Runtime.InteropServices.DllImport ("libc")]
static extern int uname (IntPtr buf);
}
public static class PlatformDetection
{
public readonly static bool IsWindows;
public readonly static bool IsMac;
static PlatformDetection()
{
IsWindows = Path.DirectorySeparatorChar == '\\';
IsMac = !IsWindows && IsRunningOnMac();
}
//From Managed.Windows.Forms/XplatUI
static bool IsRunningOnMac()
{
IntPtr buf = IntPtr.Zero;
try
{
buf = System.Runtime.InteropServices.Marshal.AllocHGlobal(8192);
// This is a hacktastic way of getting sysname from uname ()
if (uname(buf) == 0)
{
string os = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(buf);
if (os == "Darwin")
return true;
}
}
catch
{
}
finally
{
if (buf != IntPtr.Zero)
System.Runtime.InteropServices.Marshal.FreeHGlobal(buf);
}
return false;
}
[System.Runtime.InteropServices.DllImport("libc")]
static extern int uname(IntPtr buf);
}
}