mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-31 22:35:11 +00:00
Fixed some Code Analysis warnings.
This commit is contained in:
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.ATI {
|
||||
|
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.ATI {
|
||||
|
@@ -36,9 +36,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
internal sealed class AMD0FCPU : Hardware, IHardware {
|
||||
|
@@ -38,7 +38,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
|
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
|
@@ -36,9 +36,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
internal class CPULoad {
|
||||
|
@@ -39,10 +39,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
internal sealed class IntelCPU : Hardware, IHardware {
|
||||
|
@@ -37,14 +37,10 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Security;
|
||||
using System.IO;
|
||||
using System.Security.Permissions;
|
||||
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
public class Computer : IComputer {
|
||||
|
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenHardwareMonitor.Collections;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
@@ -36,7 +36,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Text;
|
||||
@@ -44,7 +44,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
||||
internal class Heatmaster : Hardware {
|
||||
internal class Heatmaster : Hardware, IDisposable {
|
||||
|
||||
private string portName;
|
||||
private SerialPort serialPort;
|
||||
@@ -85,8 +85,9 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
||||
serialPort.WriteLine("[0:" + device + "]R" + field);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
string s = ReadLine(200);
|
||||
Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]R" +
|
||||
Regex.Escape(field.ToString()) + ":(.*)");
|
||||
Match match = Regex.Match(s, @"-\[0:" +
|
||||
device.ToString(CultureInfo.InvariantCulture) + @"\]R" +
|
||||
Regex.Escape(field.ToString(CultureInfo.InvariantCulture)) + ":(.*)");
|
||||
if (match.Success)
|
||||
return match.Groups[1].Value;
|
||||
}
|
||||
@@ -114,8 +115,10 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
||||
serialPort.WriteLine("[0:" + device + "]W" + field + ":" + value);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
string s = ReadLine(200);
|
||||
Match match = Regex.Match(s, @"-\[0:" + device.ToString() + @"\]W" +
|
||||
Regex.Escape(field.ToString()) + ":" + value);
|
||||
Match match = Regex.Match(s, @"-\[0:" +
|
||||
device.ToString(CultureInfo.InvariantCulture) + @"\]W" +
|
||||
Regex.Escape(field.ToString(CultureInfo.InvariantCulture)) +
|
||||
":" + value);
|
||||
if (match.Success)
|
||||
return true;
|
||||
}
|
||||
@@ -123,7 +126,8 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
||||
}
|
||||
|
||||
private bool WriteInteger(int device, char field, int value) {
|
||||
return WriteField(device, field, value.ToString());
|
||||
return WriteField(device, field,
|
||||
value.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
private bool WriteString(int device, char field, string value) {
|
||||
@@ -233,7 +237,7 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
||||
string[] strings = s.Split(':');
|
||||
int[] ints = new int[strings.Length];
|
||||
for (int i = 0; i < ints.Length; i++)
|
||||
ints[i] = int.Parse(strings[i]);
|
||||
ints[i] = int.Parse(strings[i], CultureInfo.InvariantCulture);
|
||||
switch (device) {
|
||||
case 32:
|
||||
if (ints.Length == 3 && ints[0] <= fans.Length) {
|
||||
@@ -282,11 +286,11 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
||||
r.Append("Port: ");
|
||||
r.AppendLine(portName);
|
||||
r.Append("Hardware Revision: ");
|
||||
r.AppendLine(hardwareRevision.ToString());
|
||||
r.AppendLine(hardwareRevision.ToString(CultureInfo.InvariantCulture));
|
||||
r.Append("Firmware Revision: ");
|
||||
r.AppendLine(firmwareRevision.ToString());
|
||||
r.AppendLine(firmwareRevision.ToString(CultureInfo.InvariantCulture));
|
||||
r.Append("Firmware CRC: ");
|
||||
r.AppendLine(firmwareCRC.ToString());
|
||||
r.AppendLine(firmwareCRC.ToString(CultureInfo.InvariantCulture));
|
||||
r.AppendLine();
|
||||
|
||||
return r.ToString();
|
||||
@@ -294,6 +298,15 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
||||
|
||||
public void Close() {
|
||||
serialPort.Close();
|
||||
serialPort.Dispose();
|
||||
serialPort = null;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
if (serialPort != null) {
|
||||
serialPort.Dispose();
|
||||
serialPort = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,6 +37,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO.Ports;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
@@ -99,77 +100,77 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster {
|
||||
|
||||
string[] portNames = GetRegistryPortNames();
|
||||
for (int i = portNames.Length - 1; i >= 0; i--) {
|
||||
bool isValid = false;
|
||||
try {
|
||||
using (SerialPort serialPort =
|
||||
new SerialPort(portNames[i], 38400, Parity.None, 8, StopBits.One)) {
|
||||
serialPort.NewLine = ((char)0x0D).ToString();
|
||||
report.Append("Port Name: "); report.AppendLine(portNames[i]);
|
||||
|
||||
SerialPort serialPort =
|
||||
new SerialPort(portNames[i], 38400, Parity.None, 8, StopBits.One);
|
||||
serialPort.NewLine = ((char)0x0D).ToString();
|
||||
|
||||
bool isValid = false;
|
||||
report.Append("Port Name: "); report.AppendLine(portNames[i]);
|
||||
|
||||
try {
|
||||
serialPort.Open();
|
||||
} catch (UnauthorizedAccessException) {
|
||||
report.AppendLine("Exception: Access Denied");
|
||||
}
|
||||
|
||||
if (serialPort.IsOpen) {
|
||||
serialPort.DiscardInBuffer();
|
||||
serialPort.DiscardOutBuffer();
|
||||
serialPort.Write(new byte[] { 0xAA }, 0, 1);
|
||||
|
||||
int j = 0;
|
||||
while (serialPort.BytesToRead == 0 && j < 10) {
|
||||
Thread.Sleep(20);
|
||||
j++;
|
||||
try {
|
||||
serialPort.Open();
|
||||
} catch (UnauthorizedAccessException) {
|
||||
report.AppendLine("Exception: Access Denied");
|
||||
}
|
||||
if (serialPort.BytesToRead > 0) {
|
||||
bool flag = false;
|
||||
while (serialPort.BytesToRead > 0 && !flag) {
|
||||
flag |= (serialPort.ReadByte() == 0xAA);
|
||||
|
||||
if (serialPort.IsOpen) {
|
||||
serialPort.DiscardInBuffer();
|
||||
serialPort.DiscardOutBuffer();
|
||||
serialPort.Write(new byte[] { 0xAA }, 0, 1);
|
||||
|
||||
int j = 0;
|
||||
while (serialPort.BytesToRead == 0 && j < 10) {
|
||||
Thread.Sleep(20);
|
||||
j++;
|
||||
}
|
||||
if (flag) {
|
||||
serialPort.WriteLine("[0:0]RH");
|
||||
try {
|
||||
int k = 0;
|
||||
int revision = 0;
|
||||
while (k < 5) {
|
||||
string line = ReadLine(serialPort, 100);
|
||||
if (line.StartsWith("-[0:0]RH:")) {
|
||||
int.TryParse(line.Substring(9), out revision);
|
||||
break;
|
||||
if (serialPort.BytesToRead > 0) {
|
||||
bool flag = false;
|
||||
while (serialPort.BytesToRead > 0 && !flag) {
|
||||
flag |= (serialPort.ReadByte() == 0xAA);
|
||||
}
|
||||
if (flag) {
|
||||
serialPort.WriteLine("[0:0]RH");
|
||||
try {
|
||||
int k = 0;
|
||||
int revision = 0;
|
||||
while (k < 5) {
|
||||
string line = ReadLine(serialPort, 100);
|
||||
if (line.StartsWith("-[0:0]RH:",
|
||||
StringComparison.Ordinal)) {
|
||||
revision = int.Parse(line.Substring(9),
|
||||
CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
k++;
|
||||
isValid = (revision == 770);
|
||||
if (!isValid) {
|
||||
report.Append("Status: Wrong Hardware Revision " +
|
||||
revision.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
} catch (TimeoutException) {
|
||||
report.AppendLine("Status: Timeout Reading Revision");
|
||||
}
|
||||
isValid = (revision == 770);
|
||||
if (!isValid) {
|
||||
report.Append("Status: Wrong Hardware Revision " +
|
||||
revision.ToString());
|
||||
}
|
||||
} catch (TimeoutException) {
|
||||
report.AppendLine("Status: Timeout Reading Revision");
|
||||
} else {
|
||||
report.AppendLine("Status: Wrong Startflag");
|
||||
}
|
||||
} else {
|
||||
report.AppendLine("Status: Wrong Startflag");
|
||||
report.AppendLine("Status: No Response");
|
||||
}
|
||||
serialPort.DiscardInBuffer();
|
||||
} else {
|
||||
report.AppendLine("Status: No Response");
|
||||
report.AppendLine("Status: Port not Open");
|
||||
}
|
||||
serialPort.DiscardInBuffer();
|
||||
serialPort.Close();
|
||||
serialPort.Dispose();
|
||||
} else {
|
||||
report.AppendLine("Status: Port not Open");
|
||||
}
|
||||
if (isValid) {
|
||||
report.AppendLine("Status: OK");
|
||||
hardware.Add(new Heatmaster(portNames[i], settings));
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
report.AppendLine(e.ToString());
|
||||
}
|
||||
|
||||
if (isValid) {
|
||||
report.AppendLine("Status: OK");
|
||||
hardware.Add(new Heatmaster(portNames[i], settings));
|
||||
return;
|
||||
}
|
||||
report.AppendLine();
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
internal class HexStringArray {
|
||||
|
@@ -35,9 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
public delegate void HardwareEventHandler(IHardware hardware);
|
||||
|
@@ -35,10 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
public interface IElement {
|
||||
|
@@ -35,9 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
internal interface IGroup {
|
||||
|
@@ -35,9 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
public delegate void SensorEventHandler(ISensor sensor);
|
||||
|
@@ -35,9 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
public interface IParameter : IElement {
|
||||
|
@@ -35,9 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
public interface ISettings {
|
||||
|
||||
|
@@ -35,10 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
public interface IVisitor {
|
||||
|
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
@@ -97,7 +96,34 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
if (other == null)
|
||||
return 1;
|
||||
else
|
||||
return this.identifier.CompareTo(other.identifier);
|
||||
return string.Compare(this.identifier, other.identifier,
|
||||
StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public static bool operator ==(Identifier id1, Identifier id2) {
|
||||
if (id1 == null)
|
||||
return id2 == null;
|
||||
else
|
||||
return id1.Equals(id2);
|
||||
}
|
||||
|
||||
public static bool operator !=(Identifier id1, Identifier id2) {
|
||||
return !(id1 == id2);
|
||||
}
|
||||
|
||||
public static bool operator <(Identifier id1, Identifier id2) {
|
||||
if (id1 == null)
|
||||
return id2 != null;
|
||||
else
|
||||
return (id1.CompareTo(id2) < 0);
|
||||
}
|
||||
|
||||
public static bool operator >(Identifier id1, Identifier id2) {
|
||||
if (id1 == null)
|
||||
return false;
|
||||
else
|
||||
return (id1.CompareTo(id2) > 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,39 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
/*
|
||||
|
||||
Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the License.
|
||||
|
||||
The Original Code is the Open Hardware Monitor code.
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Michael Möller <m.moeller@gmx.ch>.
|
||||
Portions created by the Initial Developer are Copyright (C) 2009-2010
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms of
|
||||
either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
of those above. If you wish to allow use of your version of this file only
|
||||
under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
use your version of this file under the terms of the MPL, indicate your
|
||||
decision by deleting the provisions above and replace them with the notice
|
||||
and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the MPL, the GPL or the LGPL.
|
||||
|
||||
*/
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.LPC {
|
||||
|
||||
@@ -59,7 +91,6 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -35,9 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.LPC {
|
||||
internal interface ISuperIO {
|
||||
|
||||
|
@@ -35,8 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
|
@@ -35,7 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
|
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OpenHardwareMonitor.Hardware.LPC;
|
||||
|
||||
|
@@ -35,9 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.Mainboard {
|
||||
internal class MainboardGroup : IGroup {
|
||||
|
||||
|
@@ -35,7 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using OpenHardwareMonitor.Hardware.LPC;
|
||||
|
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
|
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
|
@@ -35,7 +35,6 @@
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
@@ -37,7 +37,6 @@
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
|
@@ -37,7 +37,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenHardwareMonitor.Hardware;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
|
@@ -36,7 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenHardwareMonitor.Hardware.TBalancer {
|
||||
|
@@ -37,7 +37,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
|
@@ -38,8 +38,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Ports;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
|
@@ -36,8 +36,6 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
|
Reference in New Issue
Block a user