* Unified operating system type detection

* Revert "Unified operating system type detection"

This reverts commit 3edf0edfceaca259e041e23b9930d78531366fd5.

* Introduced OperatingSystem.IsLinux instead of constant check on Os version.

* Misc
This commit is contained in:
Phyxion
2018-02-10 14:01:52 +01:00
committed by GitHub
parent 22bd00c806
commit 66e69c4c25
12 changed files with 76 additions and 79 deletions
+2 -2
View File
@@ -144,8 +144,8 @@ namespace OpenHardwareMonitor.Hardware.CPU {
// the file reader for lm-sensors support on Linux
temperatureStream = null;
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
if (Software.OperatingSystem.IsLinux) {
string[] devicePaths = Directory.GetDirectories("/sys/class/hwmon/");
foreach (string path in devicePaths) {
string name = null;
+2 -2
View File
@@ -24,8 +24,8 @@ namespace OpenHardwareMonitor.Hardware.HDD {
new List<AbstractHarddrive>();
public HarddriveGroup(ISettings settings) {
int p = (int)Environment.OSVersion.Platform;
if (p == 4 || p == 128) return;
if (Software.OperatingSystem.IsLinux) return;
ISmart smart = new WindowsSmart();
+1 -3
View File
@@ -67,9 +67,7 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
public HeatmasterGroup(ISettings settings) {
// No implementation for Heatmaster on Unix systems
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128))
return;
if (Software.OperatingSystem.IsLinux) return;
string[] portNames = GetRegistryPortNames();
for (int i = 0; i < portNames.Length; i++) {
+2 -2
View File
@@ -50,8 +50,8 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
new Identifier(Identifier, "name").ToString(), name);
ISuperIO[] superIO;
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
if (Software.OperatingSystem.IsLinux) {
this.lmSensors = new LMSensors();
superIO = lmSensors.SuperIO;
} else {
+5 -6
View File
@@ -19,8 +19,7 @@ namespace OpenHardwareMonitor.Hardware {
private static ulong size;
public static void Open() {
int p = (int)Environment.OSVersion.Platform;
byte[] rdtscCode;
byte[] cpuidCode;
if (IntPtr.Size == 4) {
@@ -29,7 +28,7 @@ namespace OpenHardwareMonitor.Hardware {
} else {
rdtscCode = RDTSC_64;
if ((p == 4) || (p == 128)) { // Unix
if (Software.OperatingSystem.IsLinux) { // Unix
cpuidCode = CPUID_64_LINUX;
} else { // Windows
cpuidCode = CPUID_64_WINDOWS;
@@ -38,7 +37,7 @@ namespace OpenHardwareMonitor.Hardware {
size = (ulong)(rdtscCode.Length + cpuidCode.Length);
if ((p == 4) || (p == 128)) { // Unix
if (Software.OperatingSystem.IsLinux) { // Unix
Assembly assembly =
Assembly.Load("Mono.Posix, Version=2.0.0.0, Culture=neutral, " +
"PublicKeyToken=0738eb9f132ed756");
@@ -81,8 +80,8 @@ namespace OpenHardwareMonitor.Hardware {
Rdtsc = null;
Cpuid = null;
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) { // Unix
if (Software.OperatingSystem.IsLinux) { // Unix
Assembly assembly =
Assembly.Load("Mono.Posix, Version=2.0.0.0, Culture=neutral, " +
"PublicKeyToken=0738eb9f132ed756");
-38
View File
@@ -1,38 +0,0 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (C) 2012 Michael Möller <mmoeller@openhardwaremonitor.org>
*/
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace OpenHardwareMonitor.Hardware {
internal static class OperatingSystem {
public static bool Is64BitOperatingSystem() {
if (IntPtr.Size == 8)
return true;
try {
bool wow64Process;
bool result = IsWow64Process(
Process.GetCurrentProcess().Handle, out wow64Process);
return result && wow64Process;
} catch (EntryPointNotFoundException) {
return false;
}
}
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWow64Process(IntPtr hProcess,
out bool wow64Process);
}
}
+2 -2
View File
@@ -18,8 +18,8 @@ namespace OpenHardwareMonitor.Hardware.RAM {
public RAMGroup(SMBIOS smbios, ISettings settings) {
// No implementation for RAM on Unix systems
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
if (Software.OperatingSystem.IsLinux) {
hardware = new Hardware[0];
return;
}
+2 -4
View File
@@ -80,7 +80,7 @@ namespace OpenHardwareMonitor.Hardware {
private static bool ExtractDriver(string fileName) {
string resourceName = "OpenHardwareMonitor.Hardware." +
(OperatingSystem.Is64BitOperatingSystem() ? "WinRing0x64.sys" :
(Software.OperatingSystem.Is64Bit ? "WinRing0x64.sys" :
"WinRing0.sys");
string[] names = GetAssembly().GetManifestResourceNames();
@@ -129,9 +129,7 @@ namespace OpenHardwareMonitor.Hardware {
public static void Open() {
// no implementation for unix systems
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128))
return;
if (Software.OperatingSystem.IsLinux) return;
if (driver != null)
return;
+5 -3
View File
@@ -41,9 +41,11 @@ namespace OpenHardwareMonitor.Hardware {
}
}
public SMBIOS() {
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) {
public SMBIOS()
{
if (Software.OperatingSystem.IsLinux)
{
this.raw = null;
this.table = null;
+15 -16
View File
@@ -19,26 +19,25 @@ namespace OpenHardwareMonitor.Hardware {
if (mask == 0)
return 0;
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) { // Unix
ulong result = 0;
if (NativeMethods.sched_getaffinity(0, (IntPtr)Marshal.SizeOf(result),
ref result) != 0)
return 0;
if (NativeMethods.sched_setaffinity(0, (IntPtr)Marshal.SizeOf(mask),
ref mask) != 0)
return 0;
return result;
} else { // Windows
if (Software.OperatingSystem.IsLinux)
{ // Unix
ulong result = 0;
if (NativeMethods.sched_getaffinity(0, (IntPtr)Marshal.SizeOf(result),
ref result) != 0)
return 0;
if (NativeMethods.sched_setaffinity(0, (IntPtr)Marshal.SizeOf(mask),
ref mask) != 0)
return 0;
return result;
} // Windows
UIntPtr uIntPtrMask;
try {
uIntPtrMask = (UIntPtr)mask;
uIntPtrMask = (UIntPtr)mask;
} catch (OverflowException) {
throw new ArgumentOutOfRangeException("mask");
}
throw new ArgumentOutOfRangeException("mask");
}
return (ulong)NativeMethods.SetThreadAffinityMask(
NativeMethods.GetCurrentThread(), uIntPtrMask);
}
NativeMethods.GetCurrentThread(), uIntPtrMask);
}
private static class NativeMethods {
+1 -1
View File
@@ -65,7 +65,6 @@
<Compile Include="Hardware\Mainboard\GigabyteTAMG.cs" />
<Compile Include="Hardware\Mainboard\Identification.cs" />
<Compile Include="Hardware\Opcode.cs" />
<Compile Include="Hardware\OperatingSystem.cs" />
<Compile Include="Hardware\RAM\GenericRAM.cs" />
<Compile Include="Hardware\RAM\RAMGroup.cs" />
<Compile Include="Hardware\Ring0.cs" />
@@ -114,6 +113,7 @@
<Compile Include="Hardware\ThreadAffinity.cs" />
<Compile Include="Properties\AssemblyLibInfo.cs" />
<Compile Include="Properties\AssemblyVersion.cs" />
<Compile Include="Software\OperatingSystem.cs" />
</ItemGroup>
<ItemGroup>
+39
View File
@@ -0,0 +1,39 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace OpenHardwareMonitor.Software
{
public static class OperatingSystem
{
static OperatingSystem()
{
// The operating system doesn't change during execution so let's query it just one time.
var platform = Environment.OSVersion.Platform;
IsLinux = platform == PlatformID.Unix || platform == PlatformID.MacOSX;
if (IntPtr.Size == 8)
Is64Bit = true;
try
{
var result = IsWow64Process(Process.GetCurrentProcess().Handle, out bool wow64Process);
Is64Bit = result && wow64Process;
}
catch (EntryPointNotFoundException)
{
Is64Bit = false;
}
}
public static bool Is64Bit { get; }
public static bool IsLinux { get; }
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWow64Process(IntPtr hProcess, out bool wow64Process);
}
}