mirror of
https://github.com/SteamRE/DepotDownloader.git
synced 2026-10-20 01:46:17 +00:00
Restore Environment.OSVersion and P/Invoke for getting OS type on .NET Framework
This commit is contained in:
1 parent
8eb3f711b9
commit
359a8d017d
1 file changed
+65
@@ -12,6 +12,8 @@ namespace DepotDownloader
|
||||
{
|
||||
public static string GetSteamOS()
|
||||
{
|
||||
#if NETCOREAPP1_1
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return "windows";
|
||||
@@ -25,6 +27,22 @@ namespace DepotDownloader
|
||||
return "linux";
|
||||
}
|
||||
|
||||
#elif NET46
|
||||
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.Win32NT:
|
||||
case PlatformID.Win32Windows:
|
||||
return "windows";
|
||||
case PlatformID.MacOSX:
|
||||
return "macos";
|
||||
case PlatformID.Unix:
|
||||
return IsMacOSX() ? "macos" : "linux";
|
||||
}
|
||||
#else
|
||||
#error Unknown Target Platform
|
||||
#endif
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
@@ -127,5 +145,52 @@ namespace DepotDownloader
|
||||
( sb, v ) => sb.Append( v.ToString( "x2" ) )
|
||||
).ToString();
|
||||
}
|
||||
|
||||
#if NET46
|
||||
|
||||
[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
|
||||
private 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;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user