Add proper OS detection

This commit is contained in:
Hylke Bons 2010-12-18 01:01:00 +01:00
parent 6a8ca90271
commit cd60a85825

View file

@ -25,6 +25,7 @@ using SparkleLib;
using SparkleLib.Options; using SparkleLib.Options;
using System.Text; using System.Text;
namespace SparkleShare { namespace SparkleShare {
// This is SparkleShare! // This is SparkleShare!
@ -84,15 +85,15 @@ namespace SparkleShare {
ShowHelp (p); ShowHelp (p);
switch (Environment.OSVersion.Platform) { switch (SparkleShare.Platform ()) {
case PlatformID.Unix: case PlatformID.Unix:
SetProcessName ("sparkleshare"); SetProcessName ("sparkleshare");
Controller = new SparkleLinController (); //Controller = new SparkleLinController ();
break; break;
case PlatformID.MacOSX: case PlatformID.MacOSX:
//Controller = new SparkleMacController (); Controller = new SparkleMacController ();
break; break;
case PlatformID.Win32NT: case PlatformID.Win32NT:
@ -149,6 +150,11 @@ namespace SparkleShare {
} }
// Strange magic needed by SetProcessName ()
[DllImport ("libc")]
private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
// Sets the Unix process name to 'sparkleshare' instead of 'mono' // Sets the Unix process name to 'sparkleshare' instead of 'mono'
private static void SetProcessName (string name) private static void SetProcessName (string name)
{ {
@ -171,9 +177,34 @@ namespace SparkleShare {
} }
// Strange magic needed by SetProcessName // Strange magic needed by Platform ()
[DllImport ("libc")] [DllImport ("libc")]
private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5); 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);
}
return Environment.OSVersion.Platform;
}
} }