61 lines
2.1 KiB
VB.net
61 lines
2.1 KiB
VB.net
Imports System.IO
|
|
Imports System.Runtime.InteropServices
|
|
|
|
Namespace Runtime
|
|
|
|
Public Module RuntimeInformationsEx
|
|
|
|
Public ReadOnly Property OSType As OSType
|
|
Get
|
|
Static t As OSType? = Nothing
|
|
|
|
If t Is Nothing Then
|
|
Select Case True
|
|
Case RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
|
t = OSType.Windows
|
|
Case RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|
|
t = OSType.Linux
|
|
Case RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
|
|
t = OSType.OSX
|
|
Case Else
|
|
t = OSType.Unknown
|
|
End Select
|
|
End If
|
|
|
|
Return t
|
|
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
|