Add proper OS detection
This commit is contained in:
parent
446de29f3f
commit
51a7d0195c
|
@ -25,6 +25,7 @@ using SparkleLib;
|
|||
using SparkleLib.Options;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace SparkleShare {
|
||||
|
||||
// This is SparkleShare!
|
||||
|
@ -84,15 +85,15 @@ namespace SparkleShare {
|
|||
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:
|
||||
|
@ -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'
|
||||
private static void SetProcessName (string name)
|
||||
{
|
||||
|
@ -171,9 +177,34 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
// Strange magic needed by SetProcessName
|
||||
// Strange magic needed by Platform ()
|
||||
[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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue