PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/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
17
18using System;
19using System.Reflection;
20using System.Runtime.InteropServices;
21
22namespace SparkleLib {
23
24    public static class SparkleBackend {
25
26        public static string Version {
27            get {
28                string version = "" + Assembly.GetExecutingAssembly ().GetName ().Version;
29                return version.Substring (0, version.Length - 2);
30            }
31        }
32
33
34        // This fixes the PlatformID enumeration for MacOSX in Environment.OSVersion.Platform,
35        // which is intentionally broken in Mono for historical reasons
36        public static PlatformID Platform {
37            get {
38                IntPtr buf = IntPtr.Zero;
39
40                try {
41                    buf = Marshal.AllocHGlobal (8192);
42
43                    if (uname (buf) == 0 && Marshal.PtrToStringAnsi (buf) == "Darwin")
44                        return PlatformID.MacOSX;
45
46                } catch {
47                } finally {
48                    if (buf != IntPtr.Zero)
49                        Marshal.FreeHGlobal (buf);
50                }
51
52                return Environment.OSVersion.Platform;
53            }
54        }
55
56
57        [DllImport ("libc")]
58        private static extern int uname (IntPtr buf);
59    }
60}