From 37238969fb79e6d05e025b28b57bd51712fe03c2 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 18 Dec 2010 01:24:15 +0100 Subject: [PATCH] Cleanup platform detection some more --- SparkleShare/SparkleShare.cs | 50 ++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/SparkleShare/SparkleShare.cs b/SparkleShare/SparkleShare.cs index d5e7fc9b..9bf5bce5 100644 --- a/SparkleShare/SparkleShare.cs +++ b/SparkleShare/SparkleShare.cs @@ -85,7 +85,7 @@ namespace SparkleShare { ShowHelp (p); - switch (SparkleShare.Platform ()) { + switch (SparkleShare.Platform) { case PlatformID.Unix: SetProcessName ("sparkleshare"); @@ -180,30 +180,36 @@ namespace SparkleShare { // Strange magic needed by Platform () [DllImport ("libc")] static extern int uname (IntPtr buf); - - - static PlatformID Platform () { - - IntPtr buf = IntPtr.Zero; - - try { - - buf = Marshal.AllocHGlobal (8192); - - if (uname (buf) == 0 && Marshal.PtrToStringAnsi (buf) == "Darwin") - return PlatformID.MacOSX; - - } catch { - - } finally { - - if (buf != IntPtr.Zero) - Marshal.FreeHGlobal (buf); + + // This fixes the PlatformID enumeration for MacOSX in Environment.OSVersion.Platform, + // which is intentionally broken in Mono for hystorical reasons + static PlatformID Platform { + + get { + + IntPtr buf = IntPtr.Zero; + + try { + + buf = Marshal.AllocHGlobal (8192); + + if (uname (buf) == 0 && Marshal.PtrToStringAnsi (buf) == "Darwin") + return PlatformID.MacOSX; + + } catch { + + } finally { + + if (buf != IntPtr.Zero) + Marshal.FreeHGlobal (buf); + + } + + return Environment.OSVersion.Platform; + } - return Environment.OSVersion.Platform; - } }