mirror of
https://github.com/SteamRE/DepotDownloader.git
synced 2026-10-19 15:51:50 +00:00
Properly detect Mac OS X in DepotDownloader.
OSVersion.Platform just returns Unix on Mono.
This commit is contained in:
1 parent
8aa8798459
commit
2a24b41d60
3 files changed
+72
-16
No files matched your search
@@ -159,7 +159,7 @@ namespace DepotDownloader
|
||||
if ( ver.VersionID == version )
|
||||
{
|
||||
if ( ver.IsEncryptionKeyAvailable )
|
||||
return DecodeHexString( ver.DepotEncryptionKey );
|
||||
return Util.DecodeHexString( ver.DepotEncryptionKey );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ namespace DepotDownloader
|
||||
|
||||
if ( platform == PlatformID.Win32NT )
|
||||
platformStr = "windows";
|
||||
else if ( platform == PlatformID.MacOSX )
|
||||
else if ( Util.IsMacOSX() )
|
||||
platformStr = "macos";
|
||||
|
||||
foreach ( var blobField in appInfoBlob.FileSystems )
|
||||
@@ -212,7 +212,7 @@ namespace DepotDownloader
|
||||
|
||||
if ( platform == PlatformID.Win32NT )
|
||||
platformSuffix = "-win32";
|
||||
else if ( platform == PlatformID.Unix )
|
||||
else if ( platform == PlatformID.Unix && !Util.IsMacOSX() )
|
||||
platformSuffix = "-linux";
|
||||
|
||||
int gameLen = gameName.Length;
|
||||
@@ -280,18 +280,5 @@ namespace DepotDownloader
|
||||
return null;
|
||||
}
|
||||
}
|
||||
static byte[] DecodeHexString( string hex )
|
||||
{
|
||||
if ( hex == null )
|
||||
return null;
|
||||
|
||||
int chars = hex.Length;
|
||||
byte[] bytes = new byte [ chars / 2 ];
|
||||
|
||||
for ( int i = 0 ; i < chars ; i += 2 )
|
||||
bytes[ i / 2 ] = Convert.ToByte( hex.Substring( i, 2 ), 16 );
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ServerCache.cs" />
|
||||
<Compile Include="Steam3Session.cs" />
|
||||
<Compile Include="Util.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\SteamKit2\SteamKit2\SteamKit2.csproj">
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
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 byte[] DecodeHexString( string hex )
|
||||
{
|
||||
if ( hex == null )
|
||||
return null;
|
||||
|
||||
int chars = hex.Length;
|
||||
byte[] bytes = new byte[ chars / 2 ];
|
||||
|
||||
for ( int i = 0 ; i < chars ; i += 2 )
|
||||
bytes[ i / 2 ] = Convert.ToByte( hex.Substring(i, 2), 16 );
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user