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 System.Text;
namespace SparkleShare {
// This is SparkleShare!
@ -83,16 +84,16 @@ namespace SparkleShare {
if (show_help)
ShowHelp (p);
switch (Environment.OSVersion.Platform) {
switch (SparkleShare.Platform ()) {
case PlatformID.Unix:
SetProcessName ("sparkleshare");
Controller = new SparkleLinController ();
//Controller = new SparkleLinController ();
break;
case PlatformID.MacOSX:
//Controller = new SparkleMacController ();
Controller = new SparkleMacController ();
break;
case PlatformID.Win32NT:
@ -148,6 +149,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'
private static void SetProcessName (string name)
@ -169,12 +175,37 @@ namespace SparkleShare {
}
}
// Strange magic needed by SetProcessName
[DllImport ("libc")]
private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
// 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);
}
return Environment.OSVersion.Platform;
}
}
}