add RealOSType and also set unknown ostype

This commit is contained in:
2020-12-04 09:10:21 +01:00
parent 1f9114dc02
commit cf8c8d782a
2 changed files with 34 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
Namespace Runtime Namespace Runtime
Public Enum OSType Public Enum OSType
Unknown
Windows Windows
Linux Linux
OSX OSX

View File

@@ -1,4 +1,5 @@
Imports System.Runtime.InteropServices Imports System.IO
Imports System.Runtime.InteropServices
Namespace Runtime Namespace Runtime
@@ -16,6 +17,8 @@ Namespace Runtime
t = OSType.Linux t = OSType.Linux
Case RuntimeInformation.IsOSPlatform(OSPlatform.OSX) Case RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
t = OSType.OSX t = OSType.OSX
Case Else
t = OSType.Unknown
End Select End Select
End If End If
@@ -23,6 +26,35 @@ Namespace Runtime
End Get End Get
End Property 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 Module
End Namespace End Namespace