Merge pull request #199 from danoli3/macOS_fix

Fix macOS Runtime Platform determination failing
This commit is contained in:
Garry Newman 2018-11-30 11:10:43 +00:00 committed by GitHub
commit 6c6c8dc696
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 14 deletions

View File

@ -23,7 +23,7 @@ public static void ForUnity( string platform )
if ( platform == "OSXEditor" || platform == "OSXPlayer" || platform == "OSXDashboardPlayer" ) if ( platform == "OSXEditor" || platform == "OSXPlayer" || platform == "OSXDashboardPlayer" )
{ {
ForcePlatform( OperatingSystem.Osx, IntPtr.Size == 4 ? Architecture.x86 : Architecture.x64 ); ForcePlatform( OperatingSystem.macOS, IntPtr.Size == 4 ? Architecture.x86 : Architecture.x64 );
} }
if ( platform == "LinuxPlayer" || platform == "LinuxEditor" ) if ( platform == "LinuxPlayer" || platform == "LinuxEditor" )

View File

@ -1,4 +1,5 @@
using System; using System;
using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Facepunch.Steamworks namespace Facepunch.Steamworks
@ -8,7 +9,7 @@ public enum OperatingSystem
Unset, Unset,
Windows, Windows,
Linux, Linux,
Osx, macOS,
} }
public enum Architecture public enum Architecture
@ -26,6 +27,24 @@ internal static partial class Platform
private static Facepunch.Steamworks.OperatingSystem _os; private static Facepunch.Steamworks.OperatingSystem _os;
private static Facepunch.Steamworks.Architecture _arch; private static Facepunch.Steamworks.Architecture _arch;
public static Facepunch.Steamworks.OperatingSystem RunningPlatform()
{
switch (Environment.OSVersion.Platform)
{
case PlatformID.Unix:
// macOS sometimes reports to .NET as Unix. Fix is to check against macOS root folders
if (Directory.Exists("/Applications") && Directory.Exists("/System") && Directory.Exists("/Users") && Directory.Exists("/Volumes"))
return Facepunch.Steamworks.OperatingSystem.macOS;
else
return Facepunch.Steamworks.OperatingSystem.Linux;
case PlatformID.MacOSX:
return Facepunch.Steamworks.OperatingSystem.macOS;
default:
return Facepunch.Steamworks.OperatingSystem.Windows;
}
}
internal static Facepunch.Steamworks.OperatingSystem Os internal static Facepunch.Steamworks.OperatingSystem Os
{ {
get get
@ -38,17 +57,8 @@ internal static Facepunch.Steamworks.OperatingSystem Os
_os = Facepunch.Steamworks.OperatingSystem.Windows; _os = Facepunch.Steamworks.OperatingSystem.Windows;
#if !NET_CORE #if !NET_CORE
// // Fixed Bet
// These checks aren't so accurate on older versions of mono _os = RunningPlatform();
//
if ( Environment.OSVersion.Platform == PlatformID.MacOSX ) _os = Facepunch.Steamworks.OperatingSystem.Osx;
if ( Environment.OSVersion.Platform == PlatformID.Unix ) _os = Facepunch.Steamworks.OperatingSystem.Linux;
//
// Edging our bets
//
if ( Environment.OSVersion.VersionString.ToLower().Contains( "unix" ) ) _os = Facepunch.Steamworks.OperatingSystem.Linux;
if ( Environment.OSVersion.VersionString.ToLower().Contains( "osx" ) ) _os = Facepunch.Steamworks.OperatingSystem.Osx;
#endif #endif
} }
@ -92,7 +102,7 @@ internal static Facepunch.Steamworks.Architecture Arch
public static bool IsWindows32 { get { return Arch == Facepunch.Steamworks.Architecture.x86 && IsWindows; } } public static bool IsWindows32 { get { return Arch == Facepunch.Steamworks.Architecture.x86 && IsWindows; } }
public static bool IsLinux64 { get { return Arch == Facepunch.Steamworks.Architecture.x64 && Os == Facepunch.Steamworks.OperatingSystem.Linux; } } public static bool IsLinux64 { get { return Arch == Facepunch.Steamworks.Architecture.x64 && Os == Facepunch.Steamworks.OperatingSystem.Linux; } }
public static bool IsLinux32 { get { return Arch == Facepunch.Steamworks.Architecture.x86 && Os == Facepunch.Steamworks.OperatingSystem.Linux; } } public static bool IsLinux32 { get { return Arch == Facepunch.Steamworks.Architecture.x86 && Os == Facepunch.Steamworks.OperatingSystem.Linux; } }
public static bool IsOsx { get { return Os == Facepunch.Steamworks.OperatingSystem.Osx; } } public static bool IsOsx { get { return Os == Facepunch.Steamworks.OperatingSystem.macOS; } }
/// <summary> /// <summary>