From 8a98c812c2c3179a3b884596de0572f9c421098d Mon Sep 17 00:00:00 2001 From: psychonic Date: Tue, 5 Jun 2012 18:44:39 -0400 Subject: [PATCH] Ditch P/Invoke for detecting OSX as it's a detected platform since .NET 3.5. --- DepotDownloader/CDRManager.cs | 6 ++--- DepotDownloader/Util.cs | 43 ----------------------------------- 2 files changed, 3 insertions(+), 46 deletions(-) diff --git a/DepotDownloader/CDRManager.cs b/DepotDownloader/CDRManager.cs index 8630cf58..8df5e5ab 100644 --- a/DepotDownloader/CDRManager.cs +++ b/DepotDownloader/CDRManager.cs @@ -230,7 +230,7 @@ namespace DepotDownloader if ( platform == PlatformID.Win32NT ) platformStr = "windows"; - else if ( Util.IsMacOSX() ) + else if ( platform == PlatformID.MacOSX ) platformStr = "macos"; foreach ( var blobField in appInfoBlob.FileSystems ) @@ -266,7 +266,7 @@ namespace DepotDownloader if (platform == PlatformID.Win32NT) platformSuffix = "-win32"; - else if (platform == PlatformID.Unix && !Util.IsMacOSX()) + else if (platform == PlatformID.Unix) platformSuffix = "-linux"; foreach (var blobField in serverAppInfoBlob.FileSystems) @@ -301,7 +301,7 @@ namespace DepotDownloader } else if ( platform == PlatformID.Win32NT ) appIDs.Add( 5 ); - else if ( platform == PlatformID.Unix && !Util.IsMacOSX() ) + else if ( platform == PlatformID.Unix) appIDs.Add( 4 ); // Half-Life Base Content diff --git a/DepotDownloader/Util.cs b/DepotDownloader/Util.cs index 9a787c7c..55732c55 100644 --- a/DepotDownloader/Util.cs +++ b/DepotDownloader/Util.cs @@ -11,49 +11,6 @@ namespace DepotDownloader { static class Util { - [DllImport( "libc" )] - static extern int uname( IntPtr buf ); - - static int _isMacOSX = -1; - - // Environment.OSVersion.Platform returns PlatformID.Unix under Mono on OS X - // Code adapted from Mono: mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUI.cs - public static bool IsMacOSX() - { - if ( _isMacOSX != -1 ) - return _isMacOSX == 1; - - IntPtr buf = IntPtr.Zero; - - try - { - // The size of the utsname struct varies from system to system, but this _seems_ more than enough - buf = Marshal.AllocHGlobal( 4096 ); - - if ( uname( buf ) == 0 ) - { - string sys = Marshal.PtrToStringAnsi( buf ); - if ( sys == "Darwin" ) - { - _isMacOSX = 1; - return true; - } - } - } - catch - { - // Do nothing? - } - finally - { - if ( buf != IntPtr.Zero ) - Marshal.FreeHGlobal( buf ); - } - - _isMacOSX = 0; - return false; - } - public static string ReadPassword() { ConsoleKeyInfo keyInfo;