Fixed some Code Analysis warnings.

This commit is contained in:
Michael Möller
2010-08-15 14:46:58 +00:00
parent 2ec18bf862
commit 2071610bbe
33 changed files with 609 additions and 535 deletions

View File

@@ -41,6 +41,7 @@ using System.Collections.Generic;
using System.Text;
namespace OpenHardwareMonitor.Collections {
public class ListSet<T> : IEnumerable<T> {
private List<T> list = new List<T>();

View File

@@ -66,5 +66,9 @@ namespace OpenHardwareMonitor.Collections {
public static implicit operator ReadOnlyArray<T>(T[] array) {
return new ReadOnlyArray<T>(array);
}
public T[] ToArray() {
return (T[])array.Clone();
}
}
}

View File

@@ -159,7 +159,7 @@ namespace OpenHardwareMonitor.GUI {
protected override void InsertItem(int index, Node item) {
if (item == null)
throw new ArgumentNullException();
throw new ArgumentNullException("item");
if (item.parent != owner) {
if (item.parent != null)
@@ -189,7 +189,7 @@ namespace OpenHardwareMonitor.GUI {
protected override void SetItem(int index, Node item) {
if (item == null)
throw new ArgumentNullException();
throw new ArgumentNullException("item");
RemoveAt(index);
InsertItem(index, item);

View File

@@ -104,7 +104,7 @@ namespace OpenHardwareMonitor.Hardware.ATI {
report.Append("AdapterID: 0x");
report.AppendLine(adapterID.ToString("X", CultureInfo.InvariantCulture));
if (adapterID != 0 && adapterInfo[i].UDID != "" &&
if (adapterID != 0 && !string.IsNullOrEmpty(adapterInfo[i].UDID) &&
(adapterInfo[i].VendorID == ADL.ATI_VENDOR_ID1 ||
adapterInfo[i].VendorID == ADL.ATI_VENDOR_ID2)) {
bool found = false;

View File

@@ -48,13 +48,13 @@ namespace OpenHardwareMonitor.Hardware.CPU {
private CPUID[][][] threads;
private CPUID[][] GetProcessorThreads() {
private static CPUID[][] GetProcessorThreads() {
List<CPUID> threads = new List<CPUID>();
for (int i = 0; i < 32; i++) {
try {
threads.Add(new CPUID(i));
} catch (ArgumentException) { }
} catch (ArgumentOutOfRangeException) { }
}
SortedDictionary<uint, List<CPUID>> processors =
@@ -78,7 +78,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
return processorThreads;
}
private CPUID[][] GroupThreadsByCore(CPUID[] threads) {
private static CPUID[][] GroupThreadsByCore(CPUID[] threads) {
SortedDictionary<uint, List<CPUID>> cores =
new SortedDictionary<uint, List<CPUID>>();
@@ -151,7 +151,9 @@ namespace OpenHardwareMonitor.Hardware.CPU {
}
}
private void AppendCpuidData(StringBuilder r, uint[,] data, uint offset) {
private static void AppendCpuidData(StringBuilder r, uint[,] data,
uint offset)
{
for (int i = 0; i < data.GetLength(0); i++) {
r.Append(" ");
r.Append((i + offset).ToString("X8", CultureInfo.InvariantCulture));

View File

@@ -75,14 +75,14 @@ namespace OpenHardwareMonitor.Hardware.CPU {
public static uint CPUID_0 = 0;
public static uint CPUID_EXT = 0x80000000;
private void AppendRegister(StringBuilder b, uint value) {
private static void AppendRegister(StringBuilder b, uint value) {
b.Append((char)((value) & 0xff));
b.Append((char)((value >> 8) & 0xff));
b.Append((char)((value >> 16) & 0xff));
b.Append((char)((value >> 24) & 0xff));
}
private uint NextLog2(long x) {
private static uint NextLog2(long x) {
if (x <= 0)
return 0;
@@ -105,7 +105,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
uint eax, ebx, ecx, edx;
if (thread >= 32)
throw new ArgumentException();
throw new ArgumentOutOfRangeException("thread");
UIntPtr mask = (UIntPtr)(1L << thread);
if (WinRing0.CpuidTx(CPUID_0, 0,
@@ -139,10 +139,10 @@ namespace OpenHardwareMonitor.Hardware.CPU {
else
return;
} else {
throw new ArgumentException();
throw new ArgumentOutOfRangeException("thread");
}
} else {
throw new ArgumentException();
throw new ArgumentOutOfRangeException("thread");
}
maxCpuid = Math.Min(maxCpuid, 1024);

View File

@@ -62,12 +62,6 @@ namespace OpenHardwareMonitor.Hardware.CPU {
SystemProcessorPerformanceInformation = 8
}
[DllImport("ntdll.dll")]
private static extern int NtQuerySystemInformation(
SystemInformationClass informationClass,
[Out] SystemProcessorPerformanceInformation[] informations,
int structSize, out IntPtr returnLength);
private CPUID[][] cpuid;
private long systemTime;
@@ -78,16 +72,17 @@ namespace OpenHardwareMonitor.Hardware.CPU {
private bool available = false;
private long[] GetIdleTimes() {
private static long[] GetIdleTimes() {
SystemProcessorPerformanceInformation[] informations = new
SystemProcessorPerformanceInformation[64];
int size = Marshal.SizeOf(typeof(SystemProcessorPerformanceInformation));
IntPtr returnLength;
NtQuerySystemInformation(
if (NativeMethods.NtQuerySystemInformation(
SystemInformationClass.SystemProcessorPerformanceInformation,
informations, informations.Length * size, out returnLength);
informations, informations.Length * size, out returnLength) != 0)
return null;
long[] result = new long[(int)returnLength / size];
@@ -127,10 +122,13 @@ namespace OpenHardwareMonitor.Hardware.CPU {
if (this.idleTimes == null)
return;
long localSystemTime = DateTime.Now.Ticks;
long[] localIdleTimes = GetIdleTimes();
long newSystemTime = DateTime.Now.Ticks;
long[] newIdleTimes = GetIdleTimes();
if (localSystemTime - this.systemTime < 10000)
if (newSystemTime - this.systemTime < 10000)
return;
if (newIdleTimes == null)
return;
float total = 0;
@@ -139,29 +137,37 @@ namespace OpenHardwareMonitor.Hardware.CPU {
float value = 0;
for (int j = 0; j < cpuid[i].Length; j++) {
long index = cpuid[i][j].Thread;
if (index < localIdleTimes.Length) {
long delta = localIdleTimes[index] - this.idleTimes[index];
if (index < newIdleTimes.Length) {
long delta = newIdleTimes[index] - this.idleTimes[index];
value += delta;
total += delta;
count++;
}
}
value = 1.0f - value / (cpuid[i].Length *
(localSystemTime - this.systemTime));
(newSystemTime - this.systemTime));
value = value < 0 ? 0 : value;
coreLoads[i] = value * 100;
}
if (count > 0) {
total = 1.0f - total / (count * (localSystemTime - this.systemTime));
total = 1.0f - total / (count * (newSystemTime - this.systemTime));
total = total < 0 ? 0 : total;
} else {
total = 0;
}
this.totalLoad = total * 100;
this.systemTime = localSystemTime;
this.idleTimes = localIdleTimes;
this.systemTime = newSystemTime;
this.idleTimes = newIdleTimes;
}
private static class NativeMethods {
[DllImport("ntdll.dll")]
public static extern int NtQuerySystemInformation(
SystemInformationClass informationClass,
[Out] SystemProcessorPerformanceInformation[] informations,
int structSize, out IntPtr returnLength);
}
}
}

View File

@@ -253,7 +253,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
get { return HardwareType.CPU; }
}
private void AppendMSRData(StringBuilder r, uint msr, int thread) {
private static void AppendMSRData(StringBuilder r, uint msr, int thread) {
uint eax, edx;
if (WinRing0.RdmsrTx(msr, out eax, out edx, (UIntPtr)(1L << thread))) {
r.Append(" ");
@@ -298,7 +298,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
return r.ToString();
}
private double EstimateMaxClock(double timeWindow) {
private static double EstimateMaxClock(double timeWindow) {
long ticks = (long)(timeWindow * Stopwatch.Frequency);
uint lsbBegin, msbBegin, lsbEnd, msbEnd;
@@ -359,7 +359,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
else
maxClock = estimatedMaxClock;
double busClock = 0;
double newBusClock = 0;
uint eax, edx;
for (int i = 0; i < coreClocks.Length; i++) {
System.Threading.Thread.Sleep(1);
@@ -369,7 +369,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
uint nehalemMultiplier = eax & 0xff;
coreClocks[i].Value =
(float)(nehalemMultiplier * maxClock / maxNehalemMultiplier);
busClock = (float)(maxClock / maxNehalemMultiplier);
newBusClock = (float)(maxClock / maxNehalemMultiplier);
} else { // Core 2
uint multiplier = (eax >> 8) & 0x1f;
uint maxMultiplier = (edx >> 8) & 0x1f;
@@ -378,7 +378,7 @@ namespace OpenHardwareMonitor.Hardware.CPU {
uint maxFactor = (maxMultiplier << 1) | ((edx >> 14) & 1);
if (maxFactor > 0) {
coreClocks[i].Value = (float)(factor * maxClock / maxFactor);
busClock = (float)(2 * maxClock / maxFactor);
newBusClock = (float)(2 * maxClock / maxFactor);
}
}
} else { // Intel Pentium 4
@@ -386,8 +386,8 @@ namespace OpenHardwareMonitor.Hardware.CPU {
coreClocks[i].Value = (float)maxClock;
}
}
if (busClock > 0) {
this.busClock.Value = (float)busClock;
if (newBusClock > 0) {
this.busClock.Value = (float)newBusClock;
ActivateSensor(this.busClock);
}
}

View File

@@ -41,6 +41,9 @@ using System.IO;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Security;
using System.Security.Permissions;
namespace OpenHardwareMonitor.Hardware {
@@ -86,10 +89,13 @@ namespace OpenHardwareMonitor.Hardware {
HardwareRemoved(hardware);
}
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
public void Open() {
if (open)
return;
WinRing0.Open();
Add(new Mainboard.MainboardGroup(settings));
Add(new CPU.CPUGroup(settings));
Add(new ATI.ATIGroup(settings));
@@ -104,6 +110,8 @@ namespace OpenHardwareMonitor.Hardware {
public bool HDDEnabled {
get { return hddEnabled; }
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
set {
if (open && value && !hddEnabled) {
Add(new HDD.HDDGroup(settings));
@@ -129,7 +137,7 @@ namespace OpenHardwareMonitor.Hardware {
}
}
private void NewSection(TextWriter writer) {
private static void NewSection(TextWriter writer) {
for (int i = 0; i < 8; i++)
writer.Write("----------");
writer.WriteLine();
@@ -186,7 +194,7 @@ namespace OpenHardwareMonitor.Hardware {
private void ReportHardware(IHardware hardware, TextWriter w) {
string hardwareReport = hardware.GetReport();
if (hardwareReport != null && hardwareReport != "") {
if (!string.IsNullOrEmpty(hardwareReport)) {
NewSection(w);
w.Write(hardwareReport);
}
@@ -237,7 +245,7 @@ namespace OpenHardwareMonitor.Hardware {
foreach (IGroup group in groups) {
string report = group.GetReport();
if (report != null && report != "") {
if (!string.IsNullOrEmpty(report)) {
NewSection(w);
w.Write(report);
}
@@ -259,6 +267,8 @@ namespace OpenHardwareMonitor.Hardware {
group.Close();
groups.Clear();
WinRing0.Close();
open = false;
}
@@ -266,7 +276,8 @@ namespace OpenHardwareMonitor.Hardware {
public event HardwareEventHandler HardwareRemoved;
public void Accept(IVisitor visitor) {
if (visitor != null)
if (visitor == null)
throw new ArgumentNullException("visitor");
visitor.VisitComputer(this);
}

View File

@@ -117,7 +117,8 @@ namespace OpenHardwareMonitor.Hardware.HDD {
#pragma warning restore 67
public void Accept(IVisitor visitor) {
if (visitor != null)
if (visitor == null)
throw new ArgumentNullException("visitor");
visitor.VisitHardware(this);
}

View File

@@ -232,37 +232,10 @@ namespace OpenHardwareMonitor.Hardware.HDD {
private const int MAX_DRIVE_ATTRIBUTES = 512;
private const string KERNEL = "kernel32.dll";
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
private static extern IntPtr CreateFile(string fileName,
AccessMode desiredAccess, ShareMode shareMode, IntPtr securityAttributes,
CreationMode creationDisposition, FileAttribute flagsAndAttributes,
IntPtr templateFilehandle);
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
public static extern int CloseHandle(IntPtr handle);
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
private static extern bool DeviceIoControl(IntPtr handle,
DriveCommand command, ref DriveCommandParameter parameter,
int parameterSize, out DriveSmartReadResult result, int resultSize,
out uint bytesReturned, IntPtr overlapped);
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
private static extern bool DeviceIoControl(IntPtr handle,
DriveCommand command, ref DriveCommandParameter parameter,
int parameterSize, out DriveCommandResult result, int resultSize,
out uint bytesReturned, IntPtr overlapped);
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
private static extern bool DeviceIoControl(IntPtr handle,
DriveCommand command, ref DriveCommandParameter parameter,
int parameterSize, out DriveIdentifyResult result, int resultSize,
out uint bytesReturned, IntPtr overlapped);
private SMART() { }
public static IntPtr OpenPhysicalDrive(int driveNumber) {
return CreateFile(@"\\.\PhysicalDrive" + driveNumber,
return NativeMethods.CreateFile(@"\\.\PhysicalDrive" + driveNumber,
AccessMode.Read | AccessMode.Write, ShareMode.Read | ShareMode.Write,
IntPtr.Zero, CreationMode.OpenExisting, FileAttribute.Device,
IntPtr.Zero);
@@ -279,8 +252,8 @@ namespace OpenHardwareMonitor.Hardware.HDD {
parameter.Registers.LBAHigh = SMART_LBA_HI;
parameter.Registers.Command = SMART_CMD;
return DeviceIoControl(handle, DriveCommand.SendDriveCommand,
ref parameter, Marshal.SizeOf(parameter), out result,
return NativeMethods.DeviceIoControl(handle, DriveCommand.SendDriveCommand,
ref parameter, Marshal.SizeOf(typeof(DriveCommandParameter)), out result,
Marshal.SizeOf(typeof(DriveCommandResult)), out bytesReturned,
IntPtr.Zero);
}
@@ -296,10 +269,10 @@ namespace OpenHardwareMonitor.Hardware.HDD {
parameter.Registers.LBAHigh = SMART_LBA_HI;
parameter.Registers.Command = SMART_CMD;
bool valid = DeviceIoControl(handle, DriveCommand.ReceiveDriveData,
ref parameter, Marshal.SizeOf(parameter), out result,
Marshal.SizeOf(typeof(DriveSmartReadResult)), out bytesReturned,
IntPtr.Zero);
bool valid = NativeMethods.DeviceIoControl(handle,
DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
out result, Marshal.SizeOf(typeof(DriveSmartReadResult)),
out bytesReturned, IntPtr.Zero);
if (!valid)
return null;
@@ -315,10 +288,10 @@ namespace OpenHardwareMonitor.Hardware.HDD {
parameter.DriveNumber = (byte)driveNumber;
parameter.Registers.Command = ID_CMD;
bool valid = DeviceIoControl(handle, DriveCommand.ReceiveDriveData,
ref parameter, Marshal.SizeOf(parameter), out result,
Marshal.SizeOf(typeof(DriveIdentifyResult)), out bytesReturned,
IntPtr.Zero);
bool valid = NativeMethods.DeviceIoControl(handle,
DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
out result, Marshal.SizeOf(typeof(DriveIdentifyResult)),
out bytesReturned, IntPtr.Zero);
if (!valid)
return null;
@@ -335,5 +308,43 @@ namespace OpenHardwareMonitor.Hardware.HDD {
}
}
public static int CloseHandle(IntPtr handle) {
return NativeMethods.CloseHandle(handle);
}
private static class NativeMethods {
private const string KERNEL = "kernel32.dll";
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi,
CharSet = CharSet.Unicode)]
public static extern IntPtr CreateFile(string fileName,
AccessMode desiredAccess, ShareMode shareMode, IntPtr securityAttributes,
CreationMode creationDisposition, FileAttribute flagsAndAttributes,
IntPtr templateFilehandle);
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
public static extern int CloseHandle(IntPtr handle);
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
public static extern bool DeviceIoControl(IntPtr handle,
DriveCommand command, ref DriveCommandParameter parameter,
int parameterSize, out DriveSmartReadResult result, int resultSize,
out uint bytesReturned, IntPtr overlapped);
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
public static extern bool DeviceIoControl(IntPtr handle,
DriveCommand command, ref DriveCommandParameter parameter,
int parameterSize, out DriveCommandResult result, int resultSize,
out uint bytesReturned, IntPtr overlapped);
[DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
public static extern bool DeviceIoControl(IntPtr handle,
DriveCommand command, ref DriveCommandParameter parameter,
int parameterSize, out DriveIdentifyResult result, int resultSize,
out uint bytesReturned, IntPtr overlapped);
}
}
}

View File

@@ -80,7 +80,8 @@ namespace OpenHardwareMonitor.Hardware {
public abstract void Update();
public void Accept(IVisitor visitor) {
if (visitor != null)
if (visitor == null)
throw new ArgumentNullException("visitor");
visitor.VisitHardware(this);
}

View File

@@ -46,7 +46,7 @@ namespace OpenHardwareMonitor.Hardware {
IHardware[] Hardware { get; }
bool HDDEnabled { get; set; }
bool HDDEnabled { get; }
string GetReport();

View File

@@ -45,7 +45,7 @@ namespace OpenHardwareMonitor.Hardware {
private static char SEPARATOR = '/';
private void CheckIdentifiers(string[] identifiers) {
private static void CheckIdentifiers(string[] identifiers) {
foreach (string s in identifiers)
if (s.Contains(" ") || s.Contains(SEPARATOR.ToString()))
throw new ArgumentException("Invalid identifier");

View File

@@ -28,4 +28,36 @@ namespace OpenHardwareMonitor.Hardware.LPC {
F71889F = 0x0723
}
internal class ChipName {
private ChipName() { }
public static string GetName(Chip chip) {
switch (chip) {
case Chip.F71858: return "Fintek F71858";
case Chip.F71862: return "Fintek F71862";
case Chip.F71869: return "Fintek F71869";
case Chip.F71882: return "Fintek F71882";
case Chip.F71889ED: return "Fintek F71889ED";
case Chip.F71889F: return "Fintek F71889F";
case Chip.IT8712F: return "ITE IT8712F";
case Chip.IT8716F: return "ITE IT8716F";
case Chip.IT8718F: return "ITE IT8718F";
case Chip.IT8720F: return "ITE IT8720F";
case Chip.IT8726F: return "ITE IT8726F";
case Chip.W83627DHG: return "Winbond W83627DHG";
case Chip.W83627DHGP: return "Winbond W83627DHG-P";
case Chip.W83627EHF: return "Winbond W83627EHF";
case Chip.W83627HF: return "Winbond W83627HF";
case Chip.W83627THF: return "Winbond W83627THF";
case Chip.W83667HG: return "Winbond W83667HG";
case Chip.W83667HGB: return "Winbond W83667HG-B";
case Chip.W83687THF: return "Winbond W83687THF";
case Chip.Unknown: return "Unkown";
default: return "Unknown";
}
}
}
}

View File

@@ -51,9 +51,8 @@ namespace OpenHardwareMonitor.Hardware.LPC {
foreach (string path in devicePaths) {
string name = null;
try {
StreamReader reader = new StreamReader(path + "/device/name");
using (StreamReader reader = new StreamReader(path + "/device/name"))
name = reader.ReadLine();
reader.Close();
} catch (IOException) { }
switch (name) {
case "f71858fg":

View File

@@ -47,8 +47,6 @@ namespace OpenHardwareMonitor.Hardware.LPC {
private List<ISuperIO> superIOs = new List<ISuperIO>();
private StringBuilder report = new StringBuilder();
private Chip chip = Chip.Unknown;
// I/O Ports
private ushort[] REGISTER_PORTS = new ushort[] { 0x2e, 0x4e };
private ushort[] VALUE_PORTS = new ushort[] { 0x2f, 0x4f };
@@ -121,18 +119,25 @@ namespace OpenHardwareMonitor.Hardware.LPC {
WinRing0.WriteIoPortByte(registerPort, 0xAA);
}
private void Detect() {
for (int i = 0; i < REGISTER_PORTS.Length; i++) {
registerPort = REGISTER_PORTS[i];
valuePort = VALUE_PORTS[i];
private void ReportUnknownChip(string type, int chip) {
report.Append("Chip ID: Unknown ");
report.Append(type);
report.Append(" with ID 0x");
report.Append(chip.ToString("X", CultureInfo.InvariantCulture));
report.Append(" at 0x");
report.Append(registerPort.ToString("X", CultureInfo.InvariantCulture));
report.Append("/0x");
report.AppendLine(valuePort.ToString("X", CultureInfo.InvariantCulture));
report.AppendLine();
}
private bool DetectWinbondFintek() {
WinbondFintekEnter();
byte logicalDeviceNumber;
byte id = ReadByte(CHIP_ID_REGISTER);
byte revision = ReadByte(CHIP_REVISION_REGISTER);
chip = Chip.Unknown;
Chip chip = Chip.Unknown;
logicalDeviceNumber = 0;
switch (id) {
case 0x05:
@@ -238,10 +243,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
if (id != 0 && id != 0xff) {
WinbondFintekExit();
report.Append("Chip ID: Unknown Winbond / Fintek with ID 0x");
report.AppendLine(((id << 8) | revision).ToString("X",
CultureInfo.InvariantCulture));
report.AppendLine();
ReportUnknownChip("Winbond / Fintek", ((id << 8) | revision));
}
} else {
@@ -258,10 +260,11 @@ namespace OpenHardwareMonitor.Hardware.LPC {
report.Append("Chip ID: 0x");
report.AppendLine(chip.ToString("X"));
report.Append("Chip revision: 0x");
report.AppendLine(revision.ToString("X", CultureInfo.InvariantCulture));
report.AppendLine(revision.ToString("X",
CultureInfo.InvariantCulture));
report.AppendLine("Error: Address verification failed");
report.AppendLine();
return;
return false;
}
// some Fintek chips have address register offset 0x05 added already
@@ -272,11 +275,13 @@ namespace OpenHardwareMonitor.Hardware.LPC {
report.Append("Chip ID: 0x");
report.AppendLine(chip.ToString("X"));
report.Append("Chip revision: 0x");
report.AppendLine(revision.ToString("X", CultureInfo.InvariantCulture));
report.AppendLine(revision.ToString("X",
CultureInfo.InvariantCulture));
report.Append("Error: Invalid address 0x");
report.AppendLine(address.ToString("X", CultureInfo.InvariantCulture));
report.AppendLine(address.ToString("X",
CultureInfo.InvariantCulture));
report.AppendLine();
return;
return false;
}
switch (chip) {
@@ -300,23 +305,30 @@ namespace OpenHardwareMonitor.Hardware.LPC {
report.Append("Chip ID: 0x");
report.AppendLine(chip.ToString("X"));
report.Append("Chip revision: 0x");
report.AppendLine(revision.ToString("X", CultureInfo.InvariantCulture));
report.AppendLine(revision.ToString("X",
CultureInfo.InvariantCulture));
report.Append("Error: Invalid vendor ID 0x");
report.AppendLine(vendorID.ToString("X", CultureInfo.InvariantCulture));
report.AppendLine(vendorID.ToString("X",
CultureInfo.InvariantCulture));
report.AppendLine();
return;
return false;
}
superIOs.Add(new F718XX(chip, address));
break;
default: break;
}
return;
return true;
}
return false;
}
private bool DetectIT87() {
IT87Enter();
ushort chipID = ReadWord(CHIP_ID_REGISTER);
Chip chip;
switch (chipID) {
case 0x8712: chip = Chip.IT8712F; break;
case 0x8716: chip = Chip.IT8716F; break;
@@ -329,9 +341,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
if (chipID != 0 && chipID != 0xffff) {
IT87Exit();
report.Append("Chip ID: Unknown ITE with ID 0x");
report.AppendLine(chipID.ToString("X", CultureInfo.InvariantCulture));
report.AppendLine();
ReportUnknownChip("ITE", chipID);
}
} else {
Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
@@ -347,19 +357,24 @@ namespace OpenHardwareMonitor.Hardware.LPC {
report.Append("Chip ID: 0x");
report.AppendLine(chip.ToString("X"));
report.Append("Error: Invalid address 0x");
report.AppendLine(address.ToString("X", CultureInfo.InvariantCulture));
report.AppendLine(address.ToString("X",
CultureInfo.InvariantCulture));
report.AppendLine();
return;
return false;
}
superIOs.Add(new IT87XX(chip, address, version));
return;
return true;
}
return false;
}
private bool DetectSMSC() {
SMSCEnter();
chipID = ReadWord(CHIP_ID_REGISTER);
ushort chipID = ReadWord(CHIP_ID_REGISTER);
Chip chip;
switch (chipID) {
default: chip = Chip.Unknown; break;
}
@@ -367,15 +382,27 @@ namespace OpenHardwareMonitor.Hardware.LPC {
if (chipID != 0 && chipID != 0xffff) {
SMSCExit();
report.Append("Chip ID: Unknown SMSC with ID 0x");
report.AppendLine(chipID.ToString("X", CultureInfo.InvariantCulture));
report.AppendLine();
ReportUnknownChip("SMSC", chipID);
}
} else {
SMSCExit();
return;
return true;
}
return false;
}
private void Detect() {
for (int i = 0; i < REGISTER_PORTS.Length; i++) {
registerPort = REGISTER_PORTS[i];
valuePort = VALUE_PORTS[i];
if (DetectWinbondFintek()) continue;
if (DetectIT87()) continue;
if (DetectSMSC()) continue;
}
}

View File

@@ -178,7 +178,7 @@ namespace OpenHardwareMonitor.Hardware.LPC {
return vendorId == WINBOND_VENDOR_ID;
}
private ulong SetBit(ulong target, int bit, int value) {
private static ulong SetBit(ulong target, int bit, int value) {
if ((value & 1) != value)
throw new ArgumentException("Value must be one bit only.");

View File

@@ -53,8 +53,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
this.smbios = new SMBIOS();
if (smbios.Board != null) {
if (smbios.Board.ProductName != null
&& smbios.Board.ProductName != "") {
if (!string.IsNullOrEmpty(smbios.Board.ProductName)) {
if (smbios.Board.Manufacturer == Manufacturer.Unknown)
this.name = smbios.Board.ProductName;
else
@@ -131,7 +130,8 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
#pragma warning restore 67
public void Accept(IVisitor visitor) {
if (visitor != null)
if (visitor == null)
throw new ArgumentNullException("visitor");
visitor.VisitHardware(this);
}

View File

@@ -51,7 +51,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
private BIOSInformation biosInformation = null;
private BaseBoardInformation baseBoardInformation = null;
private string ReadSysFS(string path) {
private static string ReadSysFS(string path) {
try {
if (File.Exists(path)) {
using (StreamReader reader = new StreamReader(path))
@@ -85,9 +85,12 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
raw = null;
try {
ManagementObjectCollection collection =
ManagementObjectCollection collection;
using (ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\WMI",
"SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
"SELECT SMBiosData FROM MSSMBios_RawSMBiosTables")) {
collection = searcher.Get();
}
foreach (ManagementObject mo in collection) {
raw = (byte[])mo["SMBiosData"];
@@ -144,17 +147,19 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
public string GetReport() {
StringBuilder r = new StringBuilder();
if (biosInformation != null) {
r.Append("BIOS Vendor: "); r.AppendLine(biosInformation.Vendor);
r.Append("BIOS Version: "); r.AppendLine(biosInformation.Version);
if (BIOS != null) {
r.Append("BIOS Vendor: "); r.AppendLine(BIOS.Vendor);
r.Append("BIOS Version: "); r.AppendLine(BIOS.Version);
r.AppendLine();
}
if (baseBoardInformation != null) {
if (Board != null) {
r.Append("Mainboard Manufacturer: ");
r.AppendLine(baseBoardInformation.ManufacturerName);
r.AppendLine(Board.ManufacturerName);
r.Append("Mainboard Name: ");
r.AppendLine(baseBoardInformation.ProductName);
r.AppendLine(Board.ProductName);
r.Append("Mainboard Version: ");
r.AppendLine(Board.Version);
r.AppendLine();
}
@@ -249,10 +254,10 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
private Manufacturer manufacturer;
private Model model;
private void SetManufacturerName(string manufacturerName) {
this.manufacturerName = manufacturerName;
private void SetManufacturerName(string name) {
this.manufacturerName = name;
switch (manufacturerName) {
switch (name) {
case "ASRock":
manufacturer = Manufacturer.ASRock; break;
case "ASUSTeK Computer INC.":
@@ -286,10 +291,10 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
}
}
private void SetProductName(string productName) {
this.productName = productName;
private void SetProductName(string name) {
this.productName = name;
switch (productName) {
switch (name) {
case "880GMH/USB3":
model = Model._880GMH_USB3; break;
case "Crosshair III Formula":

View File

@@ -44,39 +44,18 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
internal class SuperIOHardware : Hardware {
private ISuperIO superIO;
protected readonly string name;
private string name;
private List<Sensor> voltages = new List<Sensor>();
private List<Sensor> temperatures = new List<Sensor>();
private List<Sensor> fans = new List<Sensor>();
public SuperIOHardware(ISuperIO superIO, Manufacturer manufacturer,
Model model, ISettings settings)
{
this.superIO = superIO;
switch (superIO.Chip) {
case Chip.F71858: name = "Fintek F71858"; break;
case Chip.F71862: name = "Fintek F71862"; break;
case Chip.F71869: name = "Fintek F71869"; break;
case Chip.F71882: name = "Fintek F71882"; break;
case Chip.F71889ED: name = "Fintek F71889ED"; break;
case Chip.F71889F: name = "Fintek F71889F"; break;
case Chip.IT8712F: this.name = "ITE IT8712F"; break;
case Chip.IT8716F: this.name = "ITE IT8716F"; break;
case Chip.IT8718F: this.name = "ITE IT8718F"; break;
case Chip.IT8720F: this.name = "ITE IT8720F"; break;
case Chip.IT8726F: this.name = "ITE IT8726F"; break;
case Chip.W83627DHG: this.name = "Winbond W83627DHG"; break;
case Chip.W83627DHGP: this.name = "Winbond W83627DHG-P"; break;
case Chip.W83627EHF: this.name = "Winbond W83627EHF"; break;
case Chip.W83627HF: this.name = "Winbond W83627HF"; break;
case Chip.W83627THF: this.name = "Winbond W83627THF"; break;
case Chip.W83667HG: this.name = "Winbond W83667HG"; break;
case Chip.W83667HGB: this.name = "Winbond W83667HG-B"; break;
case Chip.W83687THF: this.name = "Winbond W83687THF"; break;
case Chip.Unknown: this.name = "Unkown"; break;
}
this.name = ChipName.GetName(superIO.Chip);
List<Voltage> v = new List<Voltage>();
List<Temperature> t = new List<Temperature>();
@@ -483,7 +462,6 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
v.Add(new Voltage("Standby +3.3V", 7, 34, 34, 0));
v.Add(new Voltage("VBAT", 8, 34, 34, 0));
t.Add(new Temperature("CPU", 0));
t.Add(new Temperature("Auxiliary", 1, true));
t.Add(new Temperature("Motherboard", 2));
f.Add(new Fan("Chassis Fan #1", 0));
f.Add(new Fan("CPU Fan", 1));
@@ -673,15 +651,10 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
private class Temperature {
public readonly string Name;
public readonly int Index;
public readonly bool Hidden;
public Temperature(string name, int index) :
this(name, index, false) { }
public Temperature(string name, int index, bool hidden) {
public Temperature(string name, int index) {
this.Name = name;
this.Index = index;
this.Hidden = hidden;
}
}

View File

@@ -312,6 +312,8 @@ namespace OpenHardwareMonitor.Hardware.Nvidia {
public static readonly NvAPI_GetDisplayDriverVersionDelegate
NvAPI_GetDisplayDriverVersion;
private NVAPI() { }
public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle,
out string name) {
StringBuilder builder = new StringBuilder(SHORT_STRING_MAX);

View File

@@ -239,7 +239,8 @@ namespace OpenHardwareMonitor.Hardware.Nvidia {
r.Append("Driver Version: ");
r.Append(driverVersion.DriverVersion / 100);
r.Append(".");
r.Append((driverVersion.DriverVersion % 100).ToString("00", CultureInfo.InvariantCulture));
r.Append((driverVersion.DriverVersion % 100).ToString("00",
CultureInfo.InvariantCulture));
r.AppendLine();
r.Append("Driver Branch: ");
r.AppendLine(driverVersion.BuildBranch);

View File

@@ -45,25 +45,15 @@ namespace OpenHardwareMonitor.Hardware {
internal sealed class PInvokeDelegateFactory {
private static AssemblyBuilder assemblyBuilder;
private static ModuleBuilder moduleBuilder;
private static ModuleBuilder moduleBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(
new AssemblyName("PInvokeDelegateFactoryInternalAssembly"),
AssemblyBuilderAccess.Run).DefineDynamicModule(
"PInvokeDelegateFactoryInternalModule");
private static IDictionary<DllImportAttribute, Type> wrapperTypes =
new Dictionary<DllImportAttribute, Type>();
static PInvokeDelegateFactory() {
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "PInvokeDelegateFactoryInternalAssembly";
assemblyBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName,
AssemblyBuilderAccess.Run);
moduleBuilder = assemblyBuilder.DefineDynamicModule(
"PInvokeDelegateFactoryInternalModule");
}
private PInvokeDelegateFactory() { }
public static void CreateDelegate<T>(DllImportAttribute dllImportAttribute,

View File

@@ -41,7 +41,7 @@ using System.Collections.Generic;
namespace OpenHardwareMonitor.Hardware {
public struct ParameterDescription {
internal struct ParameterDescription {
private string name;
private string description;
private float defaultValue;
@@ -60,7 +60,7 @@ namespace OpenHardwareMonitor.Hardware {
public float DefaultValue { get { return defaultValue; } }
}
public class Parameter : IParameter {
internal class Parameter : IParameter {
private ISensor sensor;
private ParameterDescription description;
private float value;
@@ -129,7 +129,8 @@ namespace OpenHardwareMonitor.Hardware {
}
public void Accept(IVisitor visitor) {
if (visitor != null)
if (visitor == null)
throw new ArgumentNullException("visitor");
visitor.VisitParameter(this);
}

View File

@@ -51,9 +51,9 @@ namespace OpenHardwareMonitor.Hardware {
private SensorType sensorType;
private IHardware hardware;
private ReadOnlyArray<IParameter> parameters;
private float? value;
private float? min;
private float? max;
private float? currentValue;
private float? minValue;
private float? maxValue;
private Queue<SensorValue> values =
new Queue<SensorValue>(MAX_MINUTES * 15);
private ISettings settings;
@@ -114,7 +114,7 @@ namespace OpenHardwareMonitor.Hardware {
return name;
}
set {
if (value != "")
if (!string.IsNullOrEmpty(value))
name = value;
else
name = defaultName;
@@ -136,7 +136,7 @@ namespace OpenHardwareMonitor.Hardware {
public float? Value {
get {
return value;
return currentValue;
}
set {
while (values.Count > 0 &&
@@ -153,23 +153,23 @@ namespace OpenHardwareMonitor.Hardware {
}
}
this.value = value;
if (min > value || !min.HasValue)
min = value;
if (max < value || !max.HasValue)
max = value;
this.currentValue = value;
if (minValue > value || !minValue.HasValue)
minValue = value;
if (maxValue < value || !maxValue.HasValue)
maxValue = value;
}
}
public float? Min { get { return min; } }
public float? Max { get { return max; } }
public float? Min { get { return minValue; } }
public float? Max { get { return maxValue; } }
public void ResetMin() {
min = null;
minValue = null;
}
public void ResetMax() {
max = null;
maxValue = null;
}
public IEnumerable<SensorValue> Values {
@@ -177,7 +177,8 @@ namespace OpenHardwareMonitor.Hardware {
}
public void Accept(IVisitor visitor) {
if (visitor != null)
if (visitor == null)
throw new ArgumentNullException("visitor");
visitor.VisitSensor(this);
}

View File

@@ -45,14 +45,20 @@ namespace OpenHardwareMonitor.Hardware {
private SensorEventHandler handler;
public SensorVisitor(SensorEventHandler handler) {
if (handler == null)
throw new ArgumentNullException("handler");
this.handler = handler;
}
public void VisitComputer(IComputer computer) {
if (computer == null)
throw new ArgumentNullException("computer");
computer.Traverse(this);
}
public void VisitHardware(IHardware hardware) {
if (hardware == null)
throw new ArgumentNullException("hardware");
hardware.Traverse(this);
}

View File

@@ -128,18 +128,44 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
public delegate FT_STATUS FT_ReadDelegate(FT_HANDLE handle,
[Out] byte[] buffer, uint bytesToRead, out uint bytesReturned);
public static FT_CreateDeviceInfoListDelegate FT_CreateDeviceInfoList;
public static FT_GetDeviceInfoListDelegate FT_GetDeviceInfoList;
public static FT_OpenDelegate FT_Open;
public static FT_CloseDelegate FT_Close;
public static FT_SetBaudRateDelegate FT_SetBaudRate;
public static FT_SetDataCharacteristicsDelegate FT_SetDataCharacteristics;
public static FT_SetFlowControlDelegate FT_SetFlowControl;
public static FT_SetTimeoutsDelegate FT_SetTimeouts;
public static FT_WriteDelegate FT_Write;
public static FT_PurgeDelegate FT_Purge;
public static FT_GetStatusDelegate FT_GetStatus;
public static FT_ReadDelegate FT_Read;
public static readonly FT_CreateDeviceInfoListDelegate
FT_CreateDeviceInfoList = CreateDelegate<
FT_CreateDeviceInfoListDelegate>("FT_CreateDeviceInfoList");
public static readonly FT_GetDeviceInfoListDelegate
FT_GetDeviceInfoList = CreateDelegate<
FT_GetDeviceInfoListDelegate>("FT_GetDeviceInfoList");
public static readonly FT_OpenDelegate
FT_Open = CreateDelegate<
FT_OpenDelegate>("FT_Open");
public static readonly FT_CloseDelegate
FT_Close = CreateDelegate<
FT_CloseDelegate>("FT_Close");
public static readonly FT_SetBaudRateDelegate
FT_SetBaudRate = CreateDelegate<
FT_SetBaudRateDelegate>("FT_SetBaudRate");
public static readonly FT_SetDataCharacteristicsDelegate
FT_SetDataCharacteristics = CreateDelegate<
FT_SetDataCharacteristicsDelegate>("FT_SetDataCharacteristics");
public static readonly FT_SetFlowControlDelegate
FT_SetFlowControl = CreateDelegate<
FT_SetFlowControlDelegate>("FT_SetFlowControl");
public static readonly FT_SetTimeoutsDelegate
FT_SetTimeouts = CreateDelegate<
FT_SetTimeoutsDelegate>("FT_SetTimeouts");
public static readonly FT_WriteDelegate
FT_Write = CreateDelegate<
FT_WriteDelegate>("FT_Write");
public static readonly FT_PurgeDelegate
FT_Purge = CreateDelegate<
FT_PurgeDelegate>("FT_Purge");
public static readonly FT_GetStatusDelegate
FT_GetStatus = CreateDelegate<
FT_GetStatusDelegate>("FT_GetStatus");
public static readonly FT_ReadDelegate
FT_Read = CreateDelegate<
FT_ReadDelegate>("FT_Read");
private FTD2XX() { }
public static FT_STATUS Write(FT_HANDLE handle, byte[] buffer) {
uint bytesWritten;
@@ -168,40 +194,27 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
uint bytesReturned;
FT_STATUS status = FT_Read(handle, buffer, 1, out bytesReturned);
if (status != FT_STATUS.FT_OK || bytesReturned != 1)
throw new Exception();
throw new InvalidOperationException();
return buffer[0];
}
private static string dllName;
private static string GetDllName() {
int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128))
return "libftd2xx.so";
else
return "ftd2xx.dll";
}
private static void GetDelegate<T>(string entryPoint, out T newDelegate)
private static T CreateDelegate<T>(string entryPoint)
where T : class {
DllImportAttribute attribute = new DllImportAttribute(dllName);
DllImportAttribute attribute = new DllImportAttribute(GetDllName());
attribute.CallingConvention = CallingConvention.StdCall;
attribute.PreserveSig = true;
attribute.EntryPoint = entryPoint;
T newDelegate;
PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate);
}
static FTD2XX() {
int p = (int)System.Environment.OSVersion.Platform;
if ((p == 4) || (p == 128))
dllName = "libftd2xx.so";
else
dllName = "ftd2xx.dll";
GetDelegate("FT_CreateDeviceInfoList", out FT_CreateDeviceInfoList);
GetDelegate("FT_GetDeviceInfoList", out FT_GetDeviceInfoList);
GetDelegate("FT_Open", out FT_Open);
GetDelegate("FT_Close", out FT_Close);
GetDelegate("FT_SetBaudRate", out FT_SetBaudRate);
GetDelegate("FT_SetDataCharacteristics", out FT_SetDataCharacteristics);
GetDelegate("FT_SetFlowControl", out FT_SetFlowControl);
GetDelegate("FT_SetTimeouts", out FT_SetTimeouts);
GetDelegate("FT_Write", out FT_Write);
GetDelegate("FT_Purge", out FT_Purge);
GetDelegate("FT_GetStatus", out FT_GetStatus);
GetDelegate("FT_Read", out FT_Read);
return newDelegate;
}
}
}

View File

@@ -161,8 +161,6 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
}
for (int i = 0; i < 2; i++) {
float maxRPM = 20.0f * data[offset + 44 + 2 * i];
if (miniNGFans[number * 2 + i] == null)
miniNGFans[number * 2 + i] =
new Sensor("miniNG #" + (number + 1) + " Fan Channel " + (i + 1),
@@ -376,7 +374,8 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
public event SensorEventHandler SensorRemoved;
public void Accept(IVisitor visitor) {
if (visitor != null)
if (visitor == null)
throw new ArgumentNullException("visitor");
visitor.VisitHardware(this);
}

View File

@@ -45,6 +45,8 @@ namespace OpenHardwareMonitor.Hardware {
internal class WinRing0 {
private WinRing0() { }
public enum OlsDllStatus{
OLS_DLL_NO_ERROR = 0,
OLS_DLL_UNSUPPORTED_PLATFORM = 1,
@@ -56,7 +58,7 @@ namespace OpenHardwareMonitor.Hardware {
}
private static bool available = false;
public static Mutex isaBusMutex;
private static Mutex isaBusMutex;
private static string GetDllName() {
int p = (int)System.Environment.OSVersion.Platform;
@@ -78,10 +80,7 @@ namespace OpenHardwareMonitor.Hardware {
private delegate bool InitializeOlsDelegate();
private delegate void DeinitializeOlsDelegate();
public delegate uint GetDllStatusDelegate();
public delegate bool IsCpuidDelegate();
public delegate bool CpuidDelegate(uint index, uint ecxValue,
out uint eax, out uint ebx, out uint ecx, out uint edx);
public delegate bool CpuidTxDelegate(uint index, uint ecxValue,
out uint eax, out uint ebx, out uint ecx, out uint edx,
UIntPtr threadAffinityMask);
@@ -90,7 +89,6 @@ namespace OpenHardwareMonitor.Hardware {
UIntPtr threadAffinityMask);
public delegate byte ReadIoPortByteDelegate(ushort port);
public delegate void WriteIoPortByteDelegate(ushort port, byte value);
public delegate void SetPciMaxBusIndexDelegate(byte max);
public delegate uint FindPciDeviceByIdDelegate(ushort vendorId,
ushort deviceId, byte index);
public delegate bool ReadPciConfigDwordExDelegate(uint pciAddress,
@@ -101,55 +99,46 @@ namespace OpenHardwareMonitor.Hardware {
UIntPtr threadAffinityMask);
public delegate bool RdtscDelegate(out uint eax, out uint edx);
private static InitializeOlsDelegate InitializeOls;
private static DeinitializeOlsDelegate DeinitializeOls;
private static InitializeOlsDelegate InitializeOls =
CreateDelegate<InitializeOlsDelegate>("InitializeOls");
private static DeinitializeOlsDelegate DeinitializeOls =
CreateDelegate<DeinitializeOlsDelegate>("DeinitializeOls");
public static readonly GetDllStatusDelegate GetDllStatus;
public static readonly IsCpuidDelegate IsCpuid;
public static readonly CpuidDelegate Cpuid;
public static readonly CpuidTxDelegate CpuidTx;
public static readonly RdmsrDelegate Rdmsr;
public static readonly RdmsrTxDelegate RdmsrTx;
public static readonly ReadIoPortByteDelegate ReadIoPortByte;
public static readonly WriteIoPortByteDelegate WriteIoPortByte;
public static readonly SetPciMaxBusIndexDelegate SetPciMaxBusIndex;
public static readonly FindPciDeviceByIdDelegate FindPciDeviceById;
public static readonly ReadPciConfigDwordExDelegate ReadPciConfigDwordEx;
public static readonly WritePciConfigDwordExDelegate WritePciConfigDwordEx;
public static readonly RdtscTxDelegate RdtscTx;
public static readonly RdtscDelegate Rdtsc;
public static readonly IsCpuidDelegate IsCpuid =
CreateDelegate<IsCpuidDelegate>("IsCpuid");
public static readonly CpuidTxDelegate CpuidTx =
CreateDelegate<CpuidTxDelegate>("CpuidTx");
public static readonly RdmsrDelegate Rdmsr =
CreateDelegate<RdmsrDelegate>("Rdmsr");
public static readonly RdmsrTxDelegate RdmsrTx =
CreateDelegate<RdmsrTxDelegate>("RdmsrTx");
public static readonly ReadIoPortByteDelegate ReadIoPortByte =
CreateDelegate<ReadIoPortByteDelegate>("ReadIoPortByte");
public static readonly WriteIoPortByteDelegate WriteIoPortByte =
CreateDelegate<WriteIoPortByteDelegate>("WriteIoPortByte");
public static readonly FindPciDeviceByIdDelegate FindPciDeviceById =
CreateDelegate<FindPciDeviceByIdDelegate>("FindPciDeviceById");
public static readonly ReadPciConfigDwordExDelegate ReadPciConfigDwordEx =
CreateDelegate<ReadPciConfigDwordExDelegate>("ReadPciConfigDwordEx");
public static readonly WritePciConfigDwordExDelegate WritePciConfigDwordEx =
CreateDelegate<WritePciConfigDwordExDelegate>("WritePciConfigDwordEx");
public static readonly RdtscTxDelegate RdtscTx =
CreateDelegate<RdtscTxDelegate>("RdtscTx");
public static readonly RdtscDelegate Rdtsc =
CreateDelegate<RdtscDelegate>("Rdtsc");
private static void GetDelegate<T>(string entryPoint, out T newDelegate)
where T : class
{
private static T CreateDelegate<T>(string entryPoint) where T : class {
DllImportAttribute attribute = new DllImportAttribute(GetDllName());
attribute.CallingConvention = CallingConvention.Winapi;
attribute.PreserveSig = true;
attribute.EntryPoint = entryPoint;
attribute.CharSet = CharSet.Auto;
PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate);
T result;
PInvokeDelegateFactory.CreateDelegate(attribute, out result);
return result;
}
static WinRing0() {
GetDelegate("InitializeOls", out InitializeOls);
GetDelegate("DeinitializeOls", out DeinitializeOls);
GetDelegate("GetDllStatus", out GetDllStatus);
GetDelegate("IsCpuid", out IsCpuid);
GetDelegate("Cpuid", out Cpuid);
GetDelegate("CpuidTx", out CpuidTx);
GetDelegate("Rdmsr", out Rdmsr);
GetDelegate("RdmsrTx", out RdmsrTx);
GetDelegate("ReadIoPortByte", out ReadIoPortByte);
GetDelegate("WriteIoPortByte", out WriteIoPortByte);
GetDelegate("SetPciMaxBusIndex", out SetPciMaxBusIndex);
GetDelegate("FindPciDeviceById", out FindPciDeviceById);
GetDelegate("ReadPciConfigDwordEx", out ReadPciConfigDwordEx);
GetDelegate("WritePciConfigDwordEx", out WritePciConfigDwordEx);
GetDelegate("RdtscTx", out RdtscTx);
GetDelegate("Rdtsc", out Rdtsc);
public static void Open() {
try {
if (InitializeOls != null && InitializeOls())
available = true;
@@ -162,24 +151,21 @@ namespace OpenHardwareMonitor.Hardware {
get { return available; }
}
public static void Close() {
if (available)
DeinitializeOls();
isaBusMutex.Close();
}
public static bool WaitIsaBusMutex(int millisecondsTimeout) {
try {
return isaBusMutex.WaitOne(millisecondsTimeout);
} catch { return false; }
return isaBusMutex.WaitOne(millisecondsTimeout, false);
} catch (AbandonedMutexException) { return false; }
catch (InvalidOperationException) { return false; }
}
public static void ReleaseIsaBusMutex() {
isaBusMutex.ReleaseMutex();
}
private static Deinitializer deinitializer = new Deinitializer();
private class Deinitializer {
~Deinitializer() {
if (available)
DeinitializeOls();
isaBusMutex.Close();
}
}
}
}

View File

@@ -41,6 +41,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>

View File

@@ -51,3 +51,4 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]