mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-09-03 15:55:26 +00:00
Changed the RAM implementation (removed Microsoft.VisualBasic dependency which is not implemented in Mono) and added code to prevent RAM hardware from loading on Linux.
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Microsoft.VisualBasic.Devices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.Hardware.RAM {
|
namespace OpenHardwareMonitor.Hardware.RAM {
|
||||||
internal class GenericRAM : Hardware {
|
internal class GenericRAM : Hardware {
|
||||||
@@ -16,16 +16,14 @@ namespace OpenHardwareMonitor.Hardware.RAM {
|
|||||||
private Sensor loadSensor;
|
private Sensor loadSensor;
|
||||||
private Sensor availableMemory;
|
private Sensor availableMemory;
|
||||||
|
|
||||||
private ComputerInfo computerInfo;
|
|
||||||
|
|
||||||
public GenericRAM(string name, ISettings settings)
|
public GenericRAM(string name, ISettings settings)
|
||||||
: base(name, new Identifier("ram"), settings)
|
: base(name, new Identifier("ram"), settings)
|
||||||
{
|
{
|
||||||
computerInfo = new ComputerInfo();
|
|
||||||
loadSensor = new Sensor("Memory", 0, SensorType.Load, this, settings);
|
loadSensor = new Sensor("Memory", 0, SensorType.Load, this, settings);
|
||||||
ActivateSensor(loadSensor);
|
ActivateSensor(loadSensor);
|
||||||
|
|
||||||
availableMemory = new Sensor("Available Memory", 0, SensorType.Data, this, settings);
|
availableMemory = new Sensor("Available Memory", 0, SensorType.Data, this,
|
||||||
|
settings);
|
||||||
ActivateSensor(availableMemory);
|
ActivateSensor(availableMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,12 +34,39 @@ namespace OpenHardwareMonitor.Hardware.RAM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Update() {
|
public override void Update() {
|
||||||
loadSensor.Value = 100.0f -
|
NativeMethods.MemoryStatusEx status = new NativeMethods.MemoryStatusEx();
|
||||||
(100.0f * computerInfo.AvailablePhysicalMemory) /
|
status.Length = checked((uint)Marshal.SizeOf(
|
||||||
computerInfo.TotalPhysicalMemory;
|
typeof(NativeMethods.MemoryStatusEx)));
|
||||||
|
|
||||||
availableMemory.Value = (float)computerInfo.AvailablePhysicalMemory /
|
if (!NativeMethods.GlobalMemoryStatusEx(ref status))
|
||||||
|
return;
|
||||||
|
|
||||||
|
loadSensor.Value = 100.0f -
|
||||||
|
(100.0f * status.AvailablePhysicalMemory) /
|
||||||
|
status.TotalPhysicalMemory;
|
||||||
|
|
||||||
|
availableMemory.Value = (float)status.AvailablePhysicalMemory /
|
||||||
(1024 * 1024 * 1024);
|
(1024 * 1024 * 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class NativeMethods {
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct MemoryStatusEx {
|
||||||
|
public uint Length;
|
||||||
|
public uint MemoryLoad;
|
||||||
|
public ulong TotalPhysicalMemory;
|
||||||
|
public ulong AvailablePhysicalMemory;
|
||||||
|
public ulong TotalPageFile;
|
||||||
|
public ulong AvailPageFile;
|
||||||
|
public ulong TotalVirtual;
|
||||||
|
public ulong AvailVirtual;
|
||||||
|
public ulong AvailExtendedVirtual;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
internal static extern bool GlobalMemoryStatusEx(
|
||||||
|
ref NativeMethods.MemoryStatusEx buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,12 +8,22 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.Hardware.RAM {
|
namespace OpenHardwareMonitor.Hardware.RAM {
|
||||||
internal class RAMGroup : IGroup {
|
internal class RAMGroup : IGroup {
|
||||||
|
|
||||||
private IHardware[] hardware;
|
private IHardware[] hardware;
|
||||||
|
|
||||||
public RAMGroup(SMBIOS smbios, ISettings settings) {
|
public RAMGroup(SMBIOS smbios, ISettings settings) {
|
||||||
|
|
||||||
|
// No implementation for RAM on Unix systems
|
||||||
|
int p = (int)Environment.OSVersion.Platform;
|
||||||
|
if ((p == 4) || (p == 128)) {
|
||||||
|
hardware = new IHardware[0];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
if (smbios.MemoryDevices.Length > 0) {
|
if (smbios.MemoryDevices.Length > 0) {
|
||||||
name = smbios.MemoryDevices[0].ManufacturerName + " " +
|
name = smbios.MemoryDevices[0].ManufacturerName + " " +
|
||||||
|
@@ -52,7 +52,6 @@
|
|||||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Microsoft.VisualBasic" />
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Management" />
|
<Reference Include="System.Management" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
Reference in New Issue
Block a user