From cf8c8d782a014e495652b20d932793a226ecf461 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Fri, 4 Dec 2020 09:10:21 +0100 Subject: [PATCH] add RealOSType and also set unknown ostype --- Pilz/Runtime/OSType.vb | 1 + Pilz/Runtime/RuntimeInformationsEx.vb | 34 ++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Pilz/Runtime/OSType.vb b/Pilz/Runtime/OSType.vb index caf344b..477cc87 100644 --- a/Pilz/Runtime/OSType.vb +++ b/Pilz/Runtime/OSType.vb @@ -1,6 +1,7 @@ Namespace Runtime Public Enum OSType + Unknown Windows Linux OSX diff --git a/Pilz/Runtime/RuntimeInformationsEx.vb b/Pilz/Runtime/RuntimeInformationsEx.vb index a52bb99..24ecfb0 100644 --- a/Pilz/Runtime/RuntimeInformationsEx.vb +++ b/Pilz/Runtime/RuntimeInformationsEx.vb @@ -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