Fixed some Code Analysis warnings.
1.1 --- a/Collections/ListSet.cs Thu Aug 12 20:53:27 2010 +0000
1.2 +++ b/Collections/ListSet.cs Sun Aug 15 14:46:58 2010 +0000
1.3 @@ -41,6 +41,7 @@
1.4 using System.Text;
1.5
1.6 namespace OpenHardwareMonitor.Collections {
1.7 +
1.8 public class ListSet<T> : IEnumerable<T> {
1.9
1.10 private List<T> list = new List<T>();
2.1 --- a/Collections/ReadOnlyArray.cs Thu Aug 12 20:53:27 2010 +0000
2.2 +++ b/Collections/ReadOnlyArray.cs Sun Aug 15 14:46:58 2010 +0000
2.3 @@ -66,5 +66,9 @@
2.4 public static implicit operator ReadOnlyArray<T>(T[] array) {
2.5 return new ReadOnlyArray<T>(array);
2.6 }
2.7 +
2.8 + public T[] ToArray() {
2.9 + return (T[])array.Clone();
2.10 + }
2.11 }
2.12 }
3.1 --- a/GUI/Node.cs Thu Aug 12 20:53:27 2010 +0000
3.2 +++ b/GUI/Node.cs Sun Aug 15 14:46:58 2010 +0000
3.3 @@ -159,7 +159,7 @@
3.4
3.5 protected override void InsertItem(int index, Node item) {
3.6 if (item == null)
3.7 - throw new ArgumentNullException();
3.8 + throw new ArgumentNullException("item");
3.9
3.10 if (item.parent != owner) {
3.11 if (item.parent != null)
3.12 @@ -189,7 +189,7 @@
3.13
3.14 protected override void SetItem(int index, Node item) {
3.15 if (item == null)
3.16 - throw new ArgumentNullException();
3.17 + throw new ArgumentNullException("item");
3.18
3.19 RemoveAt(index);
3.20 InsertItem(index, item);
4.1 --- a/Hardware/ATI/ADL.cs Thu Aug 12 20:53:27 2010 +0000
4.2 +++ b/Hardware/ATI/ADL.cs Sun Aug 15 14:46:58 2010 +0000
4.3 @@ -156,7 +156,7 @@
4.4 private static ADL_Adapter_AdapterInfo_GetDelegate
4.5 _ADL_Adapter_AdapterInfo_Get;
4.6
4.7 - public static ADL_Main_Control_DestroyDelegate
4.8 + public static ADL_Main_Control_DestroyDelegate
4.9 ADL_Main_Control_Destroy;
4.10 public static ADL_Adapter_NumberOfAdapters_GetDelegate
4.11 ADL_Adapter_NumberOfAdapters_Get;
5.1 --- a/Hardware/ATI/ATIGroup.cs Thu Aug 12 20:53:27 2010 +0000
5.2 +++ b/Hardware/ATI/ATIGroup.cs Sun Aug 15 14:46:58 2010 +0000
5.3 @@ -104,7 +104,7 @@
5.4 report.Append("AdapterID: 0x");
5.5 report.AppendLine(adapterID.ToString("X", CultureInfo.InvariantCulture));
5.6
5.7 - if (adapterID != 0 && adapterInfo[i].UDID != "" &&
5.8 + if (adapterID != 0 && !string.IsNullOrEmpty(adapterInfo[i].UDID) &&
5.9 (adapterInfo[i].VendorID == ADL.ATI_VENDOR_ID1 ||
5.10 adapterInfo[i].VendorID == ADL.ATI_VENDOR_ID2)) {
5.11 bool found = false;
6.1 --- a/Hardware/CPU/CPUGroup.cs Thu Aug 12 20:53:27 2010 +0000
6.2 +++ b/Hardware/CPU/CPUGroup.cs Sun Aug 15 14:46:58 2010 +0000
6.3 @@ -48,13 +48,13 @@
6.4
6.5 private CPUID[][][] threads;
6.6
6.7 - private CPUID[][] GetProcessorThreads() {
6.8 + private static CPUID[][] GetProcessorThreads() {
6.9
6.10 List<CPUID> threads = new List<CPUID>();
6.11 for (int i = 0; i < 32; i++) {
6.12 try {
6.13 threads.Add(new CPUID(i));
6.14 - } catch (ArgumentException) { }
6.15 + } catch (ArgumentOutOfRangeException) { }
6.16 }
6.17
6.18 SortedDictionary<uint, List<CPUID>> processors =
6.19 @@ -78,7 +78,7 @@
6.20 return processorThreads;
6.21 }
6.22
6.23 - private CPUID[][] GroupThreadsByCore(CPUID[] threads) {
6.24 + private static CPUID[][] GroupThreadsByCore(CPUID[] threads) {
6.25
6.26 SortedDictionary<uint, List<CPUID>> cores =
6.27 new SortedDictionary<uint, List<CPUID>>();
6.28 @@ -151,7 +151,9 @@
6.29 }
6.30 }
6.31
6.32 - private void AppendCpuidData(StringBuilder r, uint[,] data, uint offset) {
6.33 + private static void AppendCpuidData(StringBuilder r, uint[,] data,
6.34 + uint offset)
6.35 + {
6.36 for (int i = 0; i < data.GetLength(0); i++) {
6.37 r.Append(" ");
6.38 r.Append((i + offset).ToString("X8", CultureInfo.InvariantCulture));
7.1 --- a/Hardware/CPU/CPUID.cs Thu Aug 12 20:53:27 2010 +0000
7.2 +++ b/Hardware/CPU/CPUID.cs Sun Aug 15 14:46:58 2010 +0000
7.3 @@ -75,14 +75,14 @@
7.4 public static uint CPUID_0 = 0;
7.5 public static uint CPUID_EXT = 0x80000000;
7.6
7.7 - private void AppendRegister(StringBuilder b, uint value) {
7.8 + private static void AppendRegister(StringBuilder b, uint value) {
7.9 b.Append((char)((value) & 0xff));
7.10 b.Append((char)((value >> 8) & 0xff));
7.11 b.Append((char)((value >> 16) & 0xff));
7.12 b.Append((char)((value >> 24) & 0xff));
7.13 }
7.14
7.15 - private uint NextLog2(long x) {
7.16 + private static uint NextLog2(long x) {
7.17 if (x <= 0)
7.18 return 0;
7.19
7.20 @@ -105,7 +105,7 @@
7.21 uint eax, ebx, ecx, edx;
7.22
7.23 if (thread >= 32)
7.24 - throw new ArgumentException();
7.25 + throw new ArgumentOutOfRangeException("thread");
7.26 UIntPtr mask = (UIntPtr)(1L << thread);
7.27
7.28 if (WinRing0.CpuidTx(CPUID_0, 0,
7.29 @@ -139,10 +139,10 @@
7.30 else
7.31 return;
7.32 } else {
7.33 - throw new ArgumentException();
7.34 + throw new ArgumentOutOfRangeException("thread");
7.35 }
7.36 } else {
7.37 - throw new ArgumentException();
7.38 + throw new ArgumentOutOfRangeException("thread");
7.39 }
7.40
7.41 maxCpuid = Math.Min(maxCpuid, 1024);
8.1 --- a/Hardware/CPU/CPULoad.cs Thu Aug 12 20:53:27 2010 +0000
8.2 +++ b/Hardware/CPU/CPULoad.cs Sun Aug 15 14:46:58 2010 +0000
8.3 @@ -62,12 +62,6 @@
8.4 SystemProcessorPerformanceInformation = 8
8.5 }
8.6
8.7 - [DllImport("ntdll.dll")]
8.8 - private static extern int NtQuerySystemInformation(
8.9 - SystemInformationClass informationClass,
8.10 - [Out] SystemProcessorPerformanceInformation[] informations,
8.11 - int structSize, out IntPtr returnLength);
8.12 -
8.13 private CPUID[][] cpuid;
8.14
8.15 private long systemTime;
8.16 @@ -78,16 +72,17 @@
8.17
8.18 private bool available = false;
8.19
8.20 - private long[] GetIdleTimes() {
8.21 + private static long[] GetIdleTimes() {
8.22 SystemProcessorPerformanceInformation[] informations = new
8.23 SystemProcessorPerformanceInformation[64];
8.24
8.25 int size = Marshal.SizeOf(typeof(SystemProcessorPerformanceInformation));
8.26
8.27 IntPtr returnLength;
8.28 - NtQuerySystemInformation(
8.29 + if (NativeMethods.NtQuerySystemInformation(
8.30 SystemInformationClass.SystemProcessorPerformanceInformation,
8.31 - informations, informations.Length * size, out returnLength);
8.32 + informations, informations.Length * size, out returnLength) != 0)
8.33 + return null;
8.34
8.35 long[] result = new long[(int)returnLength / size];
8.36
8.37 @@ -127,10 +122,13 @@
8.38 if (this.idleTimes == null)
8.39 return;
8.40
8.41 - long localSystemTime = DateTime.Now.Ticks;
8.42 - long[] localIdleTimes = GetIdleTimes();
8.43 + long newSystemTime = DateTime.Now.Ticks;
8.44 + long[] newIdleTimes = GetIdleTimes();
8.45
8.46 - if (localSystemTime - this.systemTime < 10000)
8.47 + if (newSystemTime - this.systemTime < 10000)
8.48 + return;
8.49 +
8.50 + if (newIdleTimes == null)
8.51 return;
8.52
8.53 float total = 0;
8.54 @@ -139,29 +137,37 @@
8.55 float value = 0;
8.56 for (int j = 0; j < cpuid[i].Length; j++) {
8.57 long index = cpuid[i][j].Thread;
8.58 - if (index < localIdleTimes.Length) {
8.59 - long delta = localIdleTimes[index] - this.idleTimes[index];
8.60 + if (index < newIdleTimes.Length) {
8.61 + long delta = newIdleTimes[index] - this.idleTimes[index];
8.62 value += delta;
8.63 total += delta;
8.64 count++;
8.65 }
8.66 }
8.67 value = 1.0f - value / (cpuid[i].Length *
8.68 - (localSystemTime - this.systemTime));
8.69 + (newSystemTime - this.systemTime));
8.70 value = value < 0 ? 0 : value;
8.71 coreLoads[i] = value * 100;
8.72 }
8.73 if (count > 0) {
8.74 - total = 1.0f - total / (count * (localSystemTime - this.systemTime));
8.75 + total = 1.0f - total / (count * (newSystemTime - this.systemTime));
8.76 total = total < 0 ? 0 : total;
8.77 } else {
8.78 total = 0;
8.79 }
8.80 this.totalLoad = total * 100;
8.81
8.82 - this.systemTime = localSystemTime;
8.83 - this.idleTimes = localIdleTimes;
8.84 + this.systemTime = newSystemTime;
8.85 + this.idleTimes = newIdleTimes;
8.86 }
8.87
8.88 + private static class NativeMethods {
8.89 +
8.90 + [DllImport("ntdll.dll")]
8.91 + public static extern int NtQuerySystemInformation(
8.92 + SystemInformationClass informationClass,
8.93 + [Out] SystemProcessorPerformanceInformation[] informations,
8.94 + int structSize, out IntPtr returnLength);
8.95 + }
8.96 }
8.97 }
9.1 --- a/Hardware/CPU/IntelCPU.cs Thu Aug 12 20:53:27 2010 +0000
9.2 +++ b/Hardware/CPU/IntelCPU.cs Sun Aug 15 14:46:58 2010 +0000
9.3 @@ -253,7 +253,7 @@
9.4 get { return HardwareType.CPU; }
9.5 }
9.6
9.7 - private void AppendMSRData(StringBuilder r, uint msr, int thread) {
9.8 + private static void AppendMSRData(StringBuilder r, uint msr, int thread) {
9.9 uint eax, edx;
9.10 if (WinRing0.RdmsrTx(msr, out eax, out edx, (UIntPtr)(1L << thread))) {
9.11 r.Append(" ");
9.12 @@ -298,7 +298,7 @@
9.13 return r.ToString();
9.14 }
9.15
9.16 - private double EstimateMaxClock(double timeWindow) {
9.17 + private static double EstimateMaxClock(double timeWindow) {
9.18 long ticks = (long)(timeWindow * Stopwatch.Frequency);
9.19 uint lsbBegin, msbBegin, lsbEnd, msbEnd;
9.20
9.21 @@ -359,7 +359,7 @@
9.22 else
9.23 maxClock = estimatedMaxClock;
9.24
9.25 - double busClock = 0;
9.26 + double newBusClock = 0;
9.27 uint eax, edx;
9.28 for (int i = 0; i < coreClocks.Length; i++) {
9.29 System.Threading.Thread.Sleep(1);
9.30 @@ -369,7 +369,7 @@
9.31 uint nehalemMultiplier = eax & 0xff;
9.32 coreClocks[i].Value =
9.33 (float)(nehalemMultiplier * maxClock / maxNehalemMultiplier);
9.34 - busClock = (float)(maxClock / maxNehalemMultiplier);
9.35 + newBusClock = (float)(maxClock / maxNehalemMultiplier);
9.36 } else { // Core 2
9.37 uint multiplier = (eax >> 8) & 0x1f;
9.38 uint maxMultiplier = (edx >> 8) & 0x1f;
9.39 @@ -378,7 +378,7 @@
9.40 uint maxFactor = (maxMultiplier << 1) | ((edx >> 14) & 1);
9.41 if (maxFactor > 0) {
9.42 coreClocks[i].Value = (float)(factor * maxClock / maxFactor);
9.43 - busClock = (float)(2 * maxClock / maxFactor);
9.44 + newBusClock = (float)(2 * maxClock / maxFactor);
9.45 }
9.46 }
9.47 } else { // Intel Pentium 4
9.48 @@ -386,8 +386,8 @@
9.49 coreClocks[i].Value = (float)maxClock;
9.50 }
9.51 }
9.52 - if (busClock > 0) {
9.53 - this.busClock.Value = (float)busClock;
9.54 + if (newBusClock > 0) {
9.55 + this.busClock.Value = (float)newBusClock;
9.56 ActivateSensor(this.busClock);
9.57 }
9.58 }
10.1 --- a/Hardware/Computer.cs Thu Aug 12 20:53:27 2010 +0000
10.2 +++ b/Hardware/Computer.cs Sun Aug 15 14:46:58 2010 +0000
10.3 @@ -41,6 +41,9 @@
10.4 using System.Globalization;
10.5 using System.Text;
10.6 using System.Threading;
10.7 +using System.Security;
10.8 +using System.Security.Permissions;
10.9 +
10.10
10.11 namespace OpenHardwareMonitor.Hardware {
10.12
10.13 @@ -86,10 +89,13 @@
10.14 HardwareRemoved(hardware);
10.15 }
10.16
10.17 + [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
10.18 public void Open() {
10.19 if (open)
10.20 return;
10.21
10.22 + WinRing0.Open();
10.23 +
10.24 Add(new Mainboard.MainboardGroup(settings));
10.25 Add(new CPU.CPUGroup(settings));
10.26 Add(new ATI.ATIGroup(settings));
10.27 @@ -101,9 +107,11 @@
10.28
10.29 open = true;
10.30 }
10.31 -
10.32 +
10.33 public bool HDDEnabled {
10.34 get { return hddEnabled; }
10.35 +
10.36 + [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
10.37 set {
10.38 if (open && value && !hddEnabled) {
10.39 Add(new HDD.HDDGroup(settings));
10.40 @@ -129,7 +137,7 @@
10.41 }
10.42 }
10.43
10.44 - private void NewSection(TextWriter writer) {
10.45 + private static void NewSection(TextWriter writer) {
10.46 for (int i = 0; i < 8; i++)
10.47 writer.Write("----------");
10.48 writer.WriteLine();
10.49 @@ -186,7 +194,7 @@
10.50
10.51 private void ReportHardware(IHardware hardware, TextWriter w) {
10.52 string hardwareReport = hardware.GetReport();
10.53 - if (hardwareReport != null && hardwareReport != "") {
10.54 + if (!string.IsNullOrEmpty(hardwareReport)) {
10.55 NewSection(w);
10.56 w.Write(hardwareReport);
10.57 }
10.58 @@ -237,7 +245,7 @@
10.59
10.60 foreach (IGroup group in groups) {
10.61 string report = group.GetReport();
10.62 - if (report != null && report != "") {
10.63 + if (!string.IsNullOrEmpty(report)) {
10.64 NewSection(w);
10.65 w.Write(report);
10.66 }
10.67 @@ -259,6 +267,8 @@
10.68 group.Close();
10.69 groups.Clear();
10.70
10.71 + WinRing0.Close();
10.72 +
10.73 open = false;
10.74 }
10.75
10.76 @@ -266,8 +276,9 @@
10.77 public event HardwareEventHandler HardwareRemoved;
10.78
10.79 public void Accept(IVisitor visitor) {
10.80 - if (visitor != null)
10.81 - visitor.VisitComputer(this);
10.82 + if (visitor == null)
10.83 + throw new ArgumentNullException("visitor");
10.84 + visitor.VisitComputer(this);
10.85 }
10.86
10.87 public void Traverse(IVisitor visitor) {
11.1 --- a/Hardware/HDD/HDD.cs Thu Aug 12 20:53:27 2010 +0000
11.2 +++ b/Hardware/HDD/HDD.cs Sun Aug 15 14:46:58 2010 +0000
11.3 @@ -117,8 +117,9 @@
11.4 #pragma warning restore 67
11.5
11.6 public void Accept(IVisitor visitor) {
11.7 - if (visitor != null)
11.8 - visitor.VisitHardware(this);
11.9 + if (visitor == null)
11.10 + throw new ArgumentNullException("visitor");
11.11 + visitor.VisitHardware(this);
11.12 }
11.13
11.14 public void Traverse(IVisitor visitor) { }
12.1 --- a/Hardware/HDD/SMART.cs Thu Aug 12 20:53:27 2010 +0000
12.2 +++ b/Hardware/HDD/SMART.cs Sun Aug 15 14:46:58 2010 +0000
12.3 @@ -232,37 +232,10 @@
12.4
12.5 private const int MAX_DRIVE_ATTRIBUTES = 512;
12.6
12.7 - private const string KERNEL = "kernel32.dll";
12.8 -
12.9 - [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
12.10 - private static extern IntPtr CreateFile(string fileName,
12.11 - AccessMode desiredAccess, ShareMode shareMode, IntPtr securityAttributes,
12.12 - CreationMode creationDisposition, FileAttribute flagsAndAttributes,
12.13 - IntPtr templateFilehandle);
12.14 -
12.15 - [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
12.16 - public static extern int CloseHandle(IntPtr handle);
12.17 -
12.18 - [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
12.19 - private static extern bool DeviceIoControl(IntPtr handle,
12.20 - DriveCommand command, ref DriveCommandParameter parameter,
12.21 - int parameterSize, out DriveSmartReadResult result, int resultSize,
12.22 - out uint bytesReturned, IntPtr overlapped);
12.23 -
12.24 - [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
12.25 - private static extern bool DeviceIoControl(IntPtr handle,
12.26 - DriveCommand command, ref DriveCommandParameter parameter,
12.27 - int parameterSize, out DriveCommandResult result, int resultSize,
12.28 - out uint bytesReturned, IntPtr overlapped);
12.29 -
12.30 - [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
12.31 - private static extern bool DeviceIoControl(IntPtr handle,
12.32 - DriveCommand command, ref DriveCommandParameter parameter,
12.33 - int parameterSize, out DriveIdentifyResult result, int resultSize,
12.34 - out uint bytesReturned, IntPtr overlapped);
12.35 + private SMART() { }
12.36
12.37 public static IntPtr OpenPhysicalDrive(int driveNumber) {
12.38 - return CreateFile(@"\\.\PhysicalDrive" + driveNumber,
12.39 + return NativeMethods.CreateFile(@"\\.\PhysicalDrive" + driveNumber,
12.40 AccessMode.Read | AccessMode.Write, ShareMode.Read | ShareMode.Write,
12.41 IntPtr.Zero, CreationMode.OpenExisting, FileAttribute.Device,
12.42 IntPtr.Zero);
12.43 @@ -279,8 +252,8 @@
12.44 parameter.Registers.LBAHigh = SMART_LBA_HI;
12.45 parameter.Registers.Command = SMART_CMD;
12.46
12.47 - return DeviceIoControl(handle, DriveCommand.SendDriveCommand,
12.48 - ref parameter, Marshal.SizeOf(parameter), out result,
12.49 + return NativeMethods.DeviceIoControl(handle, DriveCommand.SendDriveCommand,
12.50 + ref parameter, Marshal.SizeOf(typeof(DriveCommandParameter)), out result,
12.51 Marshal.SizeOf(typeof(DriveCommandResult)), out bytesReturned,
12.52 IntPtr.Zero);
12.53 }
12.54 @@ -296,10 +269,10 @@
12.55 parameter.Registers.LBAHigh = SMART_LBA_HI;
12.56 parameter.Registers.Command = SMART_CMD;
12.57
12.58 - bool valid = DeviceIoControl(handle, DriveCommand.ReceiveDriveData,
12.59 - ref parameter, Marshal.SizeOf(parameter), out result,
12.60 - Marshal.SizeOf(typeof(DriveSmartReadResult)), out bytesReturned,
12.61 - IntPtr.Zero);
12.62 + bool valid = NativeMethods.DeviceIoControl(handle,
12.63 + DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
12.64 + out result, Marshal.SizeOf(typeof(DriveSmartReadResult)),
12.65 + out bytesReturned, IntPtr.Zero);
12.66
12.67 if (!valid)
12.68 return null;
12.69 @@ -315,10 +288,10 @@
12.70 parameter.DriveNumber = (byte)driveNumber;
12.71 parameter.Registers.Command = ID_CMD;
12.72
12.73 - bool valid = DeviceIoControl(handle, DriveCommand.ReceiveDriveData,
12.74 - ref parameter, Marshal.SizeOf(parameter), out result,
12.75 - Marshal.SizeOf(typeof(DriveIdentifyResult)), out bytesReturned,
12.76 - IntPtr.Zero);
12.77 + bool valid = NativeMethods.DeviceIoControl(handle,
12.78 + DriveCommand.ReceiveDriveData, ref parameter, Marshal.SizeOf(parameter),
12.79 + out result, Marshal.SizeOf(typeof(DriveIdentifyResult)),
12.80 + out bytesReturned, IntPtr.Zero);
12.81
12.82 if (!valid)
12.83 return null;
12.84 @@ -335,5 +308,43 @@
12.85 }
12.86 }
12.87
12.88 + public static int CloseHandle(IntPtr handle) {
12.89 + return NativeMethods.CloseHandle(handle);
12.90 + }
12.91 +
12.92 + private static class NativeMethods {
12.93 + private const string KERNEL = "kernel32.dll";
12.94 +
12.95 + [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi,
12.96 + CharSet = CharSet.Unicode)]
12.97 + public static extern IntPtr CreateFile(string fileName,
12.98 + AccessMode desiredAccess, ShareMode shareMode, IntPtr securityAttributes,
12.99 + CreationMode creationDisposition, FileAttribute flagsAndAttributes,
12.100 + IntPtr templateFilehandle);
12.101 +
12.102 + [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
12.103 + public static extern int CloseHandle(IntPtr handle);
12.104 +
12.105 + [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
12.106 + [return: MarshalAsAttribute(UnmanagedType.Bool)]
12.107 + public static extern bool DeviceIoControl(IntPtr handle,
12.108 + DriveCommand command, ref DriveCommandParameter parameter,
12.109 + int parameterSize, out DriveSmartReadResult result, int resultSize,
12.110 + out uint bytesReturned, IntPtr overlapped);
12.111 +
12.112 + [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
12.113 + [return: MarshalAsAttribute(UnmanagedType.Bool)]
12.114 + public static extern bool DeviceIoControl(IntPtr handle,
12.115 + DriveCommand command, ref DriveCommandParameter parameter,
12.116 + int parameterSize, out DriveCommandResult result, int resultSize,
12.117 + out uint bytesReturned, IntPtr overlapped);
12.118 +
12.119 + [DllImport(KERNEL, CallingConvention = CallingConvention.Winapi)]
12.120 + [return: MarshalAsAttribute(UnmanagedType.Bool)]
12.121 + public static extern bool DeviceIoControl(IntPtr handle,
12.122 + DriveCommand command, ref DriveCommandParameter parameter,
12.123 + int parameterSize, out DriveIdentifyResult result, int resultSize,
12.124 + out uint bytesReturned, IntPtr overlapped);
12.125 + }
12.126 }
12.127 }
13.1 --- a/Hardware/Hardware.cs Thu Aug 12 20:53:27 2010 +0000
13.2 +++ b/Hardware/Hardware.cs Sun Aug 15 14:46:58 2010 +0000
13.3 @@ -80,8 +80,9 @@
13.4 public abstract void Update();
13.5
13.6 public void Accept(IVisitor visitor) {
13.7 - if (visitor != null)
13.8 - visitor.VisitHardware(this);
13.9 + if (visitor == null)
13.10 + throw new ArgumentNullException("visitor");
13.11 + visitor.VisitHardware(this);
13.12 }
13.13
13.14 public void Traverse(IVisitor visitor) {
14.1 --- a/Hardware/IComputer.cs Thu Aug 12 20:53:27 2010 +0000
14.2 +++ b/Hardware/IComputer.cs Sun Aug 15 14:46:58 2010 +0000
14.3 @@ -46,7 +46,7 @@
14.4
14.5 IHardware[] Hardware { get; }
14.6
14.7 - bool HDDEnabled { get; set; }
14.8 + bool HDDEnabled { get; }
14.9
14.10 string GetReport();
14.11
15.1 --- a/Hardware/Identifier.cs Thu Aug 12 20:53:27 2010 +0000
15.2 +++ b/Hardware/Identifier.cs Sun Aug 15 14:46:58 2010 +0000
15.3 @@ -45,7 +45,7 @@
15.4
15.5 private static char SEPARATOR = '/';
15.6
15.7 - private void CheckIdentifiers(string[] identifiers) {
15.8 + private static void CheckIdentifiers(string[] identifiers) {
15.9 foreach (string s in identifiers)
15.10 if (s.Contains(" ") || s.Contains(SEPARATOR.ToString()))
15.11 throw new ArgumentException("Invalid identifier");
16.1 --- a/Hardware/LPC/Chip.cs Thu Aug 12 20:53:27 2010 +0000
16.2 +++ b/Hardware/LPC/Chip.cs Sun Aug 15 14:46:58 2010 +0000
16.3 @@ -25,7 +25,39 @@
16.4 F71869 = 0x0814,
16.5 F71882 = 0x0541,
16.6 F71889ED = 0x0909,
16.7 - F71889F = 0x0723
16.8 + F71889F = 0x0723
16.9 + }
16.10 +
16.11 + internal class ChipName {
16.12 +
16.13 + private ChipName() { }
16.14 +
16.15 + public static string GetName(Chip chip) {
16.16 + switch (chip) {
16.17 + case Chip.F71858: return "Fintek F71858";
16.18 + case Chip.F71862: return "Fintek F71862";
16.19 + case Chip.F71869: return "Fintek F71869";
16.20 + case Chip.F71882: return "Fintek F71882";
16.21 + case Chip.F71889ED: return "Fintek F71889ED";
16.22 + case Chip.F71889F: return "Fintek F71889F";
16.23 + case Chip.IT8712F: return "ITE IT8712F";
16.24 + case Chip.IT8716F: return "ITE IT8716F";
16.25 + case Chip.IT8718F: return "ITE IT8718F";
16.26 + case Chip.IT8720F: return "ITE IT8720F";
16.27 + case Chip.IT8726F: return "ITE IT8726F";
16.28 + case Chip.W83627DHG: return "Winbond W83627DHG";
16.29 + case Chip.W83627DHGP: return "Winbond W83627DHG-P";
16.30 + case Chip.W83627EHF: return "Winbond W83627EHF";
16.31 + case Chip.W83627HF: return "Winbond W83627HF";
16.32 + case Chip.W83627THF: return "Winbond W83627THF";
16.33 + case Chip.W83667HG: return "Winbond W83667HG";
16.34 + case Chip.W83667HGB: return "Winbond W83667HG-B";
16.35 + case Chip.W83687THF: return "Winbond W83687THF";
16.36 + case Chip.Unknown: return "Unkown";
16.37 + default: return "Unknown";
16.38 + }
16.39 + }
16.40 +
16.41 }
16.42
16.43 }
17.1 --- a/Hardware/LPC/LMSensors.cs Thu Aug 12 20:53:27 2010 +0000
17.2 +++ b/Hardware/LPC/LMSensors.cs Sun Aug 15 14:46:58 2010 +0000
17.3 @@ -51,9 +51,8 @@
17.4 foreach (string path in devicePaths) {
17.5 string name = null;
17.6 try {
17.7 - StreamReader reader = new StreamReader(path + "/device/name");
17.8 - name = reader.ReadLine();
17.9 - reader.Close();
17.10 + using (StreamReader reader = new StreamReader(path + "/device/name"))
17.11 + name = reader.ReadLine();
17.12 } catch (IOException) { }
17.13 switch (name) {
17.14 case "f71858fg":
18.1 --- a/Hardware/LPC/LPCIO.cs Thu Aug 12 20:53:27 2010 +0000
18.2 +++ b/Hardware/LPC/LPCIO.cs Sun Aug 15 14:46:58 2010 +0000
18.3 @@ -47,8 +47,6 @@
18.4 private List<ISuperIO> superIOs = new List<ISuperIO>();
18.5 private StringBuilder report = new StringBuilder();
18.6
18.7 - private Chip chip = Chip.Unknown;
18.8 -
18.9 // I/O Ports
18.10 private ushort[] REGISTER_PORTS = new ushort[] { 0x2e, 0x4e };
18.11 private ushort[] VALUE_PORTS = new ushort[] { 0x2f, 0x4f };
18.12 @@ -121,261 +119,290 @@
18.13 WinRing0.WriteIoPortByte(registerPort, 0xAA);
18.14 }
18.15
18.16 + private void ReportUnknownChip(string type, int chip) {
18.17 + report.Append("Chip ID: Unknown ");
18.18 + report.Append(type);
18.19 + report.Append(" with ID 0x");
18.20 + report.Append(chip.ToString("X", CultureInfo.InvariantCulture));
18.21 + report.Append(" at 0x");
18.22 + report.Append(registerPort.ToString("X", CultureInfo.InvariantCulture));
18.23 + report.Append("/0x");
18.24 + report.AppendLine(valuePort.ToString("X", CultureInfo.InvariantCulture));
18.25 + report.AppendLine();
18.26 + }
18.27 +
18.28 + private bool DetectWinbondFintek() {
18.29 + WinbondFintekEnter();
18.30 +
18.31 + byte logicalDeviceNumber;
18.32 + byte id = ReadByte(CHIP_ID_REGISTER);
18.33 + byte revision = ReadByte(CHIP_REVISION_REGISTER);
18.34 + Chip chip = Chip.Unknown;
18.35 + logicalDeviceNumber = 0;
18.36 + switch (id) {
18.37 + case 0x05:
18.38 + switch (revision) {
18.39 + case 0x07:
18.40 + chip = Chip.F71858;
18.41 + logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
18.42 + break;
18.43 + case 0x41:
18.44 + chip = Chip.F71882;
18.45 + logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.46 + break;
18.47 + } break;
18.48 + case 0x06:
18.49 + switch (revision) {
18.50 + case 0x01:
18.51 + chip = Chip.F71862;
18.52 + logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.53 + break;
18.54 + } break;
18.55 + case 0x07:
18.56 + switch (revision) {
18.57 + case 0x23:
18.58 + chip = Chip.F71889F;
18.59 + logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.60 + break;
18.61 + } break;
18.62 + case 0x08:
18.63 + switch (revision) {
18.64 + case 0x14:
18.65 + chip = Chip.F71869;
18.66 + logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.67 + break;
18.68 + } break;
18.69 + case 0x09:
18.70 + switch (revision) {
18.71 + case 0x09:
18.72 + chip = Chip.F71889ED;
18.73 + logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.74 + break;
18.75 + } break;
18.76 + case 0x52:
18.77 + switch (revision) {
18.78 + case 0x17:
18.79 + case 0x3A:
18.80 + case 0x41:
18.81 + chip = Chip.W83627HF;
18.82 + logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.83 + break;
18.84 + } break;
18.85 + case 0x82:
18.86 + switch (revision & 0xF0) {
18.87 + case 0x80:
18.88 + chip = Chip.W83627THF;
18.89 + logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.90 + break;
18.91 + } break;
18.92 + case 0x85:
18.93 + switch (revision) {
18.94 + case 0x41:
18.95 + chip = Chip.W83687THF;
18.96 + logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.97 + break;
18.98 + } break;
18.99 + case 0x88:
18.100 + switch (revision & 0xF0) {
18.101 + case 0x50:
18.102 + case 0x60:
18.103 + chip = Chip.W83627EHF;
18.104 + logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.105 + break;
18.106 + } break;
18.107 + case 0xA0:
18.108 + switch (revision & 0xF0) {
18.109 + case 0x20:
18.110 + chip = Chip.W83627DHG;
18.111 + logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.112 + break;
18.113 + } break;
18.114 + case 0xA5:
18.115 + switch (revision & 0xF0) {
18.116 + case 0x10:
18.117 + chip = Chip.W83667HG;
18.118 + logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.119 + break;
18.120 + } break;
18.121 + case 0xB0:
18.122 + switch (revision & 0xF0) {
18.123 + case 0x70:
18.124 + chip = Chip.W83627DHGP;
18.125 + logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.126 + break;
18.127 + } break;
18.128 + case 0xB3:
18.129 + switch (revision & 0xF0) {
18.130 + case 0x50:
18.131 + chip = Chip.W83667HGB;
18.132 + logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.133 + break;
18.134 + } break;
18.135 + }
18.136 + if (chip == Chip.Unknown) {
18.137 + if (id != 0 && id != 0xff) {
18.138 + WinbondFintekExit();
18.139 +
18.140 + ReportUnknownChip("Winbond / Fintek", ((id << 8) | revision));
18.141 + }
18.142 + } else {
18.143 +
18.144 + Select(logicalDeviceNumber);
18.145 + ushort address = ReadWord(BASE_ADDRESS_REGISTER);
18.146 + Thread.Sleep(1);
18.147 + ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
18.148 +
18.149 + ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
18.150 +
18.151 + WinbondFintekExit();
18.152 +
18.153 + if (address != verify) {
18.154 + report.Append("Chip ID: 0x");
18.155 + report.AppendLine(chip.ToString("X"));
18.156 + report.Append("Chip revision: 0x");
18.157 + report.AppendLine(revision.ToString("X",
18.158 + CultureInfo.InvariantCulture));
18.159 + report.AppendLine("Error: Address verification failed");
18.160 + report.AppendLine();
18.161 + return false;
18.162 + }
18.163 +
18.164 + // some Fintek chips have address register offset 0x05 added already
18.165 + if ((address & 0x07) == 0x05)
18.166 + address &= 0xFFF8;
18.167 +
18.168 + if (address < 0x100 || (address & 0xF007) != 0) {
18.169 + report.Append("Chip ID: 0x");
18.170 + report.AppendLine(chip.ToString("X"));
18.171 + report.Append("Chip revision: 0x");
18.172 + report.AppendLine(revision.ToString("X",
18.173 + CultureInfo.InvariantCulture));
18.174 + report.Append("Error: Invalid address 0x");
18.175 + report.AppendLine(address.ToString("X",
18.176 + CultureInfo.InvariantCulture));
18.177 + report.AppendLine();
18.178 + return false;
18.179 + }
18.180 +
18.181 + switch (chip) {
18.182 + case Chip.W83627DHG:
18.183 + case Chip.W83627DHGP:
18.184 + case Chip.W83627EHF:
18.185 + case Chip.W83627HF:
18.186 + case Chip.W83627THF:
18.187 + case Chip.W83667HG:
18.188 + case Chip.W83667HGB:
18.189 + case Chip.W83687THF:
18.190 + superIOs.Add(new W836XX(chip, revision, address));
18.191 + break;
18.192 + case Chip.F71858:
18.193 + case Chip.F71862:
18.194 + case Chip.F71869:
18.195 + case Chip.F71882:
18.196 + case Chip.F71889ED:
18.197 + case Chip.F71889F:
18.198 + if (vendorID != FINTEK_VENDOR_ID) {
18.199 + report.Append("Chip ID: 0x");
18.200 + report.AppendLine(chip.ToString("X"));
18.201 + report.Append("Chip revision: 0x");
18.202 + report.AppendLine(revision.ToString("X",
18.203 + CultureInfo.InvariantCulture));
18.204 + report.Append("Error: Invalid vendor ID 0x");
18.205 + report.AppendLine(vendorID.ToString("X",
18.206 + CultureInfo.InvariantCulture));
18.207 + report.AppendLine();
18.208 + return false;
18.209 + }
18.210 + superIOs.Add(new F718XX(chip, address));
18.211 + break;
18.212 + default: break;
18.213 + }
18.214 +
18.215 + return true;
18.216 + }
18.217 +
18.218 + return false;
18.219 + }
18.220 +
18.221 + private bool DetectIT87() {
18.222 + IT87Enter();
18.223 +
18.224 + ushort chipID = ReadWord(CHIP_ID_REGISTER);
18.225 + Chip chip;
18.226 + switch (chipID) {
18.227 + case 0x8712: chip = Chip.IT8712F; break;
18.228 + case 0x8716: chip = Chip.IT8716F; break;
18.229 + case 0x8718: chip = Chip.IT8718F; break;
18.230 + case 0x8720: chip = Chip.IT8720F; break;
18.231 + case 0x8726: chip = Chip.IT8726F; break;
18.232 + default: chip = Chip.Unknown; break;
18.233 + }
18.234 + if (chip == Chip.Unknown) {
18.235 + if (chipID != 0 && chipID != 0xffff) {
18.236 + IT87Exit();
18.237 +
18.238 + ReportUnknownChip("ITE", chipID);
18.239 + }
18.240 + } else {
18.241 + Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
18.242 + ushort address = ReadWord(BASE_ADDRESS_REGISTER);
18.243 + Thread.Sleep(1);
18.244 + ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
18.245 +
18.246 + byte version = (byte)(ReadByte(IT87_CHIP_VERSION_REGISTER) & 0x0F);
18.247 +
18.248 + IT87Exit();
18.249 +
18.250 + if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
18.251 + report.Append("Chip ID: 0x");
18.252 + report.AppendLine(chip.ToString("X"));
18.253 + report.Append("Error: Invalid address 0x");
18.254 + report.AppendLine(address.ToString("X",
18.255 + CultureInfo.InvariantCulture));
18.256 + report.AppendLine();
18.257 + return false;
18.258 + }
18.259 +
18.260 + superIOs.Add(new IT87XX(chip, address, version));
18.261 + return true;
18.262 + }
18.263 +
18.264 + return false;
18.265 + }
18.266 +
18.267 + private bool DetectSMSC() {
18.268 + SMSCEnter();
18.269 +
18.270 + ushort chipID = ReadWord(CHIP_ID_REGISTER);
18.271 + Chip chip;
18.272 + switch (chipID) {
18.273 + default: chip = Chip.Unknown; break;
18.274 + }
18.275 + if (chip == Chip.Unknown) {
18.276 + if (chipID != 0 && chipID != 0xffff) {
18.277 + SMSCExit();
18.278 +
18.279 + ReportUnknownChip("SMSC", chipID);
18.280 + }
18.281 + } else {
18.282 + SMSCExit();
18.283 + return true;
18.284 + }
18.285 +
18.286 + return false;
18.287 + }
18.288 +
18.289 private void Detect() {
18.290
18.291 for (int i = 0; i < REGISTER_PORTS.Length; i++) {
18.292 registerPort = REGISTER_PORTS[i];
18.293 valuePort = VALUE_PORTS[i];
18.294
18.295 - WinbondFintekEnter();
18.296 + if (DetectWinbondFintek()) continue;
18.297
18.298 - byte logicalDeviceNumber;
18.299 - byte id = ReadByte(CHIP_ID_REGISTER);
18.300 - byte revision = ReadByte(CHIP_REVISION_REGISTER);
18.301 - chip = Chip.Unknown;
18.302 - logicalDeviceNumber = 0;
18.303 - switch (id) {
18.304 - case 0x05:
18.305 - switch (revision) {
18.306 - case 0x07:
18.307 - chip = Chip.F71858;
18.308 - logicalDeviceNumber = F71858_HARDWARE_MONITOR_LDN;
18.309 - break;
18.310 - case 0x41:
18.311 - chip = Chip.F71882;
18.312 - logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.313 - break;
18.314 - } break;
18.315 - case 0x06:
18.316 - switch (revision) {
18.317 - case 0x01:
18.318 - chip = Chip.F71862;
18.319 - logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.320 - break;
18.321 - } break;
18.322 - case 0x07:
18.323 - switch (revision) {
18.324 - case 0x23:
18.325 - chip = Chip.F71889F;
18.326 - logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.327 - break;
18.328 - } break;
18.329 - case 0x08:
18.330 - switch (revision) {
18.331 - case 0x14:
18.332 - chip = Chip.F71869;
18.333 - logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.334 - break;
18.335 - } break;
18.336 - case 0x09:
18.337 - switch (revision) {
18.338 - case 0x09:
18.339 - chip = Chip.F71889ED;
18.340 - logicalDeviceNumber = FINTEK_HARDWARE_MONITOR_LDN;
18.341 - break;
18.342 - } break;
18.343 - case 0x52:
18.344 - switch (revision) {
18.345 - case 0x17:
18.346 - case 0x3A:
18.347 - case 0x41:
18.348 - chip = Chip.W83627HF;
18.349 - logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.350 - break;
18.351 - } break;
18.352 - case 0x82:
18.353 - switch (revision & 0xF0) {
18.354 - case 0x80:
18.355 - chip = Chip.W83627THF;
18.356 - logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.357 - break;
18.358 - } break;
18.359 - case 0x85:
18.360 - switch (revision) {
18.361 - case 0x41:
18.362 - chip = Chip.W83687THF;
18.363 - logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.364 - break;
18.365 - } break;
18.366 - case 0x88:
18.367 - switch (revision & 0xF0) {
18.368 - case 0x50:
18.369 - case 0x60:
18.370 - chip = Chip.W83627EHF;
18.371 - logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.372 - break;
18.373 - } break;
18.374 - case 0xA0:
18.375 - switch (revision & 0xF0) {
18.376 - case 0x20:
18.377 - chip = Chip.W83627DHG;
18.378 - logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.379 - break;
18.380 - } break;
18.381 - case 0xA5:
18.382 - switch (revision & 0xF0) {
18.383 - case 0x10:
18.384 - chip = Chip.W83667HG;
18.385 - logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.386 - break;
18.387 - } break;
18.388 - case 0xB0:
18.389 - switch (revision & 0xF0) {
18.390 - case 0x70:
18.391 - chip = Chip.W83627DHGP;
18.392 - logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.393 - break;
18.394 - } break;
18.395 - case 0xB3:
18.396 - switch (revision & 0xF0) {
18.397 - case 0x50:
18.398 - chip = Chip.W83667HGB;
18.399 - logicalDeviceNumber = WINBOND_HARDWARE_MONITOR_LDN;
18.400 - break;
18.401 - } break;
18.402 - }
18.403 - if (chip == Chip.Unknown) {
18.404 - if (id != 0 && id != 0xff) {
18.405 - WinbondFintekExit();
18.406 + if (DetectIT87()) continue;
18.407
18.408 - report.Append("Chip ID: Unknown Winbond / Fintek with ID 0x");
18.409 - report.AppendLine(((id << 8) | revision).ToString("X",
18.410 - CultureInfo.InvariantCulture));
18.411 - report.AppendLine();
18.412 - }
18.413 - } else {
18.414 -
18.415 - Select(logicalDeviceNumber);
18.416 - ushort address = ReadWord(BASE_ADDRESS_REGISTER);
18.417 - Thread.Sleep(1);
18.418 - ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
18.419 -
18.420 - ushort vendorID = ReadWord(FINTEK_VENDOR_ID_REGISTER);
18.421 -
18.422 - WinbondFintekExit();
18.423 -
18.424 - if (address != verify) {
18.425 - report.Append("Chip ID: 0x");
18.426 - report.AppendLine(chip.ToString("X"));
18.427 - report.Append("Chip revision: 0x");
18.428 - report.AppendLine(revision.ToString("X", CultureInfo.InvariantCulture));
18.429 - report.AppendLine("Error: Address verification failed");
18.430 - report.AppendLine();
18.431 - return;
18.432 - }
18.433 -
18.434 - // some Fintek chips have address register offset 0x05 added already
18.435 - if ((address & 0x07) == 0x05)
18.436 - address &= 0xFFF8;
18.437 -
18.438 - if (address < 0x100 || (address & 0xF007) != 0) {
18.439 - report.Append("Chip ID: 0x");
18.440 - report.AppendLine(chip.ToString("X"));
18.441 - report.Append("Chip revision: 0x");
18.442 - report.AppendLine(revision.ToString("X", CultureInfo.InvariantCulture));
18.443 - report.Append("Error: Invalid address 0x");
18.444 - report.AppendLine(address.ToString("X", CultureInfo.InvariantCulture));
18.445 - report.AppendLine();
18.446 - return;
18.447 - }
18.448 -
18.449 - switch (chip) {
18.450 - case Chip.W83627DHG:
18.451 - case Chip.W83627DHGP:
18.452 - case Chip.W83627EHF:
18.453 - case Chip.W83627HF:
18.454 - case Chip.W83627THF:
18.455 - case Chip.W83667HG:
18.456 - case Chip.W83667HGB:
18.457 - case Chip.W83687THF:
18.458 - superIOs.Add(new W836XX(chip, revision, address));
18.459 - break;
18.460 - case Chip.F71858:
18.461 - case Chip.F71862:
18.462 - case Chip.F71869:
18.463 - case Chip.F71882:
18.464 - case Chip.F71889ED:
18.465 - case Chip.F71889F:
18.466 - if (vendorID != FINTEK_VENDOR_ID) {
18.467 - report.Append("Chip ID: 0x");
18.468 - report.AppendLine(chip.ToString("X"));
18.469 - report.Append("Chip revision: 0x");
18.470 - report.AppendLine(revision.ToString("X", CultureInfo.InvariantCulture));
18.471 - report.Append("Error: Invalid vendor ID 0x");
18.472 - report.AppendLine(vendorID.ToString("X", CultureInfo.InvariantCulture));
18.473 - report.AppendLine();
18.474 - return;
18.475 - }
18.476 - superIOs.Add(new F718XX(chip, address));
18.477 - break;
18.478 - default: break;
18.479 - }
18.480 -
18.481 - return;
18.482 - }
18.483 -
18.484 - IT87Enter();
18.485 -
18.486 - ushort chipID = ReadWord(CHIP_ID_REGISTER);
18.487 - switch (chipID) {
18.488 - case 0x8712: chip = Chip.IT8712F; break;
18.489 - case 0x8716: chip = Chip.IT8716F; break;
18.490 - case 0x8718: chip = Chip.IT8718F; break;
18.491 - case 0x8720: chip = Chip.IT8720F; break;
18.492 - case 0x8726: chip = Chip.IT8726F; break;
18.493 - default: chip = Chip.Unknown; break;
18.494 - }
18.495 - if (chip == Chip.Unknown) {
18.496 - if (chipID != 0 && chipID != 0xffff) {
18.497 - IT87Exit();
18.498 -
18.499 - report.Append("Chip ID: Unknown ITE with ID 0x");
18.500 - report.AppendLine(chipID.ToString("X", CultureInfo.InvariantCulture));
18.501 - report.AppendLine();
18.502 - }
18.503 - } else {
18.504 - Select(IT87_ENVIRONMENT_CONTROLLER_LDN);
18.505 - ushort address = ReadWord(BASE_ADDRESS_REGISTER);
18.506 - Thread.Sleep(1);
18.507 - ushort verify = ReadWord(BASE_ADDRESS_REGISTER);
18.508 -
18.509 - byte version = (byte)(ReadByte(IT87_CHIP_VERSION_REGISTER) & 0x0F);
18.510 -
18.511 - IT87Exit();
18.512 -
18.513 - if (address != verify || address < 0x100 || (address & 0xF007) != 0) {
18.514 - report.Append("Chip ID: 0x");
18.515 - report.AppendLine(chip.ToString("X"));
18.516 - report.Append("Error: Invalid address 0x");
18.517 - report.AppendLine(address.ToString("X", CultureInfo.InvariantCulture));
18.518 - report.AppendLine();
18.519 - return;
18.520 - }
18.521 -
18.522 - superIOs.Add(new IT87XX(chip, address, version));
18.523 -
18.524 - return;
18.525 - }
18.526 -
18.527 - SMSCEnter();
18.528 -
18.529 - chipID = ReadWord(CHIP_ID_REGISTER);
18.530 - switch (chipID) {
18.531 - default: chip = Chip.Unknown; break;
18.532 - }
18.533 - if (chip == Chip.Unknown) {
18.534 - if (chipID != 0 && chipID != 0xffff) {
18.535 - SMSCExit();
18.536 -
18.537 - report.Append("Chip ID: Unknown SMSC with ID 0x");
18.538 - report.AppendLine(chipID.ToString("X", CultureInfo.InvariantCulture));
18.539 - report.AppendLine();
18.540 - }
18.541 - } else {
18.542 - SMSCExit();
18.543 -
18.544 - return;
18.545 - }
18.546 + if (DetectSMSC()) continue;
18.547 }
18.548 }
18.549
19.1 --- a/Hardware/LPC/W836XX.cs Thu Aug 12 20:53:27 2010 +0000
19.2 +++ b/Hardware/LPC/W836XX.cs Sun Aug 15 14:46:58 2010 +0000
19.3 @@ -178,7 +178,7 @@
19.4 return vendorId == WINBOND_VENDOR_ID;
19.5 }
19.6
19.7 - private ulong SetBit(ulong target, int bit, int value) {
19.8 + private static ulong SetBit(ulong target, int bit, int value) {
19.9 if ((value & 1) != value)
19.10 throw new ArgumentException("Value must be one bit only.");
19.11
20.1 --- a/Hardware/Mainboard/Mainboard.cs Thu Aug 12 20:53:27 2010 +0000
20.2 +++ b/Hardware/Mainboard/Mainboard.cs Sun Aug 15 14:46:58 2010 +0000
20.3 @@ -53,8 +53,7 @@
20.4 this.smbios = new SMBIOS();
20.5
20.6 if (smbios.Board != null) {
20.7 - if (smbios.Board.ProductName != null
20.8 - && smbios.Board.ProductName != "") {
20.9 + if (!string.IsNullOrEmpty(smbios.Board.ProductName)) {
20.10 if (smbios.Board.Manufacturer == Manufacturer.Unknown)
20.11 this.name = smbios.Board.ProductName;
20.12 else
20.13 @@ -131,8 +130,9 @@
20.14 #pragma warning restore 67
20.15
20.16 public void Accept(IVisitor visitor) {
20.17 - if (visitor != null)
20.18 - visitor.VisitHardware(this);
20.19 + if (visitor == null)
20.20 + throw new ArgumentNullException("visitor");
20.21 + visitor.VisitHardware(this);
20.22 }
20.23
20.24 public void Traverse(IVisitor visitor) {
21.1 --- a/Hardware/Mainboard/SMBIOS.cs Thu Aug 12 20:53:27 2010 +0000
21.2 +++ b/Hardware/Mainboard/SMBIOS.cs Sun Aug 15 14:46:58 2010 +0000
21.3 @@ -51,7 +51,7 @@
21.4 private BIOSInformation biosInformation = null;
21.5 private BaseBoardInformation baseBoardInformation = null;
21.6
21.7 - private string ReadSysFS(string path) {
21.8 + private static string ReadSysFS(string path) {
21.9 try {
21.10 if (File.Exists(path)) {
21.11 using (StreamReader reader = new StreamReader(path))
21.12 @@ -85,9 +85,12 @@
21.13
21.14 raw = null;
21.15 try {
21.16 - ManagementObjectCollection collection =
21.17 + ManagementObjectCollection collection;
21.18 + using (ManagementObjectSearcher searcher =
21.19 new ManagementObjectSearcher("root\\WMI",
21.20 - "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables").Get();
21.21 + "SELECT SMBiosData FROM MSSMBios_RawSMBiosTables")) {
21.22 + collection = searcher.Get();
21.23 + }
21.24
21.25 foreach (ManagementObject mo in collection) {
21.26 raw = (byte[])mo["SMBiosData"];
21.27 @@ -144,17 +147,19 @@
21.28 public string GetReport() {
21.29 StringBuilder r = new StringBuilder();
21.30
21.31 - if (biosInformation != null) {
21.32 - r.Append("BIOS Vendor: "); r.AppendLine(biosInformation.Vendor);
21.33 - r.Append("BIOS Version: "); r.AppendLine(biosInformation.Version);
21.34 + if (BIOS != null) {
21.35 + r.Append("BIOS Vendor: "); r.AppendLine(BIOS.Vendor);
21.36 + r.Append("BIOS Version: "); r.AppendLine(BIOS.Version);
21.37 r.AppendLine();
21.38 }
21.39
21.40 - if (baseBoardInformation != null) {
21.41 + if (Board != null) {
21.42 r.Append("Mainboard Manufacturer: ");
21.43 - r.AppendLine(baseBoardInformation.ManufacturerName);
21.44 + r.AppendLine(Board.ManufacturerName);
21.45 r.Append("Mainboard Name: ");
21.46 - r.AppendLine(baseBoardInformation.ProductName);
21.47 + r.AppendLine(Board.ProductName);
21.48 + r.Append("Mainboard Version: ");
21.49 + r.AppendLine(Board.Version);
21.50 r.AppendLine();
21.51 }
21.52
21.53 @@ -249,10 +254,10 @@
21.54 private Manufacturer manufacturer;
21.55 private Model model;
21.56
21.57 - private void SetManufacturerName(string manufacturerName) {
21.58 - this.manufacturerName = manufacturerName;
21.59 + private void SetManufacturerName(string name) {
21.60 + this.manufacturerName = name;
21.61
21.62 - switch (manufacturerName) {
21.63 + switch (name) {
21.64 case "ASRock":
21.65 manufacturer = Manufacturer.ASRock; break;
21.66 case "ASUSTeK Computer INC.":
21.67 @@ -286,10 +291,10 @@
21.68 }
21.69 }
21.70
21.71 - private void SetProductName(string productName) {
21.72 - this.productName = productName;
21.73 + private void SetProductName(string name) {
21.74 + this.productName = name;
21.75
21.76 - switch (productName) {
21.77 + switch (name) {
21.78 case "880GMH/USB3":
21.79 model = Model._880GMH_USB3; break;
21.80 case "Crosshair III Formula":
22.1 --- a/Hardware/Mainboard/SuperIOHardware.cs Thu Aug 12 20:53:27 2010 +0000
22.2 +++ b/Hardware/Mainboard/SuperIOHardware.cs Sun Aug 15 14:46:58 2010 +0000
22.3 @@ -44,39 +44,18 @@
22.4 internal class SuperIOHardware : Hardware {
22.5
22.6 private ISuperIO superIO;
22.7 - protected readonly string name;
22.8 + private string name;
22.9
22.10 private List<Sensor> voltages = new List<Sensor>();
22.11 private List<Sensor> temperatures = new List<Sensor>();
22.12 - private List<Sensor> fans = new List<Sensor>();
22.13 + private List<Sensor> fans = new List<Sensor>();
22.14 +
22.15
22.16 public SuperIOHardware(ISuperIO superIO, Manufacturer manufacturer,
22.17 Model model, ISettings settings)
22.18 {
22.19 this.superIO = superIO;
22.20 -
22.21 - switch (superIO.Chip) {
22.22 - case Chip.F71858: name = "Fintek F71858"; break;
22.23 - case Chip.F71862: name = "Fintek F71862"; break;
22.24 - case Chip.F71869: name = "Fintek F71869"; break;
22.25 - case Chip.F71882: name = "Fintek F71882"; break;
22.26 - case Chip.F71889ED: name = "Fintek F71889ED"; break;
22.27 - case Chip.F71889F: name = "Fintek F71889F"; break;
22.28 - case Chip.IT8712F: this.name = "ITE IT8712F"; break;
22.29 - case Chip.IT8716F: this.name = "ITE IT8716F"; break;
22.30 - case Chip.IT8718F: this.name = "ITE IT8718F"; break;
22.31 - case Chip.IT8720F: this.name = "ITE IT8720F"; break;
22.32 - case Chip.IT8726F: this.name = "ITE IT8726F"; break;
22.33 - case Chip.W83627DHG: this.name = "Winbond W83627DHG"; break;
22.34 - case Chip.W83627DHGP: this.name = "Winbond W83627DHG-P"; break;
22.35 - case Chip.W83627EHF: this.name = "Winbond W83627EHF"; break;
22.36 - case Chip.W83627HF: this.name = "Winbond W83627HF"; break;
22.37 - case Chip.W83627THF: this.name = "Winbond W83627THF"; break;
22.38 - case Chip.W83667HG: this.name = "Winbond W83667HG"; break;
22.39 - case Chip.W83667HGB: this.name = "Winbond W83667HG-B"; break;
22.40 - case Chip.W83687THF: this.name = "Winbond W83687THF"; break;
22.41 - case Chip.Unknown: this.name = "Unkown"; break;
22.42 - }
22.43 + this.name = ChipName.GetName(superIO.Chip);
22.44
22.45 List<Voltage> v = new List<Voltage>();
22.46 List<Temperature> t = new List<Temperature>();
22.47 @@ -483,7 +462,6 @@
22.48 v.Add(new Voltage("Standby +3.3V", 7, 34, 34, 0));
22.49 v.Add(new Voltage("VBAT", 8, 34, 34, 0));
22.50 t.Add(new Temperature("CPU", 0));
22.51 - t.Add(new Temperature("Auxiliary", 1, true));
22.52 t.Add(new Temperature("Motherboard", 2));
22.53 f.Add(new Fan("Chassis Fan #1", 0));
22.54 f.Add(new Fan("CPU Fan", 1));
22.55 @@ -673,15 +651,10 @@
22.56 private class Temperature {
22.57 public readonly string Name;
22.58 public readonly int Index;
22.59 - public readonly bool Hidden;
22.60
22.61 - public Temperature(string name, int index) :
22.62 - this(name, index, false) { }
22.63 -
22.64 - public Temperature(string name, int index, bool hidden) {
22.65 + public Temperature(string name, int index) {
22.66 this.Name = name;
22.67 this.Index = index;
22.68 - this.Hidden = hidden;
22.69 }
22.70 }
22.71
23.1 --- a/Hardware/Nvidia/NVAPI.cs Thu Aug 12 20:53:27 2010 +0000
23.2 +++ b/Hardware/Nvidia/NVAPI.cs Sun Aug 15 14:46:58 2010 +0000
23.3 @@ -310,7 +310,9 @@
23.4 public static readonly NvAPI_GPU_GetMemoryInfoDelegate
23.5 NvAPI_GPU_GetMemoryInfo;
23.6 public static readonly NvAPI_GetDisplayDriverVersionDelegate
23.7 - NvAPI_GetDisplayDriverVersion;
23.8 + NvAPI_GetDisplayDriverVersion;
23.9 +
23.10 + private NVAPI() { }
23.11
23.12 public static NvStatus NvAPI_GPU_GetFullName(NvPhysicalGpuHandle gpuHandle,
23.13 out string name) {
24.1 --- a/Hardware/Nvidia/NvidiaGPU.cs Thu Aug 12 20:53:27 2010 +0000
24.2 +++ b/Hardware/Nvidia/NvidiaGPU.cs Sun Aug 15 14:46:58 2010 +0000
24.3 @@ -239,7 +239,8 @@
24.4 r.Append("Driver Version: ");
24.5 r.Append(driverVersion.DriverVersion / 100);
24.6 r.Append(".");
24.7 - r.Append((driverVersion.DriverVersion % 100).ToString("00", CultureInfo.InvariantCulture));
24.8 + r.Append((driverVersion.DriverVersion % 100).ToString("00",
24.9 + CultureInfo.InvariantCulture));
24.10 r.AppendLine();
24.11 r.Append("Driver Branch: ");
24.12 r.AppendLine(driverVersion.BuildBranch);
25.1 --- a/Hardware/PInvokeDelegateFactory.cs Thu Aug 12 20:53:27 2010 +0000
25.2 +++ b/Hardware/PInvokeDelegateFactory.cs Sun Aug 15 14:46:58 2010 +0000
25.3 @@ -45,25 +45,15 @@
25.4
25.5 internal sealed class PInvokeDelegateFactory {
25.6
25.7 - private static AssemblyBuilder assemblyBuilder;
25.8 - private static ModuleBuilder moduleBuilder;
25.9 + private static ModuleBuilder moduleBuilder =
25.10 + AppDomain.CurrentDomain.DefineDynamicAssembly(
25.11 + new AssemblyName("PInvokeDelegateFactoryInternalAssembly"),
25.12 + AssemblyBuilderAccess.Run).DefineDynamicModule(
25.13 + "PInvokeDelegateFactoryInternalModule");
25.14
25.15 private static IDictionary<DllImportAttribute, Type> wrapperTypes =
25.16 new Dictionary<DllImportAttribute, Type>();
25.17
25.18 - static PInvokeDelegateFactory() {
25.19 -
25.20 - AssemblyName assemblyName = new AssemblyName();
25.21 - assemblyName.Name = "PInvokeDelegateFactoryInternalAssembly";
25.22 -
25.23 - assemblyBuilder =
25.24 - AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName,
25.25 - AssemblyBuilderAccess.Run);
25.26 -
25.27 - moduleBuilder = assemblyBuilder.DefineDynamicModule(
25.28 - "PInvokeDelegateFactoryInternalModule");
25.29 - }
25.30 -
25.31 private PInvokeDelegateFactory() { }
25.32
25.33 public static void CreateDelegate<T>(DllImportAttribute dllImportAttribute,
26.1 --- a/Hardware/Parameter.cs Thu Aug 12 20:53:27 2010 +0000
26.2 +++ b/Hardware/Parameter.cs Sun Aug 15 14:46:58 2010 +0000
26.3 @@ -41,7 +41,7 @@
26.4
26.5 namespace OpenHardwareMonitor.Hardware {
26.6
26.7 - public struct ParameterDescription {
26.8 + internal struct ParameterDescription {
26.9 private string name;
26.10 private string description;
26.11 private float defaultValue;
26.12 @@ -60,7 +60,7 @@
26.13 public float DefaultValue { get { return defaultValue; } }
26.14 }
26.15
26.16 - public class Parameter : IParameter {
26.17 + internal class Parameter : IParameter {
26.18 private ISensor sensor;
26.19 private ParameterDescription description;
26.20 private float value;
26.21 @@ -129,8 +129,9 @@
26.22 }
26.23
26.24 public void Accept(IVisitor visitor) {
26.25 - if (visitor != null)
26.26 - visitor.VisitParameter(this);
26.27 + if (visitor == null)
26.28 + throw new ArgumentNullException("visitor");
26.29 + visitor.VisitParameter(this);
26.30 }
26.31
26.32 public void Traverse(IVisitor visitor) { }
27.1 --- a/Hardware/Sensor.cs Thu Aug 12 20:53:27 2010 +0000
27.2 +++ b/Hardware/Sensor.cs Sun Aug 15 14:46:58 2010 +0000
27.3 @@ -51,9 +51,9 @@
27.4 private SensorType sensorType;
27.5 private IHardware hardware;
27.6 private ReadOnlyArray<IParameter> parameters;
27.7 - private float? value;
27.8 - private float? min;
27.9 - private float? max;
27.10 + private float? currentValue;
27.11 + private float? minValue;
27.12 + private float? maxValue;
27.13 private Queue<SensorValue> values =
27.14 new Queue<SensorValue>(MAX_MINUTES * 15);
27.15 private ISettings settings;
27.16 @@ -114,7 +114,7 @@
27.17 return name;
27.18 }
27.19 set {
27.20 - if (value != "")
27.21 + if (!string.IsNullOrEmpty(value))
27.22 name = value;
27.23 else
27.24 name = defaultName;
27.25 @@ -136,7 +136,7 @@
27.26
27.27 public float? Value {
27.28 get {
27.29 - return value;
27.30 + return currentValue;
27.31 }
27.32 set {
27.33 while (values.Count > 0 &&
27.34 @@ -153,23 +153,23 @@
27.35 }
27.36 }
27.37
27.38 - this.value = value;
27.39 - if (min > value || !min.HasValue)
27.40 - min = value;
27.41 - if (max < value || !max.HasValue)
27.42 - max = value;
27.43 + this.currentValue = value;
27.44 + if (minValue > value || !minValue.HasValue)
27.45 + minValue = value;
27.46 + if (maxValue < value || !maxValue.HasValue)
27.47 + maxValue = value;
27.48 }
27.49 }
27.50
27.51 - public float? Min { get { return min; } }
27.52 - public float? Max { get { return max; } }
27.53 + public float? Min { get { return minValue; } }
27.54 + public float? Max { get { return maxValue; } }
27.55
27.56 public void ResetMin() {
27.57 - min = null;
27.58 + minValue = null;
27.59 }
27.60
27.61 public void ResetMax() {
27.62 - max = null;
27.63 + maxValue = null;
27.64 }
27.65
27.66 public IEnumerable<SensorValue> Values {
27.67 @@ -177,8 +177,9 @@
27.68 }
27.69
27.70 public void Accept(IVisitor visitor) {
27.71 - if (visitor != null)
27.72 - visitor.VisitSensor(this);
27.73 + if (visitor == null)
27.74 + throw new ArgumentNullException("visitor");
27.75 + visitor.VisitSensor(this);
27.76 }
27.77
27.78 public void Traverse(IVisitor visitor) {
28.1 --- a/Hardware/SensorVisitor.cs Thu Aug 12 20:53:27 2010 +0000
28.2 +++ b/Hardware/SensorVisitor.cs Sun Aug 15 14:46:58 2010 +0000
28.3 @@ -45,14 +45,20 @@
28.4 private SensorEventHandler handler;
28.5
28.6 public SensorVisitor(SensorEventHandler handler) {
28.7 + if (handler == null)
28.8 + throw new ArgumentNullException("handler");
28.9 this.handler = handler;
28.10 }
28.11
28.12 public void VisitComputer(IComputer computer) {
28.13 + if (computer == null)
28.14 + throw new ArgumentNullException("computer");
28.15 computer.Traverse(this);
28.16 }
28.17
28.18 public void VisitHardware(IHardware hardware) {
28.19 + if (hardware == null)
28.20 + throw new ArgumentNullException("hardware");
28.21 hardware.Traverse(this);
28.22 }
28.23
29.1 --- a/Hardware/TBalancer/FTD2XX.cs Thu Aug 12 20:53:27 2010 +0000
29.2 +++ b/Hardware/TBalancer/FTD2XX.cs Sun Aug 15 14:46:58 2010 +0000
29.3 @@ -128,18 +128,44 @@
29.4 public delegate FT_STATUS FT_ReadDelegate(FT_HANDLE handle,
29.5 [Out] byte[] buffer, uint bytesToRead, out uint bytesReturned);
29.6
29.7 - public static FT_CreateDeviceInfoListDelegate FT_CreateDeviceInfoList;
29.8 - public static FT_GetDeviceInfoListDelegate FT_GetDeviceInfoList;
29.9 - public static FT_OpenDelegate FT_Open;
29.10 - public static FT_CloseDelegate FT_Close;
29.11 - public static FT_SetBaudRateDelegate FT_SetBaudRate;
29.12 - public static FT_SetDataCharacteristicsDelegate FT_SetDataCharacteristics;
29.13 - public static FT_SetFlowControlDelegate FT_SetFlowControl;
29.14 - public static FT_SetTimeoutsDelegate FT_SetTimeouts;
29.15 - public static FT_WriteDelegate FT_Write;
29.16 - public static FT_PurgeDelegate FT_Purge;
29.17 - public static FT_GetStatusDelegate FT_GetStatus;
29.18 - public static FT_ReadDelegate FT_Read;
29.19 + public static readonly FT_CreateDeviceInfoListDelegate
29.20 + FT_CreateDeviceInfoList = CreateDelegate<
29.21 + FT_CreateDeviceInfoListDelegate>("FT_CreateDeviceInfoList");
29.22 + public static readonly FT_GetDeviceInfoListDelegate
29.23 + FT_GetDeviceInfoList = CreateDelegate<
29.24 + FT_GetDeviceInfoListDelegate>("FT_GetDeviceInfoList");
29.25 + public static readonly FT_OpenDelegate
29.26 + FT_Open = CreateDelegate<
29.27 + FT_OpenDelegate>("FT_Open");
29.28 + public static readonly FT_CloseDelegate
29.29 + FT_Close = CreateDelegate<
29.30 + FT_CloseDelegate>("FT_Close");
29.31 + public static readonly FT_SetBaudRateDelegate
29.32 + FT_SetBaudRate = CreateDelegate<
29.33 + FT_SetBaudRateDelegate>("FT_SetBaudRate");
29.34 + public static readonly FT_SetDataCharacteristicsDelegate
29.35 + FT_SetDataCharacteristics = CreateDelegate<
29.36 + FT_SetDataCharacteristicsDelegate>("FT_SetDataCharacteristics");
29.37 + public static readonly FT_SetFlowControlDelegate
29.38 + FT_SetFlowControl = CreateDelegate<
29.39 + FT_SetFlowControlDelegate>("FT_SetFlowControl");
29.40 + public static readonly FT_SetTimeoutsDelegate
29.41 + FT_SetTimeouts = CreateDelegate<
29.42 + FT_SetTimeoutsDelegate>("FT_SetTimeouts");
29.43 + public static readonly FT_WriteDelegate
29.44 + FT_Write = CreateDelegate<
29.45 + FT_WriteDelegate>("FT_Write");
29.46 + public static readonly FT_PurgeDelegate
29.47 + FT_Purge = CreateDelegate<
29.48 + FT_PurgeDelegate>("FT_Purge");
29.49 + public static readonly FT_GetStatusDelegate
29.50 + FT_GetStatus = CreateDelegate<
29.51 + FT_GetStatusDelegate>("FT_GetStatus");
29.52 + public static readonly FT_ReadDelegate
29.53 + FT_Read = CreateDelegate<
29.54 + FT_ReadDelegate>("FT_Read");
29.55 +
29.56 + private FTD2XX() { }
29.57
29.58 public static FT_STATUS Write(FT_HANDLE handle, byte[] buffer) {
29.59 uint bytesWritten;
29.60 @@ -168,40 +194,27 @@
29.61 uint bytesReturned;
29.62 FT_STATUS status = FT_Read(handle, buffer, 1, out bytesReturned);
29.63 if (status != FT_STATUS.FT_OK || bytesReturned != 1)
29.64 - throw new Exception();
29.65 + throw new InvalidOperationException();
29.66 return buffer[0];
29.67 }
29.68
29.69 - private static string dllName;
29.70 + private static string GetDllName() {
29.71 + int p = (int)System.Environment.OSVersion.Platform;
29.72 + if ((p == 4) || (p == 128))
29.73 + return "libftd2xx.so";
29.74 + else
29.75 + return "ftd2xx.dll";
29.76 + }
29.77
29.78 - private static void GetDelegate<T>(string entryPoint, out T newDelegate)
29.79 + private static T CreateDelegate<T>(string entryPoint)
29.80 where T : class {
29.81 - DllImportAttribute attribute = new DllImportAttribute(dllName);
29.82 + DllImportAttribute attribute = new DllImportAttribute(GetDllName());
29.83 attribute.CallingConvention = CallingConvention.StdCall;
29.84 attribute.PreserveSig = true;
29.85 attribute.EntryPoint = entryPoint;
29.86 + T newDelegate;
29.87 PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate);
29.88 - }
29.89 -
29.90 - static FTD2XX() {
29.91 - int p = (int)System.Environment.OSVersion.Platform;
29.92 - if ((p == 4) || (p == 128))
29.93 - dllName = "libftd2xx.so";
29.94 - else
29.95 - dllName = "ftd2xx.dll";
29.96 -
29.97 - GetDelegate("FT_CreateDeviceInfoList", out FT_CreateDeviceInfoList);
29.98 - GetDelegate("FT_GetDeviceInfoList", out FT_GetDeviceInfoList);
29.99 - GetDelegate("FT_Open", out FT_Open);
29.100 - GetDelegate("FT_Close", out FT_Close);
29.101 - GetDelegate("FT_SetBaudRate", out FT_SetBaudRate);
29.102 - GetDelegate("FT_SetDataCharacteristics", out FT_SetDataCharacteristics);
29.103 - GetDelegate("FT_SetFlowControl", out FT_SetFlowControl);
29.104 - GetDelegate("FT_SetTimeouts", out FT_SetTimeouts);
29.105 - GetDelegate("FT_Write", out FT_Write);
29.106 - GetDelegate("FT_Purge", out FT_Purge);
29.107 - GetDelegate("FT_GetStatus", out FT_GetStatus);
29.108 - GetDelegate("FT_Read", out FT_Read);
29.109 + return newDelegate;
29.110 }
29.111 }
29.112 }
30.1 --- a/Hardware/TBalancer/TBalancer.cs Thu Aug 12 20:53:27 2010 +0000
30.2 +++ b/Hardware/TBalancer/TBalancer.cs Sun Aug 15 14:46:58 2010 +0000
30.3 @@ -161,8 +161,6 @@
30.4 }
30.5
30.6 for (int i = 0; i < 2; i++) {
30.7 - float maxRPM = 20.0f * data[offset + 44 + 2 * i];
30.8 -
30.9 if (miniNGFans[number * 2 + i] == null)
30.10 miniNGFans[number * 2 + i] =
30.11 new Sensor("miniNG #" + (number + 1) + " Fan Channel " + (i + 1),
30.12 @@ -376,8 +374,9 @@
30.13 public event SensorEventHandler SensorRemoved;
30.14
30.15 public void Accept(IVisitor visitor) {
30.16 - if (visitor != null)
30.17 - visitor.VisitHardware(this);
30.18 + if (visitor == null)
30.19 + throw new ArgumentNullException("visitor");
30.20 + visitor.VisitHardware(this);
30.21 }
30.22
30.23 public void Traverse(IVisitor visitor) { }
31.1 --- a/Hardware/WinRing0.cs Thu Aug 12 20:53:27 2010 +0000
31.2 +++ b/Hardware/WinRing0.cs Sun Aug 15 14:46:58 2010 +0000
31.3 @@ -44,6 +44,8 @@
31.4 namespace OpenHardwareMonitor.Hardware {
31.5
31.6 internal class WinRing0 {
31.7 +
31.8 + private WinRing0() { }
31.9
31.10 public enum OlsDllStatus{
31.11 OLS_DLL_NO_ERROR = 0,
31.12 @@ -56,7 +58,7 @@
31.13 }
31.14
31.15 private static bool available = false;
31.16 - public static Mutex isaBusMutex;
31.17 + private static Mutex isaBusMutex;
31.18
31.19 private static string GetDllName() {
31.20 int p = (int)System.Environment.OSVersion.Platform;
31.21 @@ -78,10 +80,7 @@
31.22 private delegate bool InitializeOlsDelegate();
31.23 private delegate void DeinitializeOlsDelegate();
31.24
31.25 - public delegate uint GetDllStatusDelegate();
31.26 public delegate bool IsCpuidDelegate();
31.27 - public delegate bool CpuidDelegate(uint index, uint ecxValue,
31.28 - out uint eax, out uint ebx, out uint ecx, out uint edx);
31.29 public delegate bool CpuidTxDelegate(uint index, uint ecxValue,
31.30 out uint eax, out uint ebx, out uint ecx, out uint edx,
31.31 UIntPtr threadAffinityMask);
31.32 @@ -90,7 +89,6 @@
31.33 UIntPtr threadAffinityMask);
31.34 public delegate byte ReadIoPortByteDelegate(ushort port);
31.35 public delegate void WriteIoPortByteDelegate(ushort port, byte value);
31.36 - public delegate void SetPciMaxBusIndexDelegate(byte max);
31.37 public delegate uint FindPciDeviceByIdDelegate(ushort vendorId,
31.38 ushort deviceId, byte index);
31.39 public delegate bool ReadPciConfigDwordExDelegate(uint pciAddress,
31.40 @@ -101,85 +99,73 @@
31.41 UIntPtr threadAffinityMask);
31.42 public delegate bool RdtscDelegate(out uint eax, out uint edx);
31.43
31.44 - private static InitializeOlsDelegate InitializeOls;
31.45 - private static DeinitializeOlsDelegate DeinitializeOls;
31.46 + private static InitializeOlsDelegate InitializeOls =
31.47 + CreateDelegate<InitializeOlsDelegate>("InitializeOls");
31.48 + private static DeinitializeOlsDelegate DeinitializeOls =
31.49 + CreateDelegate<DeinitializeOlsDelegate>("DeinitializeOls");
31.50
31.51 - public static readonly GetDllStatusDelegate GetDllStatus;
31.52 - public static readonly IsCpuidDelegate IsCpuid;
31.53 - public static readonly CpuidDelegate Cpuid;
31.54 - public static readonly CpuidTxDelegate CpuidTx;
31.55 - public static readonly RdmsrDelegate Rdmsr;
31.56 - public static readonly RdmsrTxDelegate RdmsrTx;
31.57 - public static readonly ReadIoPortByteDelegate ReadIoPortByte;
31.58 - public static readonly WriteIoPortByteDelegate WriteIoPortByte;
31.59 - public static readonly SetPciMaxBusIndexDelegate SetPciMaxBusIndex;
31.60 - public static readonly FindPciDeviceByIdDelegate FindPciDeviceById;
31.61 - public static readonly ReadPciConfigDwordExDelegate ReadPciConfigDwordEx;
31.62 - public static readonly WritePciConfigDwordExDelegate WritePciConfigDwordEx;
31.63 - public static readonly RdtscTxDelegate RdtscTx;
31.64 - public static readonly RdtscDelegate Rdtsc;
31.65 -
31.66 -
31.67 -
31.68 - private static void GetDelegate<T>(string entryPoint, out T newDelegate)
31.69 - where T : class
31.70 - {
31.71 + public static readonly IsCpuidDelegate IsCpuid =
31.72 + CreateDelegate<IsCpuidDelegate>("IsCpuid");
31.73 + public static readonly CpuidTxDelegate CpuidTx =
31.74 + CreateDelegate<CpuidTxDelegate>("CpuidTx");
31.75 + public static readonly RdmsrDelegate Rdmsr =
31.76 + CreateDelegate<RdmsrDelegate>("Rdmsr");
31.77 + public static readonly RdmsrTxDelegate RdmsrTx =
31.78 + CreateDelegate<RdmsrTxDelegate>("RdmsrTx");
31.79 + public static readonly ReadIoPortByteDelegate ReadIoPortByte =
31.80 + CreateDelegate<ReadIoPortByteDelegate>("ReadIoPortByte");
31.81 + public static readonly WriteIoPortByteDelegate WriteIoPortByte =
31.82 + CreateDelegate<WriteIoPortByteDelegate>("WriteIoPortByte");
31.83 + public static readonly FindPciDeviceByIdDelegate FindPciDeviceById =
31.84 + CreateDelegate<FindPciDeviceByIdDelegate>("FindPciDeviceById");
31.85 + public static readonly ReadPciConfigDwordExDelegate ReadPciConfigDwordEx =
31.86 + CreateDelegate<ReadPciConfigDwordExDelegate>("ReadPciConfigDwordEx");
31.87 + public static readonly WritePciConfigDwordExDelegate WritePciConfigDwordEx =
31.88 + CreateDelegate<WritePciConfigDwordExDelegate>("WritePciConfigDwordEx");
31.89 + public static readonly RdtscTxDelegate RdtscTx =
31.90 + CreateDelegate<RdtscTxDelegate>("RdtscTx");
31.91 + public static readonly RdtscDelegate Rdtsc =
31.92 + CreateDelegate<RdtscDelegate>("Rdtsc");
31.93 +
31.94 + private static T CreateDelegate<T>(string entryPoint) where T : class {
31.95 DllImportAttribute attribute = new DllImportAttribute(GetDllName());
31.96 attribute.CallingConvention = CallingConvention.Winapi;
31.97 attribute.PreserveSig = true;
31.98 attribute.EntryPoint = entryPoint;
31.99 attribute.CharSet = CharSet.Auto;
31.100 - PInvokeDelegateFactory.CreateDelegate(attribute, out newDelegate);
31.101 + T result;
31.102 + PInvokeDelegateFactory.CreateDelegate(attribute, out result);
31.103 + return result;
31.104 }
31.105
31.106 - static WinRing0() {
31.107 - GetDelegate("InitializeOls", out InitializeOls);
31.108 - GetDelegate("DeinitializeOls", out DeinitializeOls);
31.109 - GetDelegate("GetDllStatus", out GetDllStatus);
31.110 - GetDelegate("IsCpuid", out IsCpuid);
31.111 - GetDelegate("Cpuid", out Cpuid);
31.112 - GetDelegate("CpuidTx", out CpuidTx);
31.113 - GetDelegate("Rdmsr", out Rdmsr);
31.114 - GetDelegate("RdmsrTx", out RdmsrTx);
31.115 - GetDelegate("ReadIoPortByte", out ReadIoPortByte);
31.116 - GetDelegate("WriteIoPortByte", out WriteIoPortByte);
31.117 - GetDelegate("SetPciMaxBusIndex", out SetPciMaxBusIndex);
31.118 - GetDelegate("FindPciDeviceById", out FindPciDeviceById);
31.119 - GetDelegate("ReadPciConfigDwordEx", out ReadPciConfigDwordEx);
31.120 - GetDelegate("WritePciConfigDwordEx", out WritePciConfigDwordEx);
31.121 - GetDelegate("RdtscTx", out RdtscTx);
31.122 - GetDelegate("Rdtsc", out Rdtsc);
31.123 -
31.124 + public static void Open() {
31.125 try {
31.126 if (InitializeOls != null && InitializeOls())
31.127 available = true;
31.128 - } catch (DllNotFoundException) { }
31.129 -
31.130 + } catch (DllNotFoundException) { }
31.131 +
31.132 isaBusMutex = new Mutex(false, "Access_ISABUS.HTP.Method");
31.133 }
31.134 -
31.135 +
31.136 public static bool IsAvailable {
31.137 get { return available; }
31.138 }
31.139
31.140 + public static void Close() {
31.141 + if (available)
31.142 + DeinitializeOls();
31.143 + isaBusMutex.Close();
31.144 + }
31.145 +
31.146 public static bool WaitIsaBusMutex(int millisecondsTimeout) {
31.147 try {
31.148 - return isaBusMutex.WaitOne(millisecondsTimeout);
31.149 - } catch { return false; }
31.150 + return isaBusMutex.WaitOne(millisecondsTimeout, false);
31.151 + } catch (AbandonedMutexException) { return false; }
31.152 + catch (InvalidOperationException) { return false; }
31.153 }
31.154
31.155 public static void ReleaseIsaBusMutex() {
31.156 isaBusMutex.ReleaseMutex();
31.157 - }
31.158 -
31.159 - private static Deinitializer deinitializer = new Deinitializer();
31.160 - private class Deinitializer {
31.161 - ~Deinitializer() {
31.162 - if (available)
31.163 - DeinitializeOls();
31.164 -
31.165 - isaBusMutex.Close();
31.166 - }
31.167 - }
31.168 + }
31.169 }
31.170 }
32.1 --- a/OpenHardwareMonitorLib.csproj Thu Aug 12 20:53:27 2010 +0000
32.2 +++ b/OpenHardwareMonitorLib.csproj Sun Aug 15 14:46:58 2010 +0000
32.3 @@ -41,6 +41,7 @@
32.4 <ErrorReport>prompt</ErrorReport>
32.5 <WarningLevel>4</WarningLevel>
32.6 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
32.7 + <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
32.8 </PropertyGroup>
32.9 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
32.10 <DebugType>none</DebugType>
33.1 --- a/Properties/AssemblyLibInfo.cs Thu Aug 12 20:53:27 2010 +0000
33.2 +++ b/Properties/AssemblyLibInfo.cs Sun Aug 15 14:46:58 2010 +0000
33.3 @@ -50,4 +50,5 @@
33.4 [assembly: AssemblyCulture("")]
33.5
33.6 [assembly: ComVisible(false)]
33.7 -[assembly: CLSCompliant(true)]
33.8 \ No newline at end of file
33.9 +[assembly: CLSCompliant(true)]
33.10 +