diff --git a/SparkleLib/SparkleBackend.cs b/SparkleLib/SparkleBackend.cs index e41929bf..7b5898b9 100644 --- a/SparkleLib/SparkleBackend.cs +++ b/SparkleLib/SparkleBackend.cs @@ -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; + } + } } diff --git a/SparkleLib/SparklePlatform.cs b/SparkleLib/SparklePlatform.cs new file mode 100644 index 00000000..0601a7d0 --- /dev/null +++ b/SparkleLib/SparklePlatform.cs @@ -0,0 +1,29 @@ +// SparkleShare, a collaboration and sharing tool. +// Copyright (C) 2010 Hylke Bons +// +// 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 . + + +using System; +using System.IO; +using System.Collections.Generic; +using System.Xml; + +using Mono.Unix; + +namespace SparkleLib { + + + +} diff --git a/SparkleShare/SparkleShare.cs b/SparkleShare/SparkleShare.cs index 8a19f1dc..fed350a6 100644 --- a/SparkleShare/SparkleShare.cs +++ b/SparkleShare/SparkleShare.cs @@ -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; - } - } } }