# HG changeset patch # User moel.mich # Date 1343148348 0 # Node ID 2de3a3e5f0b5326513b7bd3076ad679360920296 # Parent c1a0d321e6460974d90dfe8c5593f6e71597c03f 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. diff -r c1a0d321e646 -r 2de3a3e5f0b5 Hardware/RAM/GenericRAM.cs --- a/Hardware/RAM/GenericRAM.cs Tue Jul 24 16:04:30 2012 +0000 +++ b/Hardware/RAM/GenericRAM.cs Tue Jul 24 16:45:48 2012 +0000 @@ -8,7 +8,7 @@ */ -using Microsoft.VisualBasic.Devices; +using System.Runtime.InteropServices; namespace OpenHardwareMonitor.Hardware.RAM { internal class GenericRAM : Hardware { @@ -16,16 +16,14 @@ private Sensor loadSensor; private Sensor availableMemory; - private ComputerInfo computerInfo; - public GenericRAM(string name, ISettings settings) : base(name, new Identifier("ram"), settings) { - computerInfo = new ComputerInfo(); loadSensor = new Sensor("Memory", 0, SensorType.Load, this, settings); ActivateSensor(loadSensor); - availableMemory = new Sensor("Available Memory", 0, SensorType.Data, this, settings); + availableMemory = new Sensor("Available Memory", 0, SensorType.Data, this, + settings); ActivateSensor(availableMemory); } @@ -36,12 +34,39 @@ } public override void Update() { - loadSensor.Value = 100.0f - - (100.0f * computerInfo.AvailablePhysicalMemory) / - computerInfo.TotalPhysicalMemory; + NativeMethods.MemoryStatusEx status = new NativeMethods.MemoryStatusEx(); + status.Length = checked((uint)Marshal.SizeOf( + 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); } + + 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); + } } } diff -r c1a0d321e646 -r 2de3a3e5f0b5 Hardware/RAM/RAMGroup.cs --- a/Hardware/RAM/RAMGroup.cs Tue Jul 24 16:04:30 2012 +0000 +++ b/Hardware/RAM/RAMGroup.cs Tue Jul 24 16:45:48 2012 +0000 @@ -8,12 +8,22 @@ */ +using System; + namespace OpenHardwareMonitor.Hardware.RAM { internal class RAMGroup : IGroup { private IHardware[] hardware; 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; if (smbios.MemoryDevices.Length > 0) { name = smbios.MemoryDevices[0].ManufacturerName + " " + diff -r c1a0d321e646 -r 2de3a3e5f0b5 OpenHardwareMonitorLib.csproj --- a/OpenHardwareMonitorLib.csproj Tue Jul 24 16:04:30 2012 +0000 +++ b/OpenHardwareMonitorLib.csproj Tue Jul 24 16:45:48 2012 +0000 @@ -52,7 +52,6 @@ AllRules.ruleset -