Merge branch 'master' into dotnet5

This commit is contained in:
2020-12-04 09:10:40 +01:00

View File

@@ -1,4 +1,5 @@
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Runtime.InteropServices
Namespace Runtime
@@ -16,6 +17,8 @@ Namespace Runtime
t = OSType.Linux
Case RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
t = OSType.OSX
Case Else
t = OSType.Unknown
End Select
End If
@@ -23,6 +26,35 @@ Namespace Runtime
End Get
End Property
Public ReadOnly Property RealOSType As OSType
Get
Static t As OSType? = Nothing
If t Is Nothing Then
Dim windir As String = Environment.GetEnvironmentVariable("windir")
If Not String.IsNullOrEmpty(windir) AndAlso windir.Contains("\") AndAlso Directory.Exists(windir) Then
t = OSType.Windows
ElseIf File.Exists("/proc/sys/kernel/ostype") Then
Dim osTypeString As String = File.ReadAllText("/proc/sys/kernel/ostype")
If osTypeString.StartsWith("Linux", StringComparison.OrdinalIgnoreCase) Then
' Note: Android gets here too
t = OSType.Linux
Else
t = OSType.Unknown
End If
ElseIf File.Exists("/System/Library/CoreServices/SystemVersion.plist") Then
' Note: iOS gets here too
t = OSType.OSX
Else
t = OSType.Unknown
End If
End If
Return t
End Get
End Property
End Module
End Namespace