convert Pilz to c# & add AppVersion to there
This commit is contained in:
9
Pilz/Runtime/OSType.cs
Normal file
9
Pilz/Runtime/OSType.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Pilz.Runtime;
|
||||
|
||||
public enum OSType
|
||||
{
|
||||
Unknown,
|
||||
Windows,
|
||||
Linux,
|
||||
OSX
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
Namespace Runtime
|
||||
|
||||
Public Enum OSType
|
||||
Unknown
|
||||
Windows
|
||||
Linux
|
||||
OSX
|
||||
End Enum
|
||||
|
||||
End Namespace
|
||||
79
Pilz/Runtime/RuntimeInformationsEx.cs
Normal file
79
Pilz/Runtime/RuntimeInformationsEx.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Pilz.Runtime;
|
||||
|
||||
public static class RuntimeInformationsEx
|
||||
{
|
||||
private static OSType? osType;
|
||||
private static OSType? osTypeReal;
|
||||
|
||||
public static OSType OSType => osType ??= GetOSType();
|
||||
|
||||
public static OSType RealOSType => osTypeReal ??= GetRealOSType();
|
||||
|
||||
public static OSType GetOSType()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
return OSType.Windows;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
return OSType.Linux;
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
return OSType.OSX;
|
||||
|
||||
return OSType.Unknown;
|
||||
}
|
||||
|
||||
public static OSType GetRealOSType()
|
||||
{
|
||||
var windir = Environment.GetEnvironmentVariable("windir");
|
||||
const string ostypeDirWine = @"Z:\proc\sys\kernel\ostype";
|
||||
const string ostypeDirNative = "/proc/sys/kernel/ostype";
|
||||
const string systemVersionWine = @"Z:\System\Library\CoreServices\SystemVersion.plist";
|
||||
const string systemVersionNative = "/System/Library/CoreServices/SystemVersion.plist";
|
||||
|
||||
// Linux using wine
|
||||
if (File.Exists(ostypeDirWine))
|
||||
{
|
||||
var osTypeString = File.ReadAllText(ostypeDirWine);
|
||||
if (osTypeString.StartsWith("Linux", StringComparison.OrdinalIgnoreCase))
|
||||
// Note: Android gets here too
|
||||
return OSType.Linux;
|
||||
else
|
||||
return OSType.Unknown;
|
||||
}
|
||||
|
||||
// Linux native
|
||||
else if (File.Exists(ostypeDirNative))
|
||||
{
|
||||
var osTypeString = File.ReadAllText(ostypeDirNative);
|
||||
if (osTypeString.StartsWith("Linux", StringComparison.OrdinalIgnoreCase))
|
||||
// Note: Android gets here too
|
||||
return OSType.Linux;
|
||||
else
|
||||
return OSType.Unknown;
|
||||
}
|
||||
|
||||
// OSX using wine
|
||||
else if (File.Exists(systemVersionWine))
|
||||
// Note: iOS gets here too
|
||||
return OSType.OSX;
|
||||
|
||||
// OSX native
|
||||
else if (File.Exists(systemVersionNative))
|
||||
// Note: iOS gets here too
|
||||
return OSType.OSX;
|
||||
|
||||
// Windows
|
||||
else if (!string.IsNullOrEmpty(windir) && Directory.Exists(windir) && Path.DirectorySeparatorChar == '\\')
|
||||
return OSType.Windows;
|
||||
|
||||
return OSType.Unknown;
|
||||
}
|
||||
|
||||
public static bool IsOSPlatform(OSType os, bool checkRealOS)
|
||||
{
|
||||
return (checkRealOS ? RealOSType : OSType) == os;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
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 = Environment.GetEnvironmentVariable("windir")
|
||||
Const ostypeDirWine = "Z:\proc\sys\kernel\ostype"
|
||||
Const ostypeDirNative = "/proc/sys/kernel/ostype"
|
||||
Const systemVersionWine = "Z:\System\Library\CoreServices\SystemVersion.plist"
|
||||
Const systemVersionNative = "/System/Library/CoreServices/SystemVersion.plist"
|
||||
|
||||
If File.Exists(ostypeDirWine) Then ' Linux using wine
|
||||
Dim osTypeString As String = File.ReadAllText(ostypeDirWine)
|
||||
If osTypeString.StartsWith("Linux", StringComparison.OrdinalIgnoreCase) Then
|
||||
' Note: Android gets here too
|
||||
t = OSType.Linux
|
||||
Else
|
||||
t = OSType.Unknown
|
||||
End If
|
||||
ElseIf File.Exists(ostypeDirNative) Then ' Linux native
|
||||
Dim osTypeString As String = File.ReadAllText(ostypeDirNative)
|
||||
If osTypeString.StartsWith("Linux", StringComparison.OrdinalIgnoreCase) Then
|
||||
' Note: Android gets here too
|
||||
t = OSType.Linux
|
||||
Else
|
||||
t = OSType.Unknown
|
||||
End If
|
||||
ElseIf File.Exists(systemVersionWine) Then ' OSX using wine
|
||||
' Note: iOS gets here too
|
||||
t = OSType.OSX
|
||||
ElseIf File.Exists(systemVersionNative) Then ' OSX native
|
||||
' Note: iOS gets here too
|
||||
t = OSType.OSX
|
||||
ElseIf Not String.IsNullOrEmpty(windir) AndAlso Directory.Exists(windir) AndAlso Path.DirectorySeparatorChar = "\"c Then ' Windows
|
||||
t = OSType.Windows
|
||||
Else
|
||||
t = OSType.Unknown
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
Return t
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Function IsOSPlatform(os As OSType, checkRealOS As Boolean) As Boolean
|
||||
Return If(checkRealOS, RealOSType, OSType) = os
|
||||
End Function
|
||||
|
||||
End Module
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user