/SparkleLib/SparkleBackend.cs

http://github.com/hbons/SparkleShare · C# · 60 lines · 30 code · 13 blank · 17 comment · 6 complexity · 73460755ff8f7de6535fd83d6847b437 MD5 · raw file

  1. // SparkleShare, a collaboration and sharing tool.
  2. // Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as
  6. // published by the Free Software Foundation, either version 3 of the
  7. // License, or (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. using System;
  17. using System.Reflection;
  18. using System.Runtime.InteropServices;
  19. namespace SparkleLib {
  20. public static class SparkleBackend {
  21. public static string Version {
  22. get {
  23. string version = "" + Assembly.GetExecutingAssembly ().GetName ().Version;
  24. return version.Substring (0, version.Length - 2);
  25. }
  26. }
  27. // This fixes the PlatformID enumeration for MacOSX in Environment.OSVersion.Platform,
  28. // which is intentionally broken in Mono for historical reasons
  29. public static PlatformID Platform {
  30. get {
  31. IntPtr buf = IntPtr.Zero;
  32. try {
  33. buf = Marshal.AllocHGlobal (8192);
  34. if (uname (buf) == 0 && Marshal.PtrToStringAnsi (buf) == "Darwin")
  35. return PlatformID.MacOSX;
  36. } catch {
  37. } finally {
  38. if (buf != IntPtr.Zero)
  39. Marshal.FreeHGlobal (buf);
  40. }
  41. return Environment.OSVersion.Platform;
  42. }
  43. }
  44. [DllImport ("libc")]
  45. private static extern int uname (IntPtr buf);
  46. }
  47. }