Fix the mac/unix/linux detection logic

This commit is contained in:
Matthew Leibowitz 2017-01-30 17:48:05 -05:00
Родитель 93b1f906ec
Коммит 076bcc9ff6
1 изменённых файлов: 28 добавлений и 1 удалений

Просмотреть файл

@ -18,10 +18,37 @@ namespace SkiaSharp.Tests
protected static bool IsUnix => IsLinux || IsMac;
protected static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
private static class MacPlatformDetector
{
internal static readonly Lazy<bool> IsMac = new Lazy<bool> (IsRunningOnMac);
[DllImport ("libc")]
static extern int uname (IntPtr buf);
static bool IsRunningOnMac ()
{
IntPtr buf = IntPtr.Zero;
try {
buf = Marshal.AllocHGlobal (8192);
// This is a hacktastic way of getting sysname from uname ()
if (uname (buf) == 0) {
string os = Marshal.PtrToStringAnsi (buf);
if (os == "Darwin")
return true;
}
} catch {
} finally {
if (buf != IntPtr.Zero)
Marshal.FreeHGlobal (buf);
}
return false;
}
}
protected const string PathToFonts = "fonts";
protected const string PathToImages = "images";
protected static bool IsMac => Environment.OSVersion.Platform == PlatformID.MacOSX;
protected static bool IsMac => MacPlatformDetector.IsMac.Value;
protected static bool IsUnix => Environment.OSVersion.Platform == PlatformID.Unix || IsMac;
protected static bool IsLinux => IsUnix && !IsMac;
protected static bool IsWindows => !IsUnix;