diff --git a/LibreHardwareMonitorLib/Hardware/Computer.cs b/LibreHardwareMonitorLib/Hardware/Computer.cs index 19e898b..1c607bb 100644 --- a/LibreHardwareMonitorLib/Hardware/Computer.cs +++ b/LibreHardwareMonitorLib/Hardware/Computer.cs @@ -358,7 +358,7 @@ namespace LibreHardwareMonitor.Hardware w.Write(report); } - foreach (IHardware hardware in (IEnumerable)group.Hardware) + foreach (IHardware hardware in group.Hardware) ReportHardware(hardware, w); } diff --git a/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/D5Next.cs b/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/D5Next.cs index b145046..9f06222 100644 --- a/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/D5Next.cs +++ b/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/D5Next.cs @@ -32,7 +32,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.AquaComputer //Reading output report instead of feature report, as the measurements are in the output report _stream.Read(_rawData); - Name = $"D5Next"; + Name = "D5Next"; FirmwareVersion = Convert.ToUInt16(_rawData[14] | (_rawData[13] << 8)); _temperatures[0] = new Sensor("Water Temperature", 0, SensorType.Temperature, this, Array.Empty(), settings); ActivateSensor(_temperatures[0]); @@ -60,7 +60,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.AquaComputer //Reading output report instead of feature report, as the measurements are in the output report _stream.Read(_rawData); _temperatures[0].Value = (_rawData[88] | (_rawData[87] << 8)) / 100f; //Water Temp - _rpmSensors[0].Value = (_rawData[117] | (_rawData[116] << 8)); //Pump RPM + _rpmSensors[0].Value = _rawData[117] | (_rawData[116] << 8); //Pump RPM } } } diff --git a/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/MPS.cs b/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/MPS.cs index ca82b3c..d97802e 100644 --- a/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/MPS.cs +++ b/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/MPS.cs @@ -10,6 +10,9 @@ namespace LibreHardwareMonitor.Hardware.Controller.AquaComputer { internal sealed class MPS : Hardware { + public const int ExternalTemperature = 43; + public const int InternalWaterTemperature = 45; + public const int PumpFlow = 35; private const byte MPS_REPORT_ID = 0x2; private readonly Sensor _pumpFlow; @@ -79,9 +82,9 @@ namespace LibreHardwareMonitor.Hardware.Controller.AquaComputer if (_rawData[0] != MPS_REPORT_ID) return; - _pumpFlow.Value = BitConverter.ToUInt16(_rawData, MPSDataIndexes.PumpFlow) / 10f; + _pumpFlow.Value = BitConverter.ToUInt16(_rawData, PumpFlow) / 10f; - _externalTemperature = BitConverter.ToUInt16(_rawData, MPSDataIndexes.ExternalTemperature); + _externalTemperature = BitConverter.ToUInt16(_rawData, ExternalTemperature); //sensor reading returns Int16.MaxValue (32767), when not connected if (_externalTemperature != short.MaxValue) { @@ -92,19 +95,12 @@ namespace LibreHardwareMonitor.Hardware.Controller.AquaComputer _temperatures[0].Value = null; } - _temperatures[1].Value = BitConverter.ToUInt16(_rawData, MPSDataIndexes.InternalWaterTemperature) / 100f; + _temperatures[1].Value = BitConverter.ToUInt16(_rawData, InternalWaterTemperature) / 100f; } private ushort ExtractFirmwareVersion() { return BitConverter.ToUInt16(_rawData, 3); } - - private sealed class MPSDataIndexes - { - public const int ExternalTemperature = 43; - public const int InternalWaterTemperature = 45; - public const int PumpFlow = 35; - } } } diff --git a/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/Octo.cs b/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/Octo.cs index 5f9a5f4..44b2003 100644 --- a/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/Octo.cs +++ b/LibreHardwareMonitorLib/Hardware/Controller/AquaComputer/Octo.cs @@ -25,7 +25,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.AquaComputer //Reading output report instead of feature report, as the measurements are in the output report _stream.Read(_rawData); - Name = $"OCTO"; + Name = "OCTO"; FirmwareVersion = GetConvertedValue(OctoDataIndexes.FIRMWARE_VERSION).GetValueOrDefault(0); // Initialize the 4 temperature sensors diff --git a/LibreHardwareMonitorLib/Hardware/Controller/Heatmaster/Heatmaster.cs b/LibreHardwareMonitorLib/Hardware/Controller/Heatmaster/Heatmaster.cs index a5b1e5b..38da2fe 100644 --- a/LibreHardwareMonitorLib/Hardware/Controller/Heatmaster/Heatmaster.cs +++ b/LibreHardwareMonitorLib/Hardware/Controller/Heatmaster/Heatmaster.cs @@ -85,8 +85,10 @@ namespace LibreHardwareMonitor.Hardware.Controller.Heatmaster { int device = 81 + i; string name = ReadString(device, 'C'); - _relays[i] = new Sensor(name, device, SensorType.Control, this, settings); - _relays[i].Value = 100 * ReadInteger(device, 'S'); + _relays[i] = new Sensor(name, device, SensorType.Control, this, settings) + { + Value = 100 * ReadInteger(device, 'S') + }; ActivateSensor(_relays[i]); } @@ -157,7 +159,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.Heatmaster private string ReadString(int device, char field) { string s = ReadField(device, field); - if (s != null && s[0] == '"' && s[s.Length - 1] == '"') + if (s?[0] == '"' && s[s.Length - 1] == '"') return s.Substring(1, s.Length - 2); return null; diff --git a/LibreHardwareMonitorLib/Hardware/Controller/Heatmaster/HeatmasterGroup.cs b/LibreHardwareMonitorLib/Hardware/Controller/Heatmaster/HeatmasterGroup.cs index 9040f50..1447e46 100644 --- a/LibreHardwareMonitorLib/Hardware/Controller/Heatmaster/HeatmasterGroup.cs +++ b/LibreHardwareMonitorLib/Hardware/Controller/Heatmaster/HeatmasterGroup.cs @@ -32,87 +32,85 @@ namespace LibreHardwareMonitor.Hardware.Controller.Heatmaster bool isValid = false; try { - using (SerialPort serialPort = new(portNames[i], 38400, Parity.None, 8, StopBits.One)) + using SerialPort serialPort = new(portNames[i], 38400, Parity.None, 8, StopBits.One); + serialPort.NewLine = ((char)0x0D).ToString(); + _report.Append("Port Name: "); + _report.AppendLine(portNames[i]); + try { - serialPort.NewLine = ((char)0x0D).ToString(); - _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) { - serialPort.Open(); - } - catch (UnauthorizedAccessException) - { - _report.AppendLine("Exception: Access Denied"); + Thread.Sleep(20); + j++; } - if (serialPort.IsOpen) + if (serialPort.BytesToRead > 0) { - serialPort.DiscardInBuffer(); - serialPort.DiscardOutBuffer(); - serialPort.Write(new byte[] { 0xAA }, 0, 1); - - int j = 0; - while (serialPort.BytesToRead == 0 && j < 10) + bool flag = false; + while (serialPort.BytesToRead > 0 && !flag) { - Thread.Sleep(20); - j++; + flag |= serialPort.ReadByte() == 0xAA; } - if (serialPort.BytesToRead > 0) + if (flag) { - bool flag = false; - while (serialPort.BytesToRead > 0 && !flag) + serialPort.WriteLine("[0:0]RH"); + try { - flag |= serialPort.ReadByte() == 0xAA; - } - - if (flag) - { - serialPort.WriteLine("[0:0]RH"); - try + int k = 0; + int revision = 0; + while (k < 5) { - int k = 0; - int revision = 0; - while (k < 5) + string line = ReadLine(serialPort, 100); + if (line.StartsWith("-[0:0]RH:", StringComparison.Ordinal)) { - string line = ReadLine(serialPort, 100); - if (line.StartsWith("-[0:0]RH:", StringComparison.Ordinal)) - { - revision = int.Parse(line.Substring(9), CultureInfo.InvariantCulture); - break; - } - - k++; + revision = int.Parse(line.Substring(9), CultureInfo.InvariantCulture); + break; } - isValid = revision == 770; - if (!isValid) - { - _report.Append("Status: Wrong Hardware Revision " + revision.ToString(CultureInfo.InvariantCulture)); - } + k++; } - catch (TimeoutException) + + isValid = revision == 770; + if (!isValid) { - _report.AppendLine("Status: Timeout Reading Revision"); + _report.Append("Status: Wrong Hardware Revision " + revision.ToString(CultureInfo.InvariantCulture)); } } - else + catch (TimeoutException) { - _report.AppendLine("Status: Wrong Startflag"); + _report.AppendLine("Status: Timeout Reading Revision"); } } else { - _report.AppendLine("Status: No Response"); + _report.AppendLine("Status: Wrong Startflag"); } - - serialPort.DiscardInBuffer(); } else { - _report.AppendLine("Status: Port not Open"); + _report.AppendLine("Status: No Response"); } + + serialPort.DiscardInBuffer(); + } + else + { + _report.AppendLine("Status: Port not Open"); } } catch (Exception e) diff --git a/LibreHardwareMonitorLib/Hardware/Controller/Nzxt/GridV3.cs b/LibreHardwareMonitorLib/Hardware/Controller/Nzxt/GridV3.cs index 57782d8..7281322 100644 --- a/LibreHardwareMonitorLib/Hardware/Controller/Nzxt/GridV3.cs +++ b/LibreHardwareMonitorLib/Hardware/Controller/Nzxt/GridV3.cs @@ -24,7 +24,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.Nzxt private readonly byte[] _setFanSpeedMsg; private readonly HidStream _stream; - private readonly Dictionary _rawData = new Dictionary(); + private readonly Dictionary _rawData = new(); private readonly Sensor _noise; private readonly Sensor[] _currents = new Sensor[FANS_COUNT]; @@ -90,10 +90,10 @@ namespace LibreHardwareMonitor.Hardware.Controller.Nzxt // NZXT GRID does not report current PWM value. So we need to initialize it with some value to keep GUI and device values in sync. _fanControls[i].SetDefault(); } - _noise = new Sensor($"GRID Noise", 0, SensorType.Noise, this, Array.Empty(), settings); + _noise = new Sensor("GRID Noise", 0, SensorType.Noise, this, Array.Empty(), settings); ActivateSensor(_noise); - Thread readGridReports = new Thread(ContinuousRead) { IsBackground = true }; + Thread readGridReports = new(ContinuousRead) { IsBackground = true }; readGridReports.Start(_rawData); } } @@ -107,7 +107,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.Nzxt if (control.ControlMode == ControlMode.Software) { float value = control.SoftwareValue; - byte fanSpeed = (byte)(value > 100 ? 100 : (value < 0) ? 0 : value); // Clamp the value, anything out of range will fail + byte fanSpeed = (byte)(value > 100 ? 100 : value < 0 ? 0 : value); // Clamp the value, anything out of range will fail //_controlling = true; _setFanSpeedMsg[2] = (byte)control.Sensor.Index; diff --git a/LibreHardwareMonitorLib/Hardware/Controller/Nzxt/KrakenX3.cs b/LibreHardwareMonitorLib/Hardware/Controller/Nzxt/KrakenX3.cs index f9ec5d7..aae8647 100644 --- a/LibreHardwareMonitorLib/Hardware/Controller/Nzxt/KrakenX3.cs +++ b/LibreHardwareMonitorLib/Hardware/Controller/Nzxt/KrakenX3.cs @@ -22,7 +22,6 @@ namespace LibreHardwareMonitor.Hardware.Controller.Nzxt private static readonly byte[][] _setPumpTargetMap = new byte[101][]; // Sacrifice memory to speed this up with a lookup instead of a copy operation private readonly Sensor _pump; - private readonly Control _pumpControl; private readonly Sensor _pumpRpm; private readonly byte[] _rawData = new byte[64]; private readonly HidStream _stream; @@ -60,11 +59,11 @@ namespace LibreHardwareMonitor.Hardware.Controller.Nzxt Name = "Nzxt Kraken X3"; _pump = new Sensor("Pump Control", 0, SensorType.Control, this, Array.Empty(), settings); - _pumpControl = new Control(_pump, settings, 0, 100); - _pump.Control = _pumpControl; - _pumpControl.ControlModeChanged += SoftwareControlValueChanged; - _pumpControl.SoftwareControlValueChanged += SoftwareControlValueChanged; - SoftwareControlValueChanged(_pumpControl); + Control pumpControl = new(_pump, settings, 0, 100); + _pump.Control = pumpControl; + pumpControl.ControlModeChanged += SoftwareControlValueChanged; + pumpControl.SoftwareControlValueChanged += SoftwareControlValueChanged; + SoftwareControlValueChanged(pumpControl); ActivateSensor(_pump); _pumpRpm = new Sensor("Pump", 0, SensorType.Fan, this, Array.Empty(), settings); @@ -88,7 +87,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.Nzxt if (control.ControlMode == ControlMode.Software) { float value = control.SoftwareValue; - byte pumpSpeedIndex = (byte)(value > 100 ? 100 : (value < 0) ? 0 : value); // Clamp the value, anything out of range will fail + byte pumpSpeedIndex = (byte)(value > 100 ? 100 : value < 0 ? 0 : value); // Clamp the value, anything out of range will fail _controlling = true; _stream.Write(_setPumpTargetMap[pumpSpeedIndex]); @@ -152,7 +151,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.Nzxt else if (_pump.Value != _rawData[19]) { float value = _pump.Value.GetValueOrDefault(); - byte pumpSpeedIndex = (byte)(value > 100 ? 100 : (value < 0) ? 0 : value); // Clamp the value, anything out of range will fail + byte pumpSpeedIndex = (byte)(value > 100 ? 100 : value < 0 ? 0 : value); // Clamp the value, anything out of range will fail _stream.Write(_setPumpTargetMap[pumpSpeedIndex]); } else diff --git a/LibreHardwareMonitorLib/Hardware/Controller/TBalancer/TBalancer.cs b/LibreHardwareMonitorLib/Hardware/Controller/TBalancer/TBalancer.cs index c9eb236..fd8ee7c 100644 --- a/LibreHardwareMonitorLib/Hardware/Controller/TBalancer/TBalancer.cs +++ b/LibreHardwareMonitorLib/Hardware/Controller/TBalancer/TBalancer.cs @@ -43,7 +43,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.TBalancer _portIndex = portIndex; _protocolVersion = protocolVersion; - ParameterDescription[] parameter = { new ParameterDescription("Offset [°C]", "Temperature offset.", 0) }; + ParameterDescription[] parameter = { new("Offset [°C]", "Temperature offset.", 0) }; int offset = 0; for (int i = 0; i < _digitalTemperatures.Length; i++) _digitalTemperatures[i] = new Sensor("Digital Sensor " + i, offset + i, SensorType.Temperature, this, parameter, settings); @@ -138,8 +138,7 @@ namespace LibreHardwareMonitor.Hardware.Controller.TBalancer for (int i = 0; i < 2; i++) { - if (_miniNgFans[(number * 2) + i] == null) - _miniNgFans[(number * 2) + i] = new Sensor("miniNG #" + (number + 1) + " Fan Channel " + (i + 1), 4 + (number * 2) + i, SensorType.Fan, this, _settings); + _miniNgFans[(number * 2) + i] ??= new Sensor("miniNG #" + (number + 1) + " Fan Channel " + (i + 1), 4 + (number * 2) + i, SensorType.Fan, this, _settings); Sensor sensor = _miniNgFans[(number * 2) + i]; sensor.Value = 20.0f * _data[offset + 43 + (2 * i)]; @@ -233,20 +232,17 @@ namespace LibreHardwareMonitor.Hardware.Controller.TBalancer { float maxRpm = 11.5f * ((_data[149 + (2 * i)] << 8) | _data[148 + (2 * i)]); - if (_fans[i] == null) - { - _fans[i] = new Sensor("Fan Channel " + i, - i, - SensorType.Fan, - this, - new[] - { - new ParameterDescription("MaxRPM", - "Maximum revolutions per minute (RPM) of the fan.", - maxRpm) - }, - _settings); - } + _fans[i] ??= new Sensor("Fan Channel " + i, + i, + SensorType.Fan, + this, + new[] + { + new ParameterDescription("MaxRPM", + "Maximum revolutions per minute (RPM) of the fan.", + maxRpm) + }, + _settings); float value; if ((_data[136] & (1 << i)) == 0) // pwm mode diff --git a/LibreHardwareMonitorLib/Hardware/Cpu/Amd10Cpu.cs b/LibreHardwareMonitorLib/Hardware/Cpu/Amd10Cpu.cs index 7f4ee50..8995fa9 100644 --- a/LibreHardwareMonitorLib/Hardware/Cpu/Amd10Cpu.cs +++ b/LibreHardwareMonitorLib/Hardware/Cpu/Amd10Cpu.cs @@ -86,7 +86,7 @@ namespace LibreHardwareMonitor.Hardware.CPU { 0x00 => FAMILY_16H_MODEL_00_MISC_CONTROL_DEVICE_ID, 0x30 => FAMILY_16H_MODEL_30_MISC_CONTROL_DEVICE_ID, - _ => 0, + _ => 0 }; break; default: @@ -161,10 +161,12 @@ namespace LibreHardwareMonitor.Hardware.CPU { Ring0.ReadPciConfig(addr, 8, out uint rev); - if (dev == 0x43851002) - _cStatesIoOffset = (byte)((rev & 0xFF) < 0x40 ? 0xB3 : 0x9C); - else if (dev is 0x780B1022 or 0x790B1022) - _cStatesIoOffset = 0x9C; + _cStatesIoOffset = dev switch + { + 0x43851002 => (byte)((rev & 0xFF) < 0x40 ? 0xB3 : 0x9C), + 0x780B1022 or 0x790B1022 => 0x9C, + _ => _cStatesIoOffset + }; } if (_cStatesIoOffset != 0) @@ -288,7 +290,7 @@ namespace LibreHardwareMonitor.Hardware.CPU 6 => 8, 7 => 12, 8 => 16, - _ => 1, + _ => 1 }; return (cpuFid + 0x10) / divisor; @@ -314,7 +316,7 @@ namespace LibreHardwareMonitor.Hardware.CPU { stream.Seek(0, SeekOrigin.Begin); int b = stream.ReadByte(); - while (b is not (-1) and not 10) + while (b is not -1 and not 10) { stringBuilder.Append((char)b); b = stream.ReadByte(); @@ -447,7 +449,7 @@ namespace LibreHardwareMonitor.Hardware.CPU } } - private bool ReadSmuRegister(uint address, out uint value) + private static bool ReadSmuRegister(uint address, out uint value) { if (Ring0.WaitPciBusMutex(10)) { diff --git a/LibreHardwareMonitorLib/Hardware/Cpu/Amd17Cpu.cs b/LibreHardwareMonitorLib/Hardware/Cpu/Amd17Cpu.cs index ef3d0af..2c847d7 100644 --- a/LibreHardwareMonitorLib/Hardware/Cpu/Amd17Cpu.cs +++ b/LibreHardwareMonitorLib/Hardware/Cpu/Amd17Cpu.cs @@ -145,7 +145,6 @@ namespace LibreHardwareMonitor.Hardware.CPU if (cpuId == null) return; - GroupAffinity previousAffinity = ThreadAffinity.Set(cpuId.Affinity); // MSRC001_0299 @@ -490,7 +489,6 @@ namespace LibreHardwareMonitor.Hardware.CPU if (cpu == null) return; - GroupAffinity previousAffinity = ThreadAffinity.Set(cpu.Affinity); // MSRC001_0299 @@ -502,8 +500,7 @@ namespace LibreHardwareMonitor.Hardware.CPU // MSRC001_029A // total_energy [31:0] DateTime sampleTime = DateTime.Now; - uint eax; - Ring0.ReadMsr(MSR_CORE_ENERGY_STAT, out eax, out _); + Ring0.ReadMsr(MSR_CORE_ENERGY_STAT, out uint eax, out _); uint totalEnergy = eax; // MSRC001_0293 diff --git a/LibreHardwareMonitorLib/Hardware/Cpu/CpuId.cs b/LibreHardwareMonitorLib/Hardware/Cpu/CpuId.cs index 4ea2268..a5a642e 100644 --- a/LibreHardwareMonitorLib/Hardware/Cpu/CpuId.cs +++ b/LibreHardwareMonitorLib/Hardware/Cpu/CpuId.cs @@ -53,7 +53,7 @@ namespace LibreHardwareMonitor.Hardware.CPU { "GenuineIntel" => Vendor.Intel, "AuthenticAMD" => Vendor.AMD, - _ => Vendor.Unknown, + _ => Vendor.Unknown }; if (OpCode.CpuId(CPUID_EXT, 0, out eax, out _, out _, out _)) diff --git a/LibreHardwareMonitorLib/Hardware/Cpu/CpuLoad.cs b/LibreHardwareMonitorLib/Hardware/Cpu/CpuLoad.cs index f899a7d..c345510 100644 --- a/LibreHardwareMonitorLib/Hardware/Cpu/CpuLoad.cs +++ b/LibreHardwareMonitorLib/Hardware/Cpu/CpuLoad.cs @@ -12,7 +12,6 @@ namespace LibreHardwareMonitor.Hardware.CPU { internal class CpuLoad { - private readonly CpuId[][] _cpuid; private long[] _idleTimes; private readonly float[] _threadLoads; private float _totalLoad; @@ -20,7 +19,6 @@ namespace LibreHardwareMonitor.Hardware.CPU public CpuLoad(CpuId[][] cpuid) { - _cpuid = cpuid; _threadLoads = new float[cpuid.Sum(x => x.Length)]; _totalLoad = 0; try diff --git a/LibreHardwareMonitorLib/Hardware/Cpu/GenericCpu.cs b/LibreHardwareMonitorLib/Hardware/Cpu/GenericCpu.cs index cfe056d..c8a071f 100644 --- a/LibreHardwareMonitorLib/Hardware/Cpu/GenericCpu.cs +++ b/LibreHardwareMonitorLib/Hardware/Cpu/GenericCpu.cs @@ -129,13 +129,13 @@ namespace LibreHardwareMonitor.Hardware.CPU { Vendor.AMD => "amdcpu", Vendor.Intel => "intelcpu", - _ => "genericcpu", + _ => "genericcpu" }; return new Identifier(s, processorIndex.ToString(CultureInfo.InvariantCulture)); } - private void EstimateTimeStampCounterFrequency(out double frequency, out double error) + private static void EstimateTimeStampCounterFrequency(out double frequency, out double error) { // preload the function EstimateTimeStampCounterFrequency(0, out double f, out double e); diff --git a/LibreHardwareMonitorLib/Hardware/Cpu/IntelCpu.cs b/LibreHardwareMonitorLib/Hardware/Cpu/IntelCpu.cs index 6ab218a..bcc7bc0 100644 --- a/LibreHardwareMonitorLib/Hardware/Cpu/IntelCpu.cs +++ b/LibreHardwareMonitorLib/Hardware/Cpu/IntelCpu.cs @@ -34,7 +34,6 @@ namespace LibreHardwareMonitor.Hardware.CPU public IntelCpu(int processorIndex, CpuId[][] cpuId, ISettings settings) : base(processorIndex, cpuId, settings) { uint eax; - uint edx; // set tjMax float[] tjMax; @@ -53,13 +52,13 @@ namespace LibreHardwareMonitor.Hardware.CPU { 2 => Floats(80 + 10), 4 => Floats(90 + 10), - _ => Floats(85 + 10), + _ => Floats(85 + 10) }, // G0 0x0B => Floats(90 + 10), // M0 0x0D => Floats(85 + 10), - _ => Floats(85 + 10), + _ => Floats(85 + 10) }; break; @@ -76,7 +75,7 @@ namespace LibreHardwareMonitor.Hardware.CPU 0x02 => Floats(90), // A0, B0 0x0A => Floats(100), - _ => Floats(90), + _ => Floats(90) }; break; @@ -257,7 +256,7 @@ namespace LibreHardwareMonitor.Hardware.CPU case MicroArchitecture.Atom: case MicroArchitecture.Core: case MicroArchitecture.NetBurst: - if (Ring0.ReadMsr(IA32_PERF_STATUS, out uint _, out edx)) + if (Ring0.ReadMsr(IA32_PERF_STATUS, out uint _, out uint edx)) _timeStampCounterMultiplier = ((edx >> 8) & 0x1f) + (0.5 * ((edx >> 14) & 1)); break; @@ -403,7 +402,7 @@ namespace LibreHardwareMonitor.Hardware.CPU EnergyUnitsMultiplier = _microArchitecture switch { MicroArchitecture.Silvermont or MicroArchitecture.Airmont => 1.0e-6f * (1 << (int)((eax >> 8) & 0x1F)), - _ => 1.0f / (1 << (int)((eax >> 8) & 0x1F)), + _ => 1.0f / (1 << (int)((eax >> 8) & 0x1F)) }; } @@ -509,13 +508,12 @@ namespace LibreHardwareMonitor.Hardware.CPU float coreMax = float.MinValue; float coreAvg = 0; - uint eax = 0; - uint edx; + uint eax; for (int i = 0; i < _coreTemperatures.Length; i++) { // if reading is valid - if (Ring0.ReadMsr(IA32_THERM_STATUS_MSR, out eax, out uint _, _cpuId[i][0].Affinity) && (eax & 0x80000000) != 0) + if (Ring0.ReadMsr(IA32_THERM_STATUS_MSR, out eax, out _, _cpuId[i][0].Affinity) && (eax & 0x80000000) != 0) { // get the dist from tjMax from bits 22:16 float deltaT = (eax & 0x007F0000) >> 16; @@ -547,7 +545,7 @@ namespace LibreHardwareMonitor.Hardware.CPU if (_packageTemperature != null) { // if reading is valid - if (Ring0.ReadMsr(IA32_PACKAGE_THERM_STATUS, out eax, out uint _, _cpuId[0][0].Affinity) && (eax & 0x80000000) != 0) + if (Ring0.ReadMsr(IA32_PACKAGE_THERM_STATUS, out eax, out _, _cpuId[0][0].Affinity) && (eax & 0x80000000) != 0) { // get the dist from tjMax from bits 22:16 float deltaT = (eax & 0x007F0000) >> 16; @@ -567,7 +565,7 @@ namespace LibreHardwareMonitor.Hardware.CPU for (int i = 0; i < _coreClocks.Length; i++) { System.Threading.Thread.Sleep(1); - if (Ring0.ReadMsr(IA32_PERF_STATUS, out eax, out uint _, _cpuId[i][0].Affinity)) + if (Ring0.ReadMsr(IA32_PERF_STATUS, out eax, out _, _cpuId[i][0].Affinity)) { newBusClock = TimeStampCounterFrequency / _timeStampCounterMultiplier; switch (_microArchitecture) @@ -622,7 +620,7 @@ namespace LibreHardwareMonitor.Hardware.CPU if (sensor == null) continue; - if (!Ring0.ReadMsr(_energyStatusMsrs[sensor.Index], out eax, out uint _)) + if (!Ring0.ReadMsr(_energyStatusMsrs[sensor.Index], out eax, out _)) continue; DateTime time = DateTime.UtcNow; @@ -637,7 +635,7 @@ namespace LibreHardwareMonitor.Hardware.CPU } } - if (_coreVoltage != null && Ring0.ReadMsr(IA32_PERF_STATUS, out _, out edx)) + if (_coreVoltage != null && Ring0.ReadMsr(IA32_PERF_STATUS, out _, out uint edx)) { _coreVoltage.Value = ((edx >> 32) & 0xFFFF) / (float)(1 << 13); } diff --git a/LibreHardwareMonitorLib/Hardware/D3DDisplayDevice.cs b/LibreHardwareMonitorLib/Hardware/D3DDisplayDevice.cs index 38d2ca7..edc06ac 100644 --- a/LibreHardwareMonitorLib/Hardware/D3DDisplayDevice.cs +++ b/LibreHardwareMonitorLib/Hardware/D3DDisplayDevice.cs @@ -141,7 +141,7 @@ namespace LibreHardwareMonitor.Hardware D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_COPY => "D3D Copy", D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_OVERLAY => "D3D Overlay", D3dkmdt.DXGK_ENGINE_TYPE.DXGK_ENGINE_TYPE_CRYPTO => "D3D Crypto", - _ => "D3D Unknown", + _ => "D3D Unknown" }; } @@ -226,7 +226,7 @@ namespace LibreHardwareMonitor.Hardware D3dkmth.D3DKMT_OPENADAPTERFROMDEVICENAME adapter, out D3dkmth.D3DKMT_QUERYSTATISTICS_ADAPTER_INFORMATION adapterInformation) { - var queryStatistics = new D3dkmth.D3DKMT_QUERYSTATISTICS { AdapterLuid = adapter.AdapterLuid, Type = D3dkmth.D3DKMT_QUERYSTATISTICS_TYPE.D3DKMT_QUERYSTATISTICS_ADAPTER, }; + var queryStatistics = new D3dkmth.D3DKMT_QUERYSTATISTICS { AdapterLuid = adapter.AdapterLuid, Type = D3dkmth.D3DKMT_QUERYSTATISTICS_TYPE.D3DKMT_QUERYSTATISTICS_ADAPTER }; status = Gdi32.D3DKMTQueryStatistics(ref queryStatistics); diff --git a/LibreHardwareMonitorLib/Hardware/Gpu/NvidiaGpu.cs b/LibreHardwareMonitorLib/Hardware/Gpu/NvidiaGpu.cs index 23cf8bf..b8dd3db 100644 --- a/LibreHardwareMonitorLib/Hardware/Gpu/NvidiaGpu.cs +++ b/LibreHardwareMonitorLib/Hardware/Gpu/NvidiaGpu.cs @@ -213,7 +213,7 @@ namespace LibreHardwareMonitor.Hardware.Gpu for (int i = 0; i < coolerSettings.Count; i++) { NvApi.NvCooler cooler = coolerSettings.Cooler[i]; - string name = "GPU Fan" + (coolerSettings.Count > 1 ? " " + (cooler.Controller) : string.Empty); + string name = "GPU Fan" + (coolerSettings.Count > 1 ? " " + cooler.Controller : string.Empty); _controls[i] = new Sensor(name, i, SensorType.Control, this, settings); ActivateSensor(_controls[i]); @@ -991,7 +991,7 @@ namespace LibreHardwareMonitor.Hardware.Gpu NvApi.NvThermalSettings settings = new() { Version = (uint)NvApi.MAKE_NVAPI_VERSION(1), - Count = NvApi.MAX_THERMAL_SENSORS_PER_GPU, + Count = NvApi.MAX_THERMAL_SENSORS_PER_GPU }; status = NvApi.NvAPI_GPU_GetThermalSettings(_handle, (int)NvApi.NvThermalTarget.All, ref settings); diff --git a/LibreHardwareMonitorLib/Hardware/KernelDriver.cs b/LibreHardwareMonitorLib/Hardware/KernelDriver.cs index 9df1550..f19f433 100644 --- a/LibreHardwareMonitorLib/Hardware/KernelDriver.cs +++ b/LibreHardwareMonitorLib/Hardware/KernelDriver.cs @@ -117,7 +117,6 @@ namespace LibreHardwareMonitor.Hardware if (_device == null) return false; - return Kernel32.DeviceIoControl(_device, ioControlCode, inBuffer, inBuffer == null ? 0 : (uint)Marshal.SizeOf(inBuffer), null, 0, out uint _, IntPtr.Zero); } @@ -126,7 +125,6 @@ namespace LibreHardwareMonitor.Hardware if (_device == null) return false; - object boxedOutBuffer = outBuffer; bool b = Kernel32.DeviceIoControl(_device, ioControlCode, @@ -146,7 +144,6 @@ namespace LibreHardwareMonitor.Hardware if (_device == null) return false; - object boxedOutBuffer = outBuffer; bool b = Kernel32.DeviceIoControl(_device, ioControlCode, @@ -177,7 +174,6 @@ namespace LibreHardwareMonitor.Hardware if (manager == IntPtr.Zero) return false; - IntPtr service = AdvApi32.OpenService(manager, _serviceName, AdvApi32.SERVICE_ACCESS_MASK.SERVICE_ALL_ACCESS); if (service == IntPtr.Zero) { diff --git a/LibreHardwareMonitorLib/Hardware/Memory/GenericLinuxMemory.cs b/LibreHardwareMonitorLib/Hardware/Memory/GenericLinuxMemory.cs index 057743f..022c4c7 100644 --- a/LibreHardwareMonitorLib/Hardware/Memory/GenericLinuxMemory.cs +++ b/LibreHardwareMonitorLib/Hardware/Memory/GenericLinuxMemory.cs @@ -18,10 +18,8 @@ namespace LibreHardwareMonitor.Hardware.Memory private readonly Sensor _virtualMemoryLoad; private readonly Sensor _virtualMemoryUsed; - public override HardwareType HardwareType => HardwareType.Memory; - public GenericLinuxMemory(string name, ISettings settings) : base(name, new Identifier("ram"), settings) { _physicalMemoryUsed = new Sensor("Memory Used", 0, SensorType.Data, this, settings); @@ -43,7 +41,6 @@ namespace LibreHardwareMonitor.Hardware.Memory ActivateSensor(_virtualMemoryLoad); } - public override void Update() { try @@ -83,7 +80,7 @@ namespace LibreHardwareMonitor.Hardware.Memory } } - private long GetMemInfoValue(string line) + private static long GetMemInfoValue(string line) { // Example: "MemTotal: 32849676 kB" diff --git a/LibreHardwareMonitorLib/Hardware/Memory/MemoryGroup.cs b/LibreHardwareMonitorLib/Hardware/Memory/MemoryGroup.cs index 9df7da3..ce9cb6c 100644 --- a/LibreHardwareMonitorLib/Hardware/Memory/MemoryGroup.cs +++ b/LibreHardwareMonitorLib/Hardware/Memory/MemoryGroup.cs @@ -14,14 +14,7 @@ namespace LibreHardwareMonitor.Hardware.Memory public MemoryGroup(ISettings settings) { - if (Software.OperatingSystem.IsUnix) - { - _hardware = new Hardware[] { new GenericLinuxMemory("Generic Memory", settings) }; - } - else - { - _hardware = new Hardware[] { new GenericWindowsMemory("Generic Memory", settings) }; - } + _hardware = new Hardware[] { Software.OperatingSystem.IsUnix ? new GenericLinuxMemory("Generic Memory", settings) : new GenericWindowsMemory("Generic Memory", settings) }; } public string GetReport() diff --git a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/EC/EmbeddedController.cs b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/EC/EmbeddedController.cs index 1660d5c..75bd9cd 100644 --- a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/EC/EmbeddedController.cs +++ b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/EC/EmbeddedController.cs @@ -154,7 +154,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC ECSensor.TempChipset, ECSensor.FanWaterPump, ECSensor.CurrCPU, - ECSensor.VoltageCPU), + ECSensor.VoltageCPU) }; private static readonly Dictionary> _knownSensors = new() @@ -173,7 +173,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC { ECSensor.FanWaterFlow, new EmbeddedControllerSource("Water flow", SensorType.Flow, 0x00b4, 2, factor: 1.0f / 42f * 60f) }, { ECSensor.CurrCPU, new EmbeddedControllerSource("CPU", SensorType.Current, 0x00f4) }, { ECSensor.TempWaterIn, new EmbeddedControllerSource("Water In", SensorType.Temperature, 0x010d, blank: -40) }, - { ECSensor.TempWaterOut, new EmbeddedControllerSource("Water Out", SensorType.Temperature, 0x010b, blank: -40) }, + { ECSensor.TempWaterOut, new EmbeddedControllerSource("Water Out", SensorType.Temperature, 0x010b, blank: -40) } } }, { @@ -192,7 +192,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC { ECSensor.FanWaterFlow, new EmbeddedControllerSource("Water flow", SensorType.Flow, 0x00bc, 2, factor: 1.0f / 42f * 60f) }, { ECSensor.CurrCPU, new EmbeddedControllerSource("CPU", SensorType.Current, 0x00f4) }, { ECSensor.TempWaterIn, new EmbeddedControllerSource("Water In", SensorType.Temperature, 0x0100, blank: -40) }, - { ECSensor.TempWaterOut, new EmbeddedControllerSource("Water Out", SensorType.Temperature, 0x0101, blank: -40) }, + { ECSensor.TempWaterOut, new EmbeddedControllerSource("Water Out", SensorType.Temperature, 0x0101, blank: -40) } } }, { @@ -202,7 +202,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC { ECSensor.TempTSensor, new EmbeddedControllerSource("T Sensor", SensorType.Temperature, 0x003d, blank: -40) }, { ECSensor.FanWaterPump, new EmbeddedControllerSource("Water Pump", SensorType.Fan, 0x00bc, 2) }, { ECSensor.CurrCPU, new EmbeddedControllerSource("CPU", SensorType.Current, 0x00f4) }, - { ECSensor.VoltageCPU, new EmbeddedControllerSource("CPU Core", SensorType.Voltage, 0x00a2, 2, factor: 1e-3f) }, + { ECSensor.VoltageCPU, new EmbeddedControllerSource("CPU Core", SensorType.Voltage, 0x00a2, 2, factor: 1e-3f) } } }, { @@ -213,9 +213,9 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC { ECSensor.TempWaterIn, new EmbeddedControllerSource("Water In", SensorType.Temperature, 0x0100, blank: -40) }, { ECSensor.TempWaterOut, new EmbeddedControllerSource("Water Out", SensorType.Temperature, 0x0101, blank: -40) }, { ECSensor.TempWaterBlockIn, new EmbeddedControllerSource("Water Block In", SensorType.Temperature, 0x0102, blank: -40) }, - { ECSensor.FanWaterFlow, new EmbeddedControllerSource("Water Flow", SensorType.Flow, 0x00be, 2, factor: 1.0f / 42f * 60f) }, // todo: need validation for this calculation + { ECSensor.FanWaterFlow, new EmbeddedControllerSource("Water Flow", SensorType.Flow, 0x00be, 2, factor: 1.0f / 42f * 60f) } // todo: need validation for this calculation } - }, + } }; private readonly byte[] _data; @@ -260,11 +260,13 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC internal static EmbeddedController Create(Model model, ISettings settings) { var boards = _boards.Where(b => b.Models.Contains(model)).ToList(); - if (boards.Count == 0) - return null; - - if (boards.Count > 1) - throw new MultipleBoardRecordsFoundException(model.ToString()); + switch (boards.Count) + { + case 0: + return null; + case > 1: + throw new MultipleBoardRecordsFoundException(model.ToString()); + } BoardInfo board = boards[0]; IEnumerable sources = board.Sensors.Select(ecs => _knownSensors[board.Family][ecs]); @@ -291,7 +293,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC { 1 => unchecked((sbyte)_data[readRegister]), 2 => unchecked((short)((_data[readRegister] << 8) + _data[readRegister + 1])), - _ => 0, + _ => 0 }; readRegister += _sources[si].Size; @@ -414,7 +416,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC Amd400, Amd500, Intel100, - Intel600, + Intel600 } private struct BoardInfo diff --git a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/EC/WindowsEmbeddedControllerIO.cs b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/EC/WindowsEmbeddedControllerIO.cs index 82347e6..5295429 100644 --- a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/EC/WindowsEmbeddedControllerIO.cs +++ b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/EC/WindowsEmbeddedControllerIO.cs @@ -73,7 +73,6 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC WriteLoop(register, value, WriteByteOp); } - public void Dispose() { if (!_disposed) @@ -202,7 +201,6 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc.EC SmiEventPending = 0x40 // SMI_EVT } - #region Read/Write ops protected bool ReadByteOp(byte register, out byte value) diff --git a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/IT87XX.cs b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/IT87XX.cs index 3d003b8..12f7def 100644 --- a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/IT87XX.cs +++ b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/IT87XX.cs @@ -180,7 +180,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc Chip.IT8613E or Chip.IT8620E or Chip.IT8628E or Chip.IT8631E or Chip.IT8721F or Chip.IT8728F or Chip.IT8771E or Chip.IT8772E or Chip.IT8686E or Chip.IT8688E or Chip.IT8689E => 0.012f, Chip.IT8695E => 11f / 1000f, Chip.IT8655E or Chip.IT8665E or Chip.IT879XE => 0.0109f, - _ => 0.016f, + _ => 0.016f }; // Older IT8705F and IT8721F revisions do not have 16-bit fan counters. @@ -209,7 +209,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc { Chip.IT8712F or Chip.IT8716F or Chip.IT8718F or Chip.IT8726F => 5, Chip.IT8720F or Chip.IT8721F => 8, - _ => 0, + _ => 0 }; } @@ -558,7 +558,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc // Address of the Fan Controller Main Control Register. // No need for the 2nd control register (bit 7 of 0x15 0x16 0x17), // as PWM value will set it to manual mode when new value is set. - private readonly byte FAN_MAIN_CTRL_REG = 0x13; + private const byte FAN_MAIN_CTRL_REG = 0x13; #pragma warning restore IDE1006 // Naming Styles // ReSharper restore InconsistentNaming diff --git a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/LMSensors.cs b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/LMSensors.cs index f333bcc..e34b8d7 100644 --- a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/LMSensors.cs +++ b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/LMSensors.cs @@ -29,8 +29,8 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc string name = null; try { - using (StreamReader reader = new(path + "/name")) - name = reader.ReadLine(); + using StreamReader reader = new(path + "/name"); + name = reader.ReadLine(); } catch (IOException) { } @@ -260,14 +260,14 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc } } - private string ReadFirstLine(Stream stream) + private static string ReadFirstLine(Stream stream) { StringBuilder sb = new(); try { stream.Seek(0, SeekOrigin.Begin); int b = stream.ReadByte(); - while (b is not (-1) and not 10) + while (b is not -1 and not 10) { sb.Append((char)b); b = stream.ReadByte(); diff --git a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/LpcIO.cs b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/LpcIO.cs index 3a0f25c..a615e5a 100644 --- a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/LpcIO.cs +++ b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/LpcIO.cs @@ -520,76 +520,31 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc port.IT87Enter(); ushort chipId = port.ReadWord(CHIP_ID_REGISTER); - Chip chip; - switch (chipId) + Chip chip = chipId switch { - case 0x8613: - chip = Chip.IT8613E; - break; - case 0x8620: - chip = Chip.IT8620E; - break; - case 0x8628: - chip = Chip.IT8628E; - break; - case 0x8631: - chip = Chip.IT8631E; - break; - case 0x8665: - chip = Chip.IT8665E; - break; - case 0x8655: - chip = Chip.IT8655E; - break; - case 0x8686: - chip = Chip.IT8686E; - break; - case 0x8688: - chip = Chip.IT8688E; - break; - case 0x8689: - chip = Chip.IT8689E; - break; - case 0x8695: - chip = Chip.IT8695E; - break; - case 0x8705: - chip = Chip.IT8705F; - break; - case 0x8712: - chip = Chip.IT8712F; - break; - case 0x8716: - chip = Chip.IT8716F; - break; - case 0x8718: - chip = Chip.IT8718F; - break; - case 0x8720: - chip = Chip.IT8720F; - break; - case 0x8721: - chip = Chip.IT8721F; - break; - case 0x8726: - chip = Chip.IT8726F; - break; - case 0x8728: - chip = Chip.IT8728F; - break; - case 0x8771: - chip = Chip.IT8771E; - break; - case 0x8772: - chip = Chip.IT8772E; - break; - case 0x8733: - chip = Chip.IT879XE; - break; - default: - chip = Chip.Unknown; - break; - } + 0x8613 => Chip.IT8613E, + 0x8620 => Chip.IT8620E, + 0x8628 => Chip.IT8628E, + 0x8631 => Chip.IT8631E, + 0x8665 => Chip.IT8665E, + 0x8655 => Chip.IT8655E, + 0x8686 => Chip.IT8686E, + 0x8688 => Chip.IT8688E, + 0x8689 => Chip.IT8689E, + 0x8695 => Chip.IT8695E, + 0x8705 => Chip.IT8705F, + 0x8712 => Chip.IT8712F, + 0x8716 => Chip.IT8716F, + 0x8718 => Chip.IT8718F, + 0x8720 => Chip.IT8720F, + 0x8721 => Chip.IT8721F, + 0x8726 => Chip.IT8726F, + 0x8728 => Chip.IT8728F, + 0x8771 => Chip.IT8771E, + 0x8772 => Chip.IT8772E, + 0x8733 => Chip.IT879XE, + _ => Chip.Unknown + }; if (chip == Chip.Unknown) { diff --git a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/Nct677X.cs b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/Nct677X.cs index 9b1adec..b5e857e 100644 --- a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/Nct677X.cs +++ b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/Nct677X.cs @@ -32,7 +32,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc public readonly int HalfBit; public readonly ushort SourceRegister; public readonly ushort? AlternateRegister; - }; + } private readonly ushort[] _fanCountRegister; private readonly ushort[] _fanRpmRegister; @@ -280,7 +280,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc new(null, 0x106), new(null, 0x108), new(null, 0x10A), - new(null, 0x10C), + new(null, 0x10C) }; // VIN0 +12V @@ -426,7 +426,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc if (valid && _voltageRegisters[i] == _voltageVBatRegister) valid = (ReadByte(_vBatMonitorControlRegister) & 0x01) > 0; - Voltages[i] = valid ? value : (float?)null; + Voltages[i] = valid ? value : null; } else { @@ -501,7 +501,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc temperature = 0.5f * value; System.Diagnostics.Debug.WriteLine("Temperature register {0} final temperature: {1}.", i, temperature); - if (temperature is > 125 or < (-55)) + if (temperature is > 125 or < -55) { temperature = null; System.Diagnostics.Debug.WriteLine("Temperature register {0} discarded: Out of range.", i); @@ -533,7 +533,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc temperatureSourceMask |= 1L << (byte)source; temperature = 0.5f * value; - if (temperature is > 125 or < (-55)) + if (temperature is > 125 or < -55) temperature = null; for (int j = 0; j < Temperatures.Length; j++) diff --git a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/W836XX.cs b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/W836XX.cs index 3898dd3..117ff3c 100644 --- a/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/W836XX.cs +++ b/LibreHardwareMonitorLib/Hardware/Motherboard/Lpc/W836XX.cs @@ -35,7 +35,6 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc private readonly byte[] _initialFanTertiaryControlValue = Array.Empty(); private readonly bool[] _restoreDefaultFanPwmControlRequired = Array.Empty(); - public W836XX(Chip chip, byte revision, ushort address) { _address = address; @@ -376,12 +375,16 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc Fans[i] = count < 0xff ? 1.35e6f / (count * divisor) : 0; - // update fan divisor - if (count > 192 && divisorBits < 7) - divisorBits++; - - if (count < 96 && divisorBits > 0) - divisorBits--; + switch (count) + { + // update fan divisor + case > 192 when divisorBits < 7: + divisorBits++; + break; + case < 96 when divisorBits > 0: + divisorBits--; + break; + } newBits = SetBit(newBits, FAN_DIV_BIT2[i], (divisorBits >> 2) & 1); newBits = SetBit(newBits, FAN_DIV_BIT1[i], (divisorBits >> 1) & 1); @@ -391,7 +394,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard.Lpc for (int i = 0; i < Controls.Length; i++) { byte value = ReadByte(0, _fanPwmRegister[i]); - Controls[i] = (float)Math.Round((value) * 100.0f / 0xFF); + Controls[i] = (float)Math.Round(value * 100.0f / 0xFF); } Ring0.ReleaseIsaBusMutex(); diff --git a/LibreHardwareMonitorLib/Hardware/Motherboard/SuperIOHardware.cs b/LibreHardwareMonitorLib/Hardware/Motherboard/SuperIOHardware.cs index ba842ef..025e28b 100644 --- a/LibreHardwareMonitorLib/Hardware/Motherboard/SuperIOHardware.cs +++ b/LibreHardwareMonitorLib/Hardware/Motherboard/SuperIOHardware.cs @@ -2146,7 +2146,6 @@ namespace LibreHardwareMonitor.Hardware.Motherboard break; - case Model.AB350_Pro4: //NCT6779D case Model.AB350M_Pro4: case Model.AB350M: @@ -2288,7 +2287,6 @@ namespace LibreHardwareMonitor.Hardware.Motherboard c.Add(new Ctrl("Chipset Fan", 3)); break; - default: v.Add(new Voltage("Vcore", 0, 10, 10)); v.Add(new Voltage("Voltage #2", 1, true)); @@ -2526,7 +2524,7 @@ namespace LibreHardwareMonitor.Hardware.Motherboard fanControlNames = new[] {"Chassis Fan 1", "CPU Fan", "Chassis Fan 2", "Chassis Fan 3", "High Amp Fan", "W_PUMP+", "AIO Pump"}; System.Diagnostics.Debug.Assert(fanControlNames.Length == superIO.Fans.Length, - string.Format("Expected {0} fan register in the SuperIO chip", fanControlNames.Length)); + $"Expected {fanControlNames.Length} fan register in the SuperIO chip"); System.Diagnostics.Debug.Assert(superIO.Fans.Length == superIO.Controls.Length, "Expected counts of cans controls and fan speed registers to be equal"); diff --git a/LibreHardwareMonitorLib/Hardware/Network/Network.cs b/LibreHardwareMonitorLib/Hardware/Network/Network.cs index c77be5f..b174747 100644 --- a/LibreHardwareMonitorLib/Hardware/Network/Network.cs +++ b/LibreHardwareMonitorLib/Hardware/Network/Network.cs @@ -53,7 +53,6 @@ namespace LibreHardwareMonitor.Hardware.Network if (NetworkInterface == null) return; - long newTick = Stopwatch.GetTimestamp(); double dt = new TimeSpan(newTick - _lastTick).TotalSeconds; diff --git a/LibreHardwareMonitorLib/Hardware/Network/NetworkGroup.cs b/LibreHardwareMonitorLib/Hardware/Network/NetworkGroup.cs index 5b76e3e..8a9302f 100644 --- a/LibreHardwareMonitorLib/Hardware/Network/NetworkGroup.cs +++ b/LibreHardwareMonitorLib/Hardware/Network/NetworkGroup.cs @@ -19,7 +19,7 @@ namespace LibreHardwareMonitor.Hardware.Network private readonly Dictionary _networks = new(); private readonly object _scanLock = new(); private readonly ISettings _settings; - private List _hardware = new(); + private readonly List _hardware = new(); public NetworkGroup(ISettings settings) { diff --git a/LibreHardwareMonitorLib/Hardware/Psu/Corsair/CorsairPsu.cs b/LibreHardwareMonitorLib/Hardware/Psu/Corsair/CorsairPsu.cs index 59ead84..05e77fe 100644 --- a/LibreHardwareMonitorLib/Hardware/Psu/Corsair/CorsairPsu.cs +++ b/LibreHardwareMonitorLib/Hardware/Psu/Corsair/CorsairPsu.cs @@ -237,7 +237,6 @@ namespace LibreHardwareMonitor.Hardware.Psu.Corsair } } - #region Exception classes public class CommunicationProtocolError : ApplicationException @@ -249,7 +248,6 @@ namespace LibreHardwareMonitor.Hardware.Psu.Corsair #endregion - #region PSU USB communication protocol implementation internal static class UsbApi @@ -267,8 +265,8 @@ namespace LibreHardwareMonitor.Hardware.Psu.Corsair #endif static float Linear11ToFloat32(ushort val) { - int exp = ((short)val) >> 11; - int mant = (((short)(val & 0x7ff)) << 5) >> 5; + int exp = (short)val >> 11; + int mant = ((short)(val & 0x7ff) << 5) >> 5; return mant * (float)Math.Pow(2, exp); } @@ -404,7 +402,7 @@ namespace LibreHardwareMonitor.Hardware.Psu.Corsair Command.RAIL_VOLTS_HCRIT or Command.RAIL_VOLTS_LCRIT or Command.RAIL_AMPS_HCRIT or Command.TEMP_HCRIT or Command.IN_VOLTS or Command.IN_AMPS or Command.RAIL_VOLTS or Command.RAIL_AMPS or Command.TEMP0 or Command.TEMP1 or Command.FAN_RPM or Command.RAIL_WATTS or Command.TOTAL_WATTS => Linear11ToFloat32((ushort)tmp), // Linear11ToInt((ushort)tmp, 1000000); Command.TOTAL_UPTIME or Command.UPTIME or Command.OCPMODE => tmp, - _ => null, + _ => null }; } diff --git a/LibreHardwareMonitorLib/Hardware/Psu/Corsair/CorsairPsuGroup.cs b/LibreHardwareMonitorLib/Hardware/Psu/Corsair/CorsairPsuGroup.cs index 871c062..3b6103e 100644 --- a/LibreHardwareMonitorLib/Hardware/Psu/Corsair/CorsairPsuGroup.cs +++ b/LibreHardwareMonitorLib/Hardware/Psu/Corsair/CorsairPsuGroup.cs @@ -25,7 +25,7 @@ namespace LibreHardwareMonitor.Hardware.Psu.Corsair 0x1c0a, // RM650i 0x1c0b, // RM750i 0x1c0c, // RM850i - 0x1c0d, // RM1000i + 0x1c0d // RM1000i // 0x1c11, // AX1600i }; diff --git a/LibreHardwareMonitorLib/Hardware/Ring0.cs b/LibreHardwareMonitorLib/Hardware/Ring0.cs index 40aec23..75f11eb 100644 --- a/LibreHardwareMonitorLib/Hardware/Ring0.cs +++ b/LibreHardwareMonitorLib/Hardware/Ring0.cs @@ -73,7 +73,7 @@ namespace LibreHardwareMonitor.Hardware } else { - _report.Append("Status: Installing driver \"").Append(_filePath).Append("\" failed").AppendLine((File.Exists(_filePath) ? " and file exists" : string.Empty)); + _report.Append("Status: Installing driver \"").Append(_filePath).Append("\" failed").AppendLine(File.Exists(_filePath) ? " and file exists" : string.Empty); _report.Append("First Exception: ").AppendLine(installError); _report.Append("Second Exception: ").AppendLine(secondError); } diff --git a/LibreHardwareMonitorLib/Hardware/RyzenSMU.cs b/LibreHardwareMonitorLib/Hardware/RyzenSMU.cs index a14064d..8956d66 100644 --- a/LibreHardwareMonitorLib/Hardware/RyzenSMU.cs +++ b/LibreHardwareMonitorLib/Hardware/RyzenSMU.cs @@ -50,7 +50,7 @@ namespace LibreHardwareMonitor.Hardware { 166, new SmuSensorType { Name = "Fabric", Type = SensorType.Clock, Scale = 1 } }, { 177, new SmuSensorType { Name = "Uncore", Type = SensorType.Clock, Scale = 1 } }, { 178, new SmuSensorType { Name = "Memory", Type = SensorType.Clock, Scale = 1 } }, - { 342, new SmuSensorType { Name = "Displays", Type = SensorType.Factor, Scale = 1 } }, + { 342, new SmuSensorType { Name = "Displays", Type = SensorType.Factor, Scale = 1 } } } }, { @@ -62,7 +62,7 @@ namespace LibreHardwareMonitor.Hardware { 48, new SmuSensorType { Name = "Fabric", Type = SensorType.Clock, Scale = 1 } }, { 50, new SmuSensorType { Name = "Uncore", Type = SensorType.Clock, Scale = 1 } }, { 51, new SmuSensorType { Name = "Memory", Type = SensorType.Clock, Scale = 1 } }, - { 115, new SmuSensorType { Name = "SoC", Type = SensorType.Temperature, Scale = 1 } }, + { 115, new SmuSensorType { Name = "SoC", Type = SensorType.Temperature, Scale = 1 } } //{ 66, new SmuSensorType { Name = "Bus Speed", Type = SensorType.Clock, Scale = 1 } }, //{ 188, new SmuSensorType { Name = "Core #1", Type = SensorType.Clock, Scale = 1000 } }, //{ 189, new SmuSensorType { Name = "Core #2", Type = SensorType.Clock, Scale = 1000 } }, @@ -99,7 +99,7 @@ namespace LibreHardwareMonitor.Hardware { 280, new SmuSensorType { Name = "Core #13 (Effective)", Type = SensorType.Clock, Scale = 1000 } }, { 281, new SmuSensorType { Name = "Core #14 (Effective)", Type = SensorType.Clock, Scale = 1000 } }, { 282, new SmuSensorType { Name = "Core #15 (Effective)", Type = SensorType.Clock, Scale = 1000 } }, - { 283, new SmuSensorType { Name = "Core #16 (Effective)", Type = SensorType.Clock, Scale = 1000 } }, + { 283, new SmuSensorType { Name = "Core #16 (Effective)", Type = SensorType.Clock, Scale = 1000 } } } } }; @@ -141,7 +141,7 @@ namespace LibreHardwareMonitor.Hardware 0x60 => CpuCodeName.Renoir, 0x71 => CpuCodeName.Matisse, 0x90 => CpuCodeName.Vangogh, - _ => CpuCodeName.Undefined, + _ => CpuCodeName.Undefined }; } @@ -153,7 +153,7 @@ namespace LibreHardwareMonitor.Hardware 0x20 or 0x21 => CpuCodeName.Vermeer, 0x40 => CpuCodeName.Rembrandt, 0x50 => CpuCodeName.Cezanne, - _ => CpuCodeName.Undefined, + _ => CpuCodeName.Undefined }; } diff --git a/LibreHardwareMonitorLib/Hardware/SMBios.cs b/LibreHardwareMonitorLib/Hardware/SMBios.cs index 274e300..149dd60 100644 --- a/LibreHardwareMonitorLib/Hardware/SMBios.cs +++ b/LibreHardwareMonitorLib/Hardware/SMBios.cs @@ -427,7 +427,7 @@ namespace LibreHardwareMonitor.Hardware _32Way, _48Way, _64Way, - _20Way, + _20Way } /// @@ -477,7 +477,7 @@ namespace LibreHardwareMonitor.Hardware HBM = 0x20, HBM2 = 0x21, DDR5 = 0x22, - LPDDR5 = 0x23, + LPDDR5 = 0x23 } public class InformationBase diff --git a/LibreHardwareMonitorLib/Hardware/Storage/ATAStorage.cs b/LibreHardwareMonitorLib/Hardware/Storage/ATAStorage.cs index bf785de..5692404 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/ATAStorage.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/ATAStorage.cs @@ -137,7 +137,6 @@ namespace LibreHardwareMonitor.Hardware.Storage if (!allAttributesFound) continue; - // check if there is a matching name prefix for this type if (type.GetCustomAttributes(typeof(NamePrefixAttribute), true) is NamePrefixAttribute[] namePrefixes) { diff --git a/LibreHardwareMonitorLib/Hardware/Storage/DebugSmart.cs b/LibreHardwareMonitorLib/Hardware/Storage/DebugSmart.cs index 10ac261..1fa5793 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/DebugSmart.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/DebugSmart.cs @@ -14,7 +14,7 @@ namespace LibreHardwareMonitor.Hardware.Storage internal class DebugSmart : ISmart { private readonly Drive[] _drives = { - new Drive("KINGSTON SNV425S264GB", null, 16, + new("KINGSTON SNV425S264GB", null, 16, @" 01 000000000000 100 100 02 000000000000 100 100 03 000000000000 100 100 @@ -32,7 +32,7 @@ namespace LibreHardwareMonitor.Hardware.Storage F0 000000000000 100 100 AA 07007B000000 100 100 AD 0E1E71304919 100 100"), - new Drive("PLEXTOR PX-128M2S", "1.03", 16, + new("PLEXTOR PX-128M2S", "1.03", 16, @" 01 000000000000 100 100 0 03 000000000000 100 100 0 04 000000000000 100 100 0 @@ -50,7 +50,7 @@ namespace LibreHardwareMonitor.Hardware.Storage C5 000000000000 100 100 0 C6 000000000000 100 100 0 C7 000000000000 100 100 0"), - new Drive("OCZ-VERTEX2", "1.25", 16, + new("OCZ-VERTEX2", "1.25", 16, @" 01 DADAD5000000 100 106 50 05 000000000000 100 100 3 09 DF0900004A2F 100 100 0 @@ -70,7 +70,7 @@ namespace LibreHardwareMonitor.Hardware.Storage EA 000600000000 0 0 0 F1 000600000000 0 0 0 F2 801200000000 0 0 0"), - new Drive("WDC WD5000AADS-00S9B0", null, 10, + new("WDC WD5000AADS-00S9B0", null, 10, @" 1 000000000000 200 200 3 820D00000000 149 150 4 610800000000 98 98 @@ -91,7 +91,7 @@ namespace LibreHardwareMonitor.Hardware.Storage 130 7B0300010002 1 41 5 000000000000 0 0 1 000000000000 0 0"), - new Drive("INTEL SSDSA2M080G2GC", null, 10, + new("INTEL SSDSA2M080G2GC", null, 10, @" 3 000000000000 100 100 4 000000000000 100 100 5 010000000000 100 100 @@ -106,7 +106,7 @@ namespace LibreHardwareMonitor.Hardware.Storage 233 000000000000 98 98 184 000000000000 100 100 1 000000000000 0 0"), - new Drive("OCZ-VERTEX", null, 10, + new("OCZ-VERTEX", null, 10, @" 1 000000000000 0 8 9 000000000000 30 99 12 000000000000 0 15 @@ -129,7 +129,7 @@ namespace LibreHardwareMonitor.Hardware.Storage 211 000000000000 0 0 212 000000000000 0 0 213 000000000000 0 0"), - new Drive("INTEL SSDSA2CW120G3", null, 16, + new("INTEL SSDSA2CW120G3", null, 16, @"03 000000000000 100 100 0 04 000000000000 100 100 0 05 000000000000 100 100 0 @@ -149,7 +149,7 @@ namespace LibreHardwareMonitor.Hardware.Storage E9 000000000000 100 100 0 F1 FF4300000000 100 100 0 F2 264F00000000 100 100 0"), - new Drive("CORSAIR CMFSSD-128GBG2D", "VBM19C1Q", 16, + new("CORSAIR CMFSSD-128GBG2D", "VBM19C1Q", 16, @"09 100900000000 99 99 0 0C 560200000000 99 99 0 AF 000000000000 100 100 10 @@ -167,7 +167,7 @@ namespace LibreHardwareMonitor.Hardware.Storage C7 810100000000 253 253 0 E8 240000000000 60 60 10 E9 630594120000 92 92 0"), - new Drive("Maxtor 6L300R0", null, 10, + new("Maxtor 6L300R0", null, 10, @"3 9E5500000000 183 193 4 0A0D00000000 252 252 5 010000000000 253 253 @@ -202,7 +202,7 @@ namespace LibreHardwareMonitor.Hardware.Storage 59 FC3203030100 205 0 1 000000000000 0 0 144 000000000000 0 34 "), - new Drive("M4-CT256M4SSD2", "0309", 16, + new("M4-CT256M4SSD2", "0309", 16, @"01 000000000000 100 100 50 05 000000000000 100 100 10 09 AB0100000000 100 100 1 @@ -226,7 +226,7 @@ namespace LibreHardwareMonitor.Hardware.Storage C7 000000000000 100 100 1 CA 000000000000 100 100 1 CE 000000000000 100 100 1 "), - new Drive("C300-CTFDDAC256MAG", "0007", 16, + new("C300-CTFDDAC256MAG", "0007", 16, @"01 000000000000 100 100 0 05 000000000000 100 100 0 09 4C0A00000000 100 100 0 @@ -249,7 +249,7 @@ namespace LibreHardwareMonitor.Hardware.Storage C7 000000000000 100 100 0 CA 000000000000 100 100 0 CE 000000000000 100 100 0"), - new Drive("M4-CT064M4SSD2", "0009", 16, + new("M4-CT064M4SSD2", "0009", 16, @"01 000000000000 100 100 50 05 000000000000 100 100 10 09 260000000000 100 100 1 @@ -273,7 +273,7 @@ namespace LibreHardwareMonitor.Hardware.Storage C7 000000000000 100 100 1 CA 000000000000 100 100 1 CE 000000000000 100 100 1"), - new Drive("M4-CT128M4SSD2", "000F", 16, + new("M4-CT128M4SSD2", "000F", 16, @"01 000000000000 100 100 50 05 000000000000 100 100 10 09 CA1400000000 100 100 1 @@ -297,7 +297,7 @@ namespace LibreHardwareMonitor.Hardware.Storage C7 000000000000 100 100 1 CA 010000000000 99 99 1 CE 000000000000 100 100 1 "), - new Drive("Samsung SSD 840 PRO Series", "DXM05B0Q", 16, + new("Samsung SSD 840 PRO Series", "DXM05B0Q", 16, @"05 000000000000 100 100 10 09 541200000000 99 99 0 0C 820500000000 98 98 0 diff --git a/LibreHardwareMonitorLib/Hardware/Storage/GenericHardDisk.cs b/LibreHardwareMonitorLib/Hardware/Storage/GenericHardDisk.cs index e18e017..0a73e34 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/GenericHardDisk.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/GenericHardDisk.cs @@ -72,13 +72,13 @@ namespace LibreHardwareMonitor.Hardware.Storage new SmartAttribute(0xF2, SmartNames.TotalLbasRead), new SmartAttribute(0xFA, SmartNames.ReadErrorRetryRate), new SmartAttribute(0xFE, SmartNames.FreeFallProtection), - new SmartAttribute(0xC2, SmartNames.Temperature, (r, v, p) => r[0] + (p?[0].Value ?? 0), + new SmartAttribute(0xC2, SmartNames.Temperature, (r, _, p) => r[0] + (p?[0].Value ?? 0), SensorType.Temperature, 0, SmartNames.Temperature, false, new[] { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\n" + "Temperature = Value + Offset.", 0) }), - new SmartAttribute(0xE7, SmartNames.Temperature, (r, v, p) => r[0] + (p?[0].Value ?? 0), + new SmartAttribute(0xE7, SmartNames.Temperature, (r, _, p) => r[0] + (p?[0].Value ?? 0), SensorType.Temperature, 0, SmartNames.Temperature, false, new[] { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\n" + "Temperature = Value + Offset.", 0) }), - new SmartAttribute(0xBE, SmartNames.TemperatureDifferenceFrom100, (r, v, p) => r[0] + (p?[0].Value ?? 0), + new SmartAttribute(0xBE, SmartNames.TemperatureDifferenceFrom100, (r, _, p) => r[0] + (p?[0].Value ?? 0), SensorType.Temperature, 0, "Temperature", false, new[] { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\n" + "Temperature = Value + Offset.", 0) }) }; diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs index d6d258e..2ce43c5 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntel.cs @@ -22,7 +22,7 @@ namespace LibreHardwareMonitor.Hardware.Storage public bool IdentifyController(SafeHandle hDevice, out Kernel32.NVME_IDENTIFY_CONTROLLER_DATA data) { data = Kernel32.CreateStruct(); - if (hDevice == null || hDevice.IsInvalid) + if (hDevice?.IsInvalid != false) return false; bool result = false; @@ -74,7 +74,7 @@ namespace LibreHardwareMonitor.Hardware.Storage public bool HealthInfoLog(SafeHandle hDevice, out Kernel32.NVME_HEALTH_INFO_LOG data) { data = Kernel32.CreateStruct(); - if (hDevice == null || hDevice.IsInvalid) + if (hDevice?.IsInvalid != false) return false; bool result = false; @@ -118,10 +118,9 @@ namespace LibreHardwareMonitor.Hardware.Storage public static SafeHandle IdentifyDevice(StorageInfo storageInfo) { SafeHandle handle = Kernel32.OpenDevice(storageInfo.Scsi); - if (handle == null || handle.IsInvalid) + if (handle?.IsInvalid != false) return null; - Kernel32.NVME_PASS_THROUGH_IOCTL passThrough = Kernel32.CreateStruct(); passThrough.srb.HeaderLenght = (uint)Marshal.SizeOf(); passThrough.srb.Signature = Encoding.ASCII.GetBytes(Kernel32.IntelNVMeMiniPortSignature1); diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs index ff845e0..229387d 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeIntelRst.cs @@ -22,7 +22,7 @@ namespace LibreHardwareMonitor.Hardware.Storage public bool IdentifyController(SafeHandle hDevice, out Kernel32.NVME_IDENTIFY_CONTROLLER_DATA data) { data = Kernel32.CreateStruct(); - if (hDevice == null || hDevice.IsInvalid) + if (hDevice?.IsInvalid != false) return false; bool result = false; @@ -74,11 +74,10 @@ namespace LibreHardwareMonitor.Hardware.Storage public bool HealthInfoLog(SafeHandle hDevice, out Kernel32.NVME_HEALTH_INFO_LOG data) { data = Kernel32.CreateStruct(); - if (hDevice == null || hDevice.IsInvalid) + if (hDevice?.IsInvalid != false) return false; bool result = false; - IntPtr buffer; Kernel32.NVME_PASS_THROUGH_IOCTL passThrough = Kernel32.CreateStruct(); passThrough.srb.HeaderLenght = (uint)Marshal.SizeOf(); @@ -97,7 +96,7 @@ namespace LibreHardwareMonitor.Hardware.Storage passThrough.ReturnBufferLen = (uint)Marshal.SizeOf(); int length = Marshal.SizeOf(); - buffer = Marshal.AllocHGlobal(length); + IntPtr buffer = Marshal.AllocHGlobal(length); Marshal.StructureToPtr(passThrough, buffer, false); bool validTransfer = Kernel32.DeviceIoControl(hDevice, Kernel32.IOCTL.IOCTL_SCSI_MINIPORT, buffer, length, buffer, length, out _, IntPtr.Zero); @@ -120,10 +119,9 @@ namespace LibreHardwareMonitor.Hardware.Storage public static SafeHandle IdentifyDevice(StorageInfo storageInfo) { SafeHandle handle = Kernel32.OpenDevice(storageInfo.Scsi); - if (handle == null || handle.IsInvalid) + if (handle?.IsInvalid != false) return null; - Kernel32.NVME_PASS_THROUGH_IOCTL passThrough = Kernel32.CreateStruct(); passThrough.srb.HeaderLenght = (uint)Marshal.SizeOf(); passThrough.srb.Signature = Encoding.ASCII.GetBytes(Kernel32.IntelNVMeMiniPortSignature2); diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeSamsung.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeSamsung.cs index 534908d..42afa9d 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeSamsung.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeSamsung.cs @@ -100,7 +100,7 @@ namespace LibreHardwareMonitor.Hardware.Storage public bool HealthInfoLog(SafeHandle hDevice, out Kernel32.NVME_HEALTH_INFO_LOG data) { data = Kernel32.CreateStruct(); - if (hDevice == null || hDevice.IsInvalid) + if (hDevice?.IsInvalid != false) return false; bool result = false; @@ -180,10 +180,9 @@ namespace LibreHardwareMonitor.Hardware.Storage public static SafeHandle IdentifyDevice(StorageInfo storageInfo) { SafeHandle handle = Kernel32.OpenDevice(storageInfo.DeviceId); - if (handle == null || handle.IsInvalid) + if (handle?.IsInvalid != false) return null; - Kernel32.SCSI_PASS_THROUGH_WITH_BUFFERS buffers = Kernel32.CreateStruct(); buffers.Spt.Length = (ushort)Marshal.SizeOf(); diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeSmart.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeSmart.cs index 4b6812b..84f75f1 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeSmart.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeSmart.cs @@ -112,7 +112,7 @@ namespace LibreHardwareMonitor.Hardware.Storage public Storage.NVMeInfo GetInfo() { - if (_handle == null || _handle.IsClosed) + if (_handle?.IsClosed != false) return null; bool valid = false; @@ -128,7 +128,7 @@ namespace LibreHardwareMonitor.Hardware.Storage public Storage.NVMeHealthInfo GetHealthInfo() { - if (_handle == null || _handle.IsClosed) + if (_handle?.IsClosed != false) return null; bool valid = false; diff --git a/LibreHardwareMonitorLib/Hardware/Storage/NVMeWindows.cs b/LibreHardwareMonitorLib/Hardware/Storage/NVMeWindows.cs index e787db0..313beea 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/NVMeWindows.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/NVMeWindows.cs @@ -21,7 +21,7 @@ namespace LibreHardwareMonitor.Hardware.Storage public bool IdentifyController(SafeHandle hDevice, out Kernel32.NVME_IDENTIFY_CONTROLLER_DATA data) { data = Kernel32.CreateStruct(); - if (hDevice == null || hDevice.IsInvalid) + if (hDevice?.IsInvalid != false) return false; bool result = false; @@ -58,7 +58,7 @@ namespace LibreHardwareMonitor.Hardware.Storage public bool HealthInfoLog(SafeHandle hDevice, out Kernel32.NVME_HEALTH_INFO_LOG data) { data = Kernel32.CreateStruct(); - if (hDevice == null || hDevice.IsInvalid) + if (hDevice?.IsInvalid != false) return false; bool result = false; @@ -95,10 +95,9 @@ namespace LibreHardwareMonitor.Hardware.Storage public static SafeHandle IdentifyDevice(StorageInfo storageInfo) { SafeHandle handle = Kernel32.OpenDevice(storageInfo.DeviceId); - if (handle == null || handle.IsInvalid) + if (handle?.IsInvalid != false) return null; - Kernel32.STORAGE_QUERY_BUFFER nptwb = Kernel32.CreateStruct(); nptwb.ProtocolSpecific.ProtocolType = Kernel32.STORAGE_PROTOCOL_TYPE.ProtocolTypeNvme; nptwb.ProtocolSpecific.DataType = (uint)Kernel32.STORAGE_PROTOCOL_NVME_DATA_TYPE.NVMeDataTypeIdentify; diff --git a/LibreHardwareMonitorLib/Hardware/Storage/SsdIndilinx.cs b/LibreHardwareMonitorLib/Hardware/Storage/SsdIndilinx.cs index 934b8bc..49ff3a1 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/SsdIndilinx.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/SsdIndilinx.cs @@ -13,28 +13,28 @@ namespace LibreHardwareMonitor.Hardware.Storage { private static readonly IReadOnlyList _smartAttributes = new List { - new SmartAttribute(0x01, SmartNames.ReadErrorRate), - new SmartAttribute(0x09, SmartNames.PowerOnHours), - new SmartAttribute(0x0C, SmartNames.PowerCycleCount), - new SmartAttribute(0xB8, SmartNames.InitialBadBlockCount), - new SmartAttribute(0xC3, SmartNames.ProgramFailure), - new SmartAttribute(0xC4, SmartNames.EraseFailure), - new SmartAttribute(0xC5, SmartNames.ReadFailure), - new SmartAttribute(0xC6, SmartNames.SectorsRead), - new SmartAttribute(0xC7, SmartNames.SectorsWritten), - new SmartAttribute(0xC8, SmartNames.ReadCommands), - new SmartAttribute(0xC9, SmartNames.WriteCommands), - new SmartAttribute(0xCA, SmartNames.BitErrors), - new SmartAttribute(0xCB, SmartNames.CorrectedErrors), - new SmartAttribute(0xCC, SmartNames.BadBlockFullFlag), - new SmartAttribute(0xCD, SmartNames.MaxCellCycles), - new SmartAttribute(0xCE, SmartNames.MinErase), - new SmartAttribute(0xCF, SmartNames.MaxErase), - new SmartAttribute(0xD0, SmartNames.AverageEraseCount), - new SmartAttribute(0xD1, SmartNames.RemainingLife, null, SensorType.Level, 0, SmartNames.RemainingLife), - new SmartAttribute(0xD2, SmartNames.UnknownUnique), - new SmartAttribute(0xD3, SmartNames.SataErrorCountCrc), - new SmartAttribute(0xD4, SmartNames.SataErrorCountHandshake) + new(0x01, SmartNames.ReadErrorRate), + new(0x09, SmartNames.PowerOnHours), + new(0x0C, SmartNames.PowerCycleCount), + new(0xB8, SmartNames.InitialBadBlockCount), + new(0xC3, SmartNames.ProgramFailure), + new(0xC4, SmartNames.EraseFailure), + new(0xC5, SmartNames.ReadFailure), + new(0xC6, SmartNames.SectorsRead), + new(0xC7, SmartNames.SectorsWritten), + new(0xC8, SmartNames.ReadCommands), + new(0xC9, SmartNames.WriteCommands), + new(0xCA, SmartNames.BitErrors), + new(0xCB, SmartNames.CorrectedErrors), + new(0xCC, SmartNames.BadBlockFullFlag), + new(0xCD, SmartNames.MaxCellCycles), + new(0xCE, SmartNames.MinErase), + new(0xCF, SmartNames.MaxErase), + new(0xD0, SmartNames.AverageEraseCount), + new(0xD1, SmartNames.RemainingLife, null, SensorType.Level, 0, SmartNames.RemainingLife), + new(0xD2, SmartNames.UnknownUnique), + new(0xD3, SmartNames.SataErrorCountCrc), + new(0xD4, SmartNames.SataErrorCountHandshake) }; public SsdIndilinx(StorageInfo storageInfo, ISmart smart, string name, string firmwareRevision, int index, ISettings settings) diff --git a/LibreHardwareMonitorLib/Hardware/Storage/SsdIntel.cs b/LibreHardwareMonitorLib/Hardware/Storage/SsdIntel.cs index 36d5917..20d52da 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/SsdIntel.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/SsdIntel.cs @@ -13,34 +13,34 @@ namespace LibreHardwareMonitor.Hardware.Storage { private static readonly IReadOnlyList _smartAttributes = new List { - new SmartAttribute(0x01, SmartNames.ReadErrorRate), - new SmartAttribute(0x03, SmartNames.SpinUpTime), - new SmartAttribute(0x04, SmartNames.StartStopCount, RawToInt), - new SmartAttribute(0x05, SmartNames.ReallocatedSectorsCount), - new SmartAttribute(0x09, SmartNames.PowerOnHours, RawToInt), - new SmartAttribute(0x0C, SmartNames.PowerCycleCount, RawToInt), - new SmartAttribute(0xAA, SmartNames.AvailableReservedSpace), - new SmartAttribute(0xAB, SmartNames.ProgramFailCount), - new SmartAttribute(0xAC, SmartNames.EraseFailCount), - new SmartAttribute(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt), - new SmartAttribute(0xB7, SmartNames.SataDownshiftErrorCount, RawToInt), - new SmartAttribute(0xB8, SmartNames.EndToEndError), - new SmartAttribute(0xBB, SmartNames.UncorrectableErrorCount, RawToInt), - new SmartAttribute(0xBE, - SmartNames.Temperature, - (r, v, p) => r[0] + (p?[0].Value ?? 0), - SensorType.Temperature, - 0, - SmartNames.AirflowTemperature, - false, - new[] { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\nTemperature = Value + Offset.", 0) }), - new SmartAttribute(0xC0, SmartNames.UnsafeShutdownCount), - new SmartAttribute(0xC7, SmartNames.CrcErrorCount, RawToInt), - new SmartAttribute(0xE1, SmartNames.HostWrites, (r, v, p) => RawToInt(r, v, p) / 0x20, SensorType.Data, 0, SmartNames.HostWrites), - new SmartAttribute(0xE8, SmartNames.RemainingLife, null, SensorType.Level, 0, SmartNames.RemainingLife), - new SmartAttribute(0xE9, SmartNames.MediaWearOutIndicator), - new SmartAttribute(0xF1, SmartNames.HostWrites, (r, v, p) => RawToInt(r, v, p) / 0x20, SensorType.Data, 0, SmartNames.HostWrites), - new SmartAttribute(0xF2, SmartNames.HostReads, (r, v, p) => RawToInt(r, v, p) / 0x20, SensorType.Data, 1, SmartNames.HostReads) + new(0x01, SmartNames.ReadErrorRate), + new(0x03, SmartNames.SpinUpTime), + new(0x04, SmartNames.StartStopCount, RawToInt), + new(0x05, SmartNames.ReallocatedSectorsCount), + new(0x09, SmartNames.PowerOnHours, RawToInt), + new(0x0C, SmartNames.PowerCycleCount, RawToInt), + new(0xAA, SmartNames.AvailableReservedSpace), + new(0xAB, SmartNames.ProgramFailCount), + new(0xAC, SmartNames.EraseFailCount), + new(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt), + new(0xB7, SmartNames.SataDownshiftErrorCount, RawToInt), + new(0xB8, SmartNames.EndToEndError), + new(0xBB, SmartNames.UncorrectableErrorCount, RawToInt), + new(0xBE, + SmartNames.Temperature, + (r, _, p) => r[0] + (p?[0].Value ?? 0), + SensorType.Temperature, + 0, + SmartNames.AirflowTemperature, + false, + new[] { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\nTemperature = Value + Offset.", 0) }), + new(0xC0, SmartNames.UnsafeShutdownCount), + new(0xC7, SmartNames.CrcErrorCount, RawToInt), + new(0xE1, SmartNames.HostWrites, (r, v, p) => RawToInt(r, v, p) / 0x20, SensorType.Data, 0, SmartNames.HostWrites), + new(0xE8, SmartNames.RemainingLife, null, SensorType.Level, 0, SmartNames.RemainingLife), + new(0xE9, SmartNames.MediaWearOutIndicator), + new(0xF1, SmartNames.HostWrites, (r, v, p) => RawToInt(r, v, p) / 0x20, SensorType.Data, 0, SmartNames.HostWrites), + new(0xF2, SmartNames.HostReads, (r, v, p) => RawToInt(r, v, p) / 0x20, SensorType.Data, 1, SmartNames.HostReads) }; public SsdIntel(StorageInfo storageInfo, ISmart smart, string name, string firmwareRevision, int index, ISettings settings) diff --git a/LibreHardwareMonitorLib/Hardware/Storage/SsdMicron.cs b/LibreHardwareMonitorLib/Hardware/Storage/SsdMicron.cs index 5b226b6..c8c68e7 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/SsdMicron.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/SsdMicron.cs @@ -14,44 +14,44 @@ namespace LibreHardwareMonitor.Hardware.Storage { private static readonly IReadOnlyList _smartAttributes = new List { - new SmartAttribute(0x01, SmartNames.ReadErrorRate, RawToInt), - new SmartAttribute(0x05, SmartNames.ReallocatedNANDBlockCount, RawToInt), - new SmartAttribute(0x09, SmartNames.PowerOnHours, RawToInt), - new SmartAttribute(0x0C, SmartNames.PowerCycleCount, RawToInt), - new SmartAttribute(0xAA, SmartNames.NewFailingBlockCount, RawToInt), - new SmartAttribute(0xAB, SmartNames.ProgramFailCount, RawToInt), - new SmartAttribute(0xAC, SmartNames.EraseFailCount, RawToInt), - new SmartAttribute(0xAD, SmartNames.WearLevelingCount, RawToInt), - new SmartAttribute(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt), - new SmartAttribute(0xB4, SmartNames.UnusedReserveNANDBlocks, RawToInt), - new SmartAttribute(0xB5, SmartNames.Non4KAlignedAccess, (raw, value, p) => 6e4f * ((raw[5] << 8) | raw[4])), - new SmartAttribute(0xB7, SmartNames.SataDownshiftErrorCount, RawToInt), - new SmartAttribute(0xB8, SmartNames.ErrorCorrectionCount, RawToInt), - new SmartAttribute(0xBB, SmartNames.ReportedUncorrectableErrors, RawToInt), - new SmartAttribute(0xBC, SmartNames.CommandTimeout, RawToInt), - new SmartAttribute(0xBD, SmartNames.FactoryBadBlockCount, RawToInt), - new SmartAttribute(0xC2, SmartNames.Temperature, RawToInt), - new SmartAttribute(0xC4, SmartNames.ReallocationEventCount, RawToInt), - new SmartAttribute(0xC5, SmartNames.CurrentPendingSectorCount), - new SmartAttribute(0xC6, SmartNames.OffLineUncorrectableErrorCount, RawToInt), - new SmartAttribute(0xC7, SmartNames.UltraDmaCrcErrorCount, RawToInt), - new SmartAttribute(0xCA, SmartNames.RemainingLife, (raw, value, p) => 100 - RawToInt(raw, value, p), SensorType.Level, 0, SmartNames.RemainingLife), - new SmartAttribute(0xCE, SmartNames.WriteErrorRate, (raw, value, p) => 6e4f * ((raw[1] << 8) | raw[0])), - new SmartAttribute(0xD2, SmartNames.SuccessfulRAINRecoveryCount, RawToInt), - new SmartAttribute(0xF6, - SmartNames.TotalLbasWritten, - (r, v, p) => (((long)r[5] << 40) | - ((long)r[4] << 32) | - ((long)r[3] << 24) | - ((long)r[2] << 16) | - ((long)r[1] << 8) | - r[0]) * - (512.0f / 1024 / 1024 / 1024), - SensorType.Data, - 0, - "Total Bytes Written"), - new SmartAttribute(0xF7, SmartNames.HostProgramNANDPagesCount, RawToInt), - new SmartAttribute(0xF8, SmartNames.FTLProgramNANDPagesCount, RawToInt) + new(0x01, SmartNames.ReadErrorRate, RawToInt), + new(0x05, SmartNames.ReallocatedNANDBlockCount, RawToInt), + new(0x09, SmartNames.PowerOnHours, RawToInt), + new(0x0C, SmartNames.PowerCycleCount, RawToInt), + new(0xAA, SmartNames.NewFailingBlockCount, RawToInt), + new(0xAB, SmartNames.ProgramFailCount, RawToInt), + new(0xAC, SmartNames.EraseFailCount, RawToInt), + new(0xAD, SmartNames.WearLevelingCount, RawToInt), + new(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt), + new(0xB4, SmartNames.UnusedReserveNANDBlocks, RawToInt), + new(0xB5, SmartNames.Non4KAlignedAccess, (raw, _, _) => 6e4f * ((raw[5] << 8) | raw[4])), + new(0xB7, SmartNames.SataDownshiftErrorCount, RawToInt), + new(0xB8, SmartNames.ErrorCorrectionCount, RawToInt), + new(0xBB, SmartNames.ReportedUncorrectableErrors, RawToInt), + new(0xBC, SmartNames.CommandTimeout, RawToInt), + new(0xBD, SmartNames.FactoryBadBlockCount, RawToInt), + new(0xC2, SmartNames.Temperature, RawToInt), + new(0xC4, SmartNames.ReallocationEventCount, RawToInt), + new(0xC5, SmartNames.CurrentPendingSectorCount), + new(0xC6, SmartNames.OffLineUncorrectableErrorCount, RawToInt), + new(0xC7, SmartNames.UltraDmaCrcErrorCount, RawToInt), + new(0xCA, SmartNames.RemainingLife, (raw, value, p) => 100 - RawToInt(raw, value, p), SensorType.Level, 0, SmartNames.RemainingLife), + new(0xCE, SmartNames.WriteErrorRate, (raw, _, _) => 6e4f * ((raw[1] << 8) | raw[0])), + new(0xD2, SmartNames.SuccessfulRAINRecoveryCount, RawToInt), + new(0xF6, + SmartNames.TotalLbasWritten, + (r, _, _) => (((long)r[5] << 40) | + ((long)r[4] << 32) | + ((long)r[3] << 24) | + ((long)r[2] << 16) | + ((long)r[1] << 8) | + r[0]) * + (512.0f / 1024 / 1024 / 1024), + SensorType.Data, + 0, + "Total Bytes Written"), + new(0xF7, SmartNames.HostProgramNANDPagesCount, RawToInt), + new(0xF8, SmartNames.FTLProgramNANDPagesCount, RawToInt) }; private readonly Sensor _temperature; diff --git a/LibreHardwareMonitorLib/Hardware/Storage/SsdPlextor.cs b/LibreHardwareMonitorLib/Hardware/Storage/SsdPlextor.cs index eb02f50..438ca47 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/SsdPlextor.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/SsdPlextor.cs @@ -13,10 +13,10 @@ namespace LibreHardwareMonitor.Hardware.Storage { private static readonly IReadOnlyList _smartAttributes = new List { - new SmartAttribute(0x09, SmartNames.PowerOnHours, RawToInt), - new SmartAttribute(0x0C, SmartNames.PowerCycleCount, RawToInt), - new SmartAttribute(0xF1, SmartNames.HostWrites, RawToGb, SensorType.Data, 0, SmartNames.HostWrites), - new SmartAttribute(0xF2, SmartNames.HostReads, RawToGb, SensorType.Data, 1, SmartNames.HostReads) + new(0x09, SmartNames.PowerOnHours, RawToInt), + new(0x0C, SmartNames.PowerCycleCount, RawToInt), + new(0xF1, SmartNames.HostWrites, RawToGb, SensorType.Data, 0, SmartNames.HostWrites), + new(0xF2, SmartNames.HostReads, RawToGb, SensorType.Data, 1, SmartNames.HostReads) }; public SsdPlextor(StorageInfo storageInfo, ISmart smart, string name, string firmwareRevision, int index, ISettings settings) diff --git a/LibreHardwareMonitorLib/Hardware/Storage/SsdSamsung.cs b/LibreHardwareMonitorLib/Hardware/Storage/SsdSamsung.cs index c67e617..cb62d6a 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/SsdSamsung.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/SsdSamsung.cs @@ -13,42 +13,42 @@ namespace LibreHardwareMonitor.Hardware.Storage { private static readonly IReadOnlyList _smartAttributes = new List { - new SmartAttribute(0x05, SmartNames.ReallocatedSectorsCount), - new SmartAttribute(0x09, SmartNames.PowerOnHours, RawToInt), - new SmartAttribute(0x0C, SmartNames.PowerCycleCount, RawToInt), - new SmartAttribute(0xAF, SmartNames.ProgramFailCountChip, RawToInt), - new SmartAttribute(0xB0, SmartNames.EraseFailCountChip, RawToInt), - new SmartAttribute(0xB1, SmartNames.WearLevelingCount, RawToInt), - new SmartAttribute(0xB2, SmartNames.UsedReservedBlockCountChip, RawToInt), - new SmartAttribute(0xB3, SmartNames.UsedReservedBlockCountTotal, RawToInt), + new(0x05, SmartNames.ReallocatedSectorsCount), + new(0x09, SmartNames.PowerOnHours, RawToInt), + new(0x0C, SmartNames.PowerCycleCount, RawToInt), + new(0xAF, SmartNames.ProgramFailCountChip, RawToInt), + new(0xB0, SmartNames.EraseFailCountChip, RawToInt), + new(0xB1, SmartNames.WearLevelingCount, RawToInt), + new(0xB2, SmartNames.UsedReservedBlockCountChip, RawToInt), + new(0xB3, SmartNames.UsedReservedBlockCountTotal, RawToInt), // Unused Reserved Block Count (Total) - new SmartAttribute(0xB4, SmartNames.RemainingLife, null, SensorType.Level, 0, SmartNames.RemainingLife), - new SmartAttribute(0xB5, SmartNames.ProgramFailCountTotal, RawToInt), - new SmartAttribute(0xB6, SmartNames.EraseFailCountTotal, RawToInt), - new SmartAttribute(0xB7, SmartNames.RuntimeBadBlockTotal, RawToInt), - new SmartAttribute(0xBB, SmartNames.UncorrectableErrorCount, RawToInt), - new SmartAttribute(0xBE, - SmartNames.Temperature, - (r, v, p) => r[0] + (p?[0].Value ?? 0), - SensorType.Temperature, - 0, - SmartNames.Temperature, - false, - new[] { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\nTemperature = Value + Offset.", 0) }), - new SmartAttribute(0xC2, SmartNames.AirflowTemperature), - new SmartAttribute(0xC3, SmartNames.EccRate), - new SmartAttribute(0xC6, SmartNames.OffLineUncorrectableErrorCount, RawToInt), - new SmartAttribute(0xC7, SmartNames.CrcErrorCount, RawToInt), - new SmartAttribute(0xC9, SmartNames.SupercapStatus), - new SmartAttribute(0xCA, SmartNames.ExceptionModeStatus), - new SmartAttribute(0xEB, SmartNames.PowerRecoveryCount), - new SmartAttribute(0xF1, - SmartNames.TotalLbasWritten, - (r, v, p) => (((long)r[5] << 40) | ((long)r[4] << 32) | ((long)r[3] << 24) | ((long)r[2] << 16) | ((long)r[1] << 8) | r[0]) * (512.0f / 1024 / 1024 / 1024), - SensorType.Data, - 0, - "Total Bytes Written") + new(0xB4, SmartNames.RemainingLife, null, SensorType.Level, 0, SmartNames.RemainingLife), + new(0xB5, SmartNames.ProgramFailCountTotal, RawToInt), + new(0xB6, SmartNames.EraseFailCountTotal, RawToInt), + new(0xB7, SmartNames.RuntimeBadBlockTotal, RawToInt), + new(0xBB, SmartNames.UncorrectableErrorCount, RawToInt), + new(0xBE, + SmartNames.Temperature, + (r, _, p) => r[0] + (p?[0].Value ?? 0), + SensorType.Temperature, + 0, + SmartNames.Temperature, + false, + new[] { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\nTemperature = Value + Offset.", 0) }), + new(0xC2, SmartNames.AirflowTemperature), + new(0xC3, SmartNames.EccRate), + new(0xC6, SmartNames.OffLineUncorrectableErrorCount, RawToInt), + new(0xC7, SmartNames.CrcErrorCount, RawToInt), + new(0xC9, SmartNames.SupercapStatus), + new(0xCA, SmartNames.ExceptionModeStatus), + new(0xEB, SmartNames.PowerRecoveryCount), + new(0xF1, + SmartNames.TotalLbasWritten, + (r, _, _) => (((long)r[5] << 40) | ((long)r[4] << 32) | ((long)r[3] << 24) | ((long)r[2] << 16) | ((long)r[1] << 8) | r[0]) * (512.0f / 1024 / 1024 / 1024), + SensorType.Data, + 0, + "Total Bytes Written") }; public SsdSamsung(StorageInfo storageInfo, ISmart smart, string name, string firmwareRevision, int index, ISettings settings) diff --git a/LibreHardwareMonitorLib/Hardware/Storage/SsdSandforce.cs b/LibreHardwareMonitorLib/Hardware/Storage/SsdSandforce.cs index be54754..5122fda 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/SsdSandforce.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/SsdSandforce.cs @@ -14,32 +14,32 @@ namespace LibreHardwareMonitor.Hardware.Storage { private static readonly IReadOnlyList _smartAttributes = new List { - new SmartAttribute(0x01, SmartNames.RawReadErrorRate), - new SmartAttribute(0x05, SmartNames.RetiredBlockCount, RawToInt), - new SmartAttribute(0x09, SmartNames.PowerOnHours, RawToInt), - new SmartAttribute(0x0C, SmartNames.PowerCycleCount, RawToInt), - new SmartAttribute(0xAB, SmartNames.ProgramFailCount, RawToInt), - new SmartAttribute(0xAC, SmartNames.EraseFailCount, RawToInt), - new SmartAttribute(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt), - new SmartAttribute(0xB1, SmartNames.WearRangeDelta, RawToInt), - new SmartAttribute(0xB5, SmartNames.AlternativeProgramFailCount, RawToInt), - new SmartAttribute(0xB6, SmartNames.AlternativeEraseFailCount, RawToInt), - new SmartAttribute(0xBB, SmartNames.UncorrectableErrorCount, RawToInt), - new SmartAttribute(0xC2, - SmartNames.Temperature, - (raw, value, p) => value + (p?[0].Value ?? 0), - SensorType.Temperature, - 0, - SmartNames.Temperature, - true, - new[] { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\nTemperature = Value + Offset.", 0) }), - new SmartAttribute(0xC3, SmartNames.UnrecoverableEcc), - new SmartAttribute(0xC4, SmartNames.ReallocationEventCount, RawToInt), - new SmartAttribute(0xE7, SmartNames.RemainingLife, null, SensorType.Level, 0, SmartNames.RemainingLife), - new SmartAttribute(0xE9, SmartNames.ControllerWritesToNand, RawToInt, SensorType.Data, 0, SmartNames.ControllerWritesToNand), - new SmartAttribute(0xEA, SmartNames.HostWritesToController, RawToInt, SensorType.Data, 1, SmartNames.HostWritesToController), - new SmartAttribute(0xF1, SmartNames.HostWrites, RawToInt, SensorType.Data, 1, SmartNames.HostWrites), - new SmartAttribute(0xF2, SmartNames.HostReads, RawToInt, SensorType.Data, 2, SmartNames.HostReads) + new(0x01, SmartNames.RawReadErrorRate), + new(0x05, SmartNames.RetiredBlockCount, RawToInt), + new(0x09, SmartNames.PowerOnHours, RawToInt), + new(0x0C, SmartNames.PowerCycleCount, RawToInt), + new(0xAB, SmartNames.ProgramFailCount, RawToInt), + new(0xAC, SmartNames.EraseFailCount, RawToInt), + new(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt), + new(0xB1, SmartNames.WearRangeDelta, RawToInt), + new(0xB5, SmartNames.AlternativeProgramFailCount, RawToInt), + new(0xB6, SmartNames.AlternativeEraseFailCount, RawToInt), + new(0xBB, SmartNames.UncorrectableErrorCount, RawToInt), + new(0xC2, + SmartNames.Temperature, + (_, value, p) => value + (p?[0].Value ?? 0), + SensorType.Temperature, + 0, + SmartNames.Temperature, + true, + new[] { new ParameterDescription("Offset [°C]", "Temperature offset of the thermal sensor.\nTemperature = Value + Offset.", 0) }), + new(0xC3, SmartNames.UnrecoverableEcc), + new(0xC4, SmartNames.ReallocationEventCount, RawToInt), + new(0xE7, SmartNames.RemainingLife, null, SensorType.Level, 0, SmartNames.RemainingLife), + new(0xE9, SmartNames.ControllerWritesToNand, RawToInt, SensorType.Data, 0, SmartNames.ControllerWritesToNand), + new(0xEA, SmartNames.HostWritesToController, RawToInt, SensorType.Data, 1, SmartNames.HostWritesToController), + new(0xF1, SmartNames.HostWrites, RawToInt, SensorType.Data, 1, SmartNames.HostWrites), + new(0xF2, SmartNames.HostReads, RawToInt, SensorType.Data, 2, SmartNames.HostReads) }; private readonly Sensor _writeAmplification; diff --git a/LibreHardwareMonitorLib/Hardware/Storage/WindowsSmart.cs b/LibreHardwareMonitorLib/Hardware/Storage/WindowsSmart.cs index 504e588..e4d6ba4 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/WindowsSmart.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/WindowsSmart.cs @@ -153,16 +153,14 @@ namespace LibreHardwareMonitor.Hardware.Storage // high and mid registers are unchanged, which means that the drive is healthy return true; } - else if (Kernel32.SMART_LBA_HI_EXCEEDED == result.irDriveRegs.bCylHighReg && Kernel32.SMART_LBA_MID_EXCEEDED == result.irDriveRegs.bCylLowReg) + + if (Kernel32.SMART_LBA_HI_EXCEEDED == result.irDriveRegs.bCylHighReg && Kernel32.SMART_LBA_MID_EXCEEDED == result.irDriveRegs.bCylLowReg) { // high and mid registers are exceeded, which means that the drive is unhealthy return false; } - else - { - // response is not clear - return null; - } + // response is not clear + return null; } protected void Dispose(bool disposing) diff --git a/LibreHardwareMonitorLib/Hardware/Storage/WindowsStorage.cs b/LibreHardwareMonitorLib/Hardware/Storage/WindowsStorage.cs index bc0b4e4..a6502f6 100644 --- a/LibreHardwareMonitorLib/Hardware/Storage/WindowsStorage.cs +++ b/LibreHardwareMonitorLib/Hardware/Storage/WindowsStorage.cs @@ -15,39 +15,35 @@ namespace LibreHardwareMonitor.Hardware.Storage { public static Storage.StorageInfo GetStorageInfo(string deviceId, uint driveIndex) { - using (SafeHandle handle = Kernel32.OpenDevice(deviceId)) + using SafeHandle handle = Kernel32.OpenDevice(deviceId); + if (handle?.IsInvalid != false) + return null; + + var query = new Kernel32.STORAGE_PROPERTY_QUERY { PropertyId = Kernel32.STORAGE_PROPERTY_ID.StorageDeviceProperty, QueryType = Kernel32.STORAGE_QUERY_TYPE.PropertyStandardQuery }; + + if (!Kernel32.DeviceIoControl(handle, + Kernel32.IOCTL.IOCTL_STORAGE_QUERY_PROPERTY, + ref query, + Marshal.SizeOf(query), + out Kernel32.STORAGE_DEVICE_DESCRIPTOR_HEADER header, + Marshal.SizeOf(), + out _, + IntPtr.Zero)) { - if (handle == null || handle.IsInvalid) + return null; + } + + IntPtr descriptorPtr = Marshal.AllocHGlobal((int)header.Size); + try + { + if (!Kernel32.DeviceIoControl(handle, Kernel32.IOCTL.IOCTL_STORAGE_QUERY_PROPERTY, ref query, Marshal.SizeOf(query), descriptorPtr, header.Size, out _, IntPtr.Zero)) return null; - - var query = new Kernel32.STORAGE_PROPERTY_QUERY { PropertyId = Kernel32.STORAGE_PROPERTY_ID.StorageDeviceProperty, QueryType = Kernel32.STORAGE_QUERY_TYPE.PropertyStandardQuery }; - - if (!Kernel32.DeviceIoControl(handle, - Kernel32.IOCTL.IOCTL_STORAGE_QUERY_PROPERTY, - ref query, - Marshal.SizeOf(query), - out Kernel32.STORAGE_DEVICE_DESCRIPTOR_HEADER header, - Marshal.SizeOf(), - out _, - IntPtr.Zero)) - { - return null; - } - - IntPtr descriptorPtr = Marshal.AllocHGlobal((int)header.Size); - try - { - if (!Kernel32.DeviceIoControl(handle, Kernel32.IOCTL.IOCTL_STORAGE_QUERY_PROPERTY, ref query, Marshal.SizeOf(query), descriptorPtr, header.Size, out _, IntPtr.Zero)) - return null; - - - return new StorageInfo((int)driveIndex, descriptorPtr); - } - finally - { - Marshal.FreeHGlobal(descriptorPtr); - } + return new StorageInfo((int)driveIndex, descriptorPtr); + } + finally + { + Marshal.FreeHGlobal(descriptorPtr); } } @@ -57,22 +53,14 @@ namespace LibreHardwareMonitor.Hardware.Storage try { - using (var s = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskPartition " + "WHERE DiskIndex = " + driveIndex)) + using var s = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskPartition " + "WHERE DiskIndex = " + driveIndex); + foreach (ManagementBaseObject o in s.Get()) { - using (ManagementObjectCollection dpc = s.Get()) + if (o is ManagementObject dp) { - foreach (ManagementBaseObject o in dpc) + foreach (ManagementBaseObject ld in dp.GetRelated("Win32_LogicalDisk")) { - if (o is ManagementObject dp) - { - using (ManagementObjectCollection ldc = dp.GetRelated("Win32_LogicalDisk")) - { - foreach (ManagementBaseObject ld in ldc) - { - list.Add(((string)ld["Name"]).TrimEnd(':')); - } - } - } + list.Add(((string)ld["Name"]).TrimEnd(':')); } } } diff --git a/LibreHardwareMonitorLib/Interop/D3dkmth.cs b/LibreHardwareMonitorLib/Interop/D3dkmth.cs index 117801b..d82818f 100644 --- a/LibreHardwareMonitorLib/Interop/D3dkmth.cs +++ b/LibreHardwareMonitorLib/Interop/D3dkmth.cs @@ -329,8 +329,8 @@ namespace LibreHardwareMonitor.Interop { public WinNt.LARGE_INTEGER RunningTime; // 100ns public uint ContextSwitch; - readonly D3DKMT_QUERYSTATISTICS_PREEMPTION_INFORMATION PreemptionStatistics; - readonly D3DKMT_QUERYSTATISTICS_PACKET_INFORMATION PacketStatistics; + private readonly D3DKMT_QUERYSTATISTICS_PREEMPTION_INFORMATION PreemptionStatistics; + private readonly D3DKMT_QUERYSTATISTICS_PACKET_INFORMATION PacketStatistics; private fixed ulong Reserved[8]; } @@ -557,7 +557,7 @@ namespace LibreHardwareMonitor.Interop KMTQAITYPE_PARAVIRTUALIZATION_RENDER = 68, KMTQAITYPE_SERVICENAME = 69, KMTQAITYPE_WDDM_2_7_CAPS = 70, - KMTQAITYPE_TRACKEDWORKLOAD_SUPPORT = 72, + KMTQAITYPE_TRACKEDWORKLOAD_SUPPORT = 72 } } } diff --git a/LibreHardwareMonitorLib/Interop/NvApi.cs b/LibreHardwareMonitorLib/Interop/NvApi.cs index 6dbd24b..8691a87 100644 --- a/LibreHardwareMonitorLib/Interop/NvApi.cs +++ b/LibreHardwareMonitorLib/Interop/NvApi.cs @@ -586,7 +586,7 @@ namespace LibreHardwareMonitor.Interop CurrentFrequency, BaseClock, BoostClock, - ClockTypeNumber, + ClockTypeNumber } internal enum NvCoolerTarget