OS X and linux can be treated separately

This commit is contained in:
Mark McDowall
2014-03-08 21:28:40 -08:00
parent 9d74693bb7
commit 8885bbb60f
22 changed files with 101 additions and 50 deletions
+64 -17
View File
@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
namespace NzbDrone.Common.EnvironmentInfo
{
@@ -7,34 +8,80 @@ namespace NzbDrone.Common.EnvironmentInfo
static OsInfo()
{
Version = Environment.OSVersion.Version;
IsMono = Type.GetType("Mono.Runtime") != null;
var platform = (int)Environment.OSVersion.Platform;
int platform = (int)Environment.OSVersion.Platform;
IsLinux = (platform == 4) || (platform == 6) || (platform == 128);
Version = Environment.OSVersion.Version;
IsMonoRuntime = Type.GetType("Mono.Runtime") != null;
IsMono = (platform == 4) || (platform == 6) || (platform == 128);
IsOsx = IsRunningOnMac();
IsLinux = IsMono && !IsOsx;
IsWindows = !IsMono;
FirstDayOfWeek = DateTime.Today.GetFirstDayOfWeek().DayOfWeek;
if (!IsMono)
{
Os = Os.Windows;
}
else
{
Os = IsOsx ? Os.Osx : Os.Linux;
}
}
public static Version Version { get; private set; }
public static bool IsMonoRuntime { get; private set; }
public static bool IsMono { get; private set; }
public static bool IsLinux { get; private set; }
public static bool IsOsx { get; private set; }
public static bool IsWindows { get; private set; }
public static Os Os { get; private set; }
public static DayOfWeek FirstDayOfWeek { get; private set; }
public static bool IsWindows
{
get
{
return !IsLinux;
}
}
//Borrowed from: https://github.com/jpobst/Pinta/blob/master/Pinta.Core/Managers/SystemManager.cs
//From Managed.Windows.Forms/XplatUI
[DllImport("libc")]
static extern int uname(IntPtr buf);
public static DayOfWeek FirstDayOfWeek
static bool IsRunningOnMac()
{
get
var buf = IntPtr.Zero;
try
{
return DateTime.Today.GetFirstDayOfWeek().DayOfWeek;
buf = Marshal.AllocHGlobal(8192);
// This is a hacktastic way of getting sysname from uname ()
if (uname(buf) == 0)
{
var os = Marshal.PtrToStringAnsi(buf);
if (os == "Darwin")
{
return true;
}
}
}
catch
{
}
finally
{
if (buf != IntPtr.Zero)
{
Marshal.FreeHGlobal(buf);
}
}
return false;
}
}
public enum Os
{
Windows,
Linux,
Osx
}
}