Move OS detection code to the backend
This commit is contained in:
parent
6a89bfe961
commit
b3fb85c305
|
@ -17,6 +17,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SparkleLib {
|
||||
|
||||
|
@ -52,6 +53,34 @@ namespace SparkleLib {
|
|||
{
|
||||
return (path.Length > 0);
|
||||
}
|
||||
|
||||
|
||||
// Strange magic needed by Platform ()
|
||||
[DllImport ("libc")]
|
||||
static extern int uname (IntPtr buf);
|
||||
|
||||
|
||||
// This fixes the PlatformID enumeration for MacOSX in Environment.OSVersion.Platform,
|
||||
// which is intentionally broken in Mono for historical reasons
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
29
SparkleLib/SparklePlatform.cs
Normal file
29
SparkleLib/SparklePlatform.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
// SparkleShare, a collaboration and sharing tool.
|
||||
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
||||
using Mono.Unix;
|
||||
|
||||
namespace SparkleLib {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -49,8 +49,8 @@ namespace SparkleShare {
|
|||
Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR);
|
||||
|
||||
// Don't allow running as root on Linux or Mac
|
||||
if ((SparkleShare.Platform == PlatformID.Unix ||
|
||||
SparkleShare.Platform == PlatformID.MacOSX) &&
|
||||
if ((SparkleBackend.Platform == PlatformID.Unix ||
|
||||
SparkleBackend.Platform == PlatformID.MacOSX) &&
|
||||
new UnixUserInfo (UnixEnvironment.UserName).UserId == 0) {
|
||||
|
||||
Console.WriteLine (_("Sorry, you can't run SparkleShare with these permissions."));
|
||||
|
@ -82,7 +82,7 @@ namespace SparkleShare {
|
|||
|
||||
// Load the right controller for the OS
|
||||
string controller_name = "Lin";
|
||||
switch (SparkleShare.Platform) {
|
||||
switch (SparkleBackend.Platform) {
|
||||
case PlatformID.Unix:
|
||||
SetProcessName ("sparkleshare");
|
||||
break;
|
||||
|
@ -158,33 +158,5 @@ namespace SparkleShare {
|
|||
Console.WriteLine ("SetProcessName: Entry point not found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Strange magic needed by Platform ()
|
||||
[DllImport ("libc")]
|
||||
static extern int uname (IntPtr buf);
|
||||
|
||||
|
||||
// This fixes the PlatformID enumeration for MacOSX in Environment.OSVersion.Platform,
|
||||
// which is intentionally broken in Mono for historical 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue