diff --git a/Collections/IReadOnlyArray.cs b/Collections/IReadOnlyArray.cs deleted file mode 100644 index 9a998b3..0000000 --- a/Collections/IReadOnlyArray.cs +++ /dev/null @@ -1,23 +0,0 @@ -/* - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - - Copyright (C) 2009-2010 Michael Möller - -*/ - -using System; -using System.Collections.Generic; - -namespace OpenHardwareMonitor.Collections { - - public interface IReadOnlyArray : IEnumerable { - - T this[int index] { get; } - - int Length { get; } - - } -} diff --git a/Collections/ListSet.cs b/Collections/ListSet.cs deleted file mode 100644 index c90df38..0000000 --- a/Collections/ListSet.cs +++ /dev/null @@ -1,58 +0,0 @@ -/* - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - - Copyright (C) 2009-2013 Michael Möller - -*/ - -using System.Collections; -using System.Collections.Generic; - -namespace OpenHardwareMonitor.Collections { - - public class ListSet : IEnumerable { - - private readonly List list = new List(); - - public bool Add(T item) { - if (list.Contains(item)) - return false; - - list.Add(item); - return true; - } - - public bool Remove(T item) { - if (!list.Contains(item)) - return false; - - list.Remove(item); - return true; - } - - public bool Contains(T item) { - return list.Contains(item); - } - - public T[] ToArray() { - return list.ToArray(); - } - - public IEnumerator GetEnumerator() { - return list.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() { - return list.GetEnumerator(); - } - - public int Count { - get { - return list.Count; - } - } - } -} diff --git a/Collections/Pair.cs b/Collections/Pair.cs deleted file mode 100644 index 7c0f775..0000000 --- a/Collections/Pair.cs +++ /dev/null @@ -1,40 +0,0 @@ -/* - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - - Copyright (C) 2011 Michael Möller - -*/ - -using System; -using System.Collections.Generic; - -namespace OpenHardwareMonitor.Collections { - - public struct Pair { - private F first; - private S second; - - public Pair(F first, S second) { - this.first = first; - this.second = second; - } - - public F First { - get { return first; } - set { first = value; } - } - - public S Second { - get { return second; } - set { second = value; } - } - - public override int GetHashCode() { - return (first != null ? first.GetHashCode() : 0) ^ - (second != null ? second.GetHashCode() : 0); - } - } -} diff --git a/Collections/ReadOnlyArray.cs b/Collections/ReadOnlyArray.cs deleted file mode 100644 index 4a25354..0000000 --- a/Collections/ReadOnlyArray.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - - Copyright (C) 2009-2010 Michael Möller - -*/ - -using System.Collections; -using System.Collections.Generic; - -namespace OpenHardwareMonitor.Collections { - - public class ReadOnlyArray : IReadOnlyArray { - - private readonly T[] array; - - public ReadOnlyArray(T[] array) { - this.array = array; - } - - public T this[int index] { - get { return array[index]; } - } - - public int Length { get { return array.Length; } } - - public IEnumerator GetEnumerator() { - return ((IEnumerable)array).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() { - return array.GetEnumerator(); - } - - public static implicit operator ReadOnlyArray(T[] array) { - return new ReadOnlyArray(array); - } - - public T[] ToArray() { - return (T[])array.Clone(); - } - } -} diff --git a/Collections/RingCollection.cs b/Collections/RingCollection.cs deleted file mode 100644 index 0d28343..0000000 --- a/Collections/RingCollection.cs +++ /dev/null @@ -1,208 +0,0 @@ -/* - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. - - Copyright (C) 2011 Michael Möller - -*/ - -using System; -using System.Collections; -using System.Collections.Generic; - -namespace OpenHardwareMonitor.Collections { - public class RingCollection : IEnumerable { - - private T[] array; - - // first item of collection - private int head; - - // index after the last item of the collection - private int tail; - - // number of items in the collection - private int size; - - public RingCollection() : this(0) { } - - public RingCollection(int capacity) { - if (capacity < 0) - throw new ArgumentOutOfRangeException("capacity"); - this.array = new T[capacity]; - this.head = 0; - this.tail = 0; - this.size = 0; - } - - public int Capacity { - get { - return array.Length; - } - set { - T[] newArray = new T[value]; - if (size > 0) { - if (head < tail) { - Array.Copy(array, head, newArray, 0, size); - } else { - Array.Copy(array, head, newArray, 0, array.Length - head); - Array.Copy(array, 0, newArray, array.Length - head, tail); - } - } - this.array = newArray; - this.head = 0; - this.tail = size == value ? 0 : size; - } - } - - public void Clear() { - - // remove potential references - if (head < tail) { - Array.Clear(array, head, size); - } else { - Array.Clear(array, 0, tail); - Array.Clear(array, head, array.Length - head); - } - - this.head = 0; - this.tail = 0; - this.size = 0; - } - - public void Append(T item) { - if (size == array.Length) { - int newCapacity = array.Length * 3 / 2; - if (newCapacity < array.Length + 8) - newCapacity = array.Length + 8; - Capacity = newCapacity; - } - - array[tail] = item; - tail = tail + 1 == array.Length ? 0 : tail + 1; - size++; - } - - public T Remove() { - if (size == 0) - throw new InvalidOperationException(); - - T result = array[head]; - array[head] = default(T); - head = head + 1 == array.Length ? 0 : head + 1; - size--; - - return result; - } - - public int Count { - get { - return size; - } - } - - public T this[int index] { - get { - if (index < 0 || index >= size) - throw new IndexOutOfRangeException(); - int i = head + index; - if (i >= array.Length) - i -= array.Length; - return array[i]; - } - set { - if (index < 0 || index >= size) - throw new IndexOutOfRangeException(); - int i = head + index; - if (i >= array.Length) - i -= array.Length; - array[i] = value; - } - } - - public T First { - get { - if (size == 0) - throw new InvalidOperationException(); - return array[head]; - } - set { - if (size == 0) - throw new InvalidOperationException(); - array[head] = value; - } - } - - public T Last { - get { - if (size == 0) - throw new InvalidOperationException(); - return array[tail == 0 ? array.Length - 1 : tail - 1]; - } - set { - if (size == 0) - throw new InvalidOperationException(); - array[tail == 0 ? array.Length - 1 : tail - 1] = value; - } - } - - IEnumerator IEnumerable.GetEnumerator() { - return new RingCollection.Enumerator(this); - } - - IEnumerator IEnumerable.GetEnumerator() { - return new RingCollection.Enumerator(this); - } - - private struct Enumerator : IEnumerator, IEnumerator { - - private RingCollection collection; - private int index; - - public Enumerator(RingCollection collection) { - this.collection = collection; - this.index = -1; - } - - public void Dispose() { - this.index = -2; - } - - public void Reset() { - this.index = -1; - } - - public T Current { - get { - if (index < 0) - throw new InvalidOperationException(); - return collection[index]; - } - } - - object IEnumerator.Current { - get { - if (index < 0) - throw new InvalidOperationException(); - return collection[index]; - } - } - - public bool MoveNext() { - if (index == -2) - return false; - - index++; - - if (index == collection.size) { - index = -2; - return false; - } - - return true; - } - } - } -} diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 981ea11..cb89969 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -678,7 +678,7 @@ namespace OpenHardwareMonitor.GUI { SensorNode node = info.Node.Tag as SensorNode; if (node != null && node.Sensor != null) { treeContextMenu.MenuItems.Clear(); - if (node.Sensor.Parameters.Length > 0) { + if (node.Sensor.Parameters.Count > 0) { MenuItem item = new MenuItem("Parameters..."); item.Click += delegate(object obj, EventArgs args) { ShowParameterForm(node.Sensor); @@ -854,7 +854,7 @@ namespace OpenHardwareMonitor.GUI { TreeNodeAdvMouseEventArgs e) { SensorNode node = e.Node.Tag as SensorNode; if (node != null && node.Sensor != null && - node.Sensor.Parameters.Length > 0) { + node.Sensor.Parameters.Count > 0) { ShowParameterForm(node.Sensor); } } diff --git a/GUI/ParameterForm.cs b/GUI/ParameterForm.cs index 5a43981..4a3cb8b 100644 --- a/GUI/ParameterForm.cs +++ b/GUI/ParameterForm.cs @@ -15,19 +15,18 @@ using System.ComponentModel; using System.Text; using System.Windows.Forms; using OpenHardwareMonitor.Hardware; -using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.GUI { public partial class ParameterForm : Form { - private IReadOnlyArray parameters; + private IReadOnlyList parameters; private BindingList parameterRows; public ParameterForm() { InitializeComponent(); } - public IReadOnlyArray Parameters { + public IReadOnlyList Parameters { get { return parameters; } @@ -88,7 +87,7 @@ namespace OpenHardwareMonitor.GUI { private void dataGridView_RowEnter(object sender, DataGridViewCellEventArgs e) { - if (e.RowIndex >= 0 && e.RowIndex < parameters.Length) + if (e.RowIndex >= 0 && e.RowIndex < parameters.Count) descriptionLabel.Text = parameters[e.RowIndex].Description; else descriptionLabel.Text = ""; diff --git a/GUI/PlotPanel.cs b/GUI/PlotPanel.cs index 49054be..998724b 100644 --- a/GUI/PlotPanel.cs +++ b/GUI/PlotPanel.cs @@ -18,7 +18,6 @@ using OxyPlot; using OxyPlot.Axes; using OxyPlot.WindowsForms; using OxyPlot.Series; -using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.GUI { public class PlotPanel : UserControl { @@ -212,7 +211,7 @@ namespace OpenHardwareMonitor.GUI { IDictionary colors) { this.model.Series.Clear(); - ListSet types = new ListSet(); + var types = new System.Collections.Generic.HashSet(); foreach (ISensor sensor in sensors) { var series = new LineSeries(); diff --git a/Hardware/ATI/ATIGroup.cs b/Hardware/ATI/ATIGroup.cs index f2603a1..fb375cb 100644 --- a/Hardware/ATI/ATIGroup.cs +++ b/Hardware/ATI/ATIGroup.cs @@ -106,11 +106,7 @@ namespace OpenHardwareMonitor.Hardware.ATI { } } - public IHardware[] Hardware { - get { - return hardware.ToArray(); - } - } + public IEnumerable Hardware => hardware; public string GetReport() { return report.ToString(); diff --git a/Hardware/Aquacomputer/AquacomputerGroup.cs b/Hardware/Aquacomputer/AquacomputerGroup.cs index 0a2581e..d1e5930 100644 --- a/Hardware/Aquacomputer/AquacomputerGroup.cs +++ b/Hardware/Aquacomputer/AquacomputerGroup.cs @@ -50,7 +50,7 @@ namespace OpenHardwareMonitor.Hardware.Aquacomputer } } - public IHardware[] Hardware => _hardware.ToArray(); + public IEnumerable Hardware => _hardware; public void Close() { diff --git a/Hardware/CPU/CPUGroup.cs b/Hardware/CPU/CPUGroup.cs index 7373a46..c72f86e 100644 --- a/Hardware/CPU/CPUGroup.cs +++ b/Hardware/CPU/CPUGroup.cs @@ -119,12 +119,8 @@ namespace OpenHardwareMonitor.Hardware.CPU { index++; } } - - public IHardware[] Hardware { - get { - return hardware.ToArray(); - } - } + + public IEnumerable Hardware => hardware; private static void AppendCpuidData(StringBuilder r, uint[,] data, uint offset) diff --git a/Hardware/Computer.cs b/Hardware/Computer.cs index fd3a3b4..410d70e 100644 --- a/Hardware/Computer.cs +++ b/Hardware/Computer.cs @@ -283,7 +283,7 @@ namespace OpenHardwareMonitor.Hardware { Array.Sort(sensors, CompareSensor); foreach (ISensor sensor in sensors) { string innerSpace = space + "| "; - if (sensor.Parameters.Length > 0) { + if (sensor.Parameters.Count > 0) { w.WriteLine("{0}|", innerSpace); w.WriteLine("{0}+- {1} ({2})", innerSpace, sensor.Name, sensor.Identifier); @@ -365,7 +365,7 @@ namespace OpenHardwareMonitor.Hardware { w.Write(report); } - IHardware[] hardwareArray = group.Hardware; + var hardwareArray = group.Hardware; foreach (IHardware hardware in hardwareArray) ReportHardware(hardware, w); diff --git a/Hardware/HDD/AbstractHarddrive.cs b/Hardware/HDD/AbstractHarddrive.cs index 0958e84..548d01f 100644 --- a/Hardware/HDD/AbstractHarddrive.cs +++ b/Hardware/HDD/AbstractHarddrive.cs @@ -15,9 +15,9 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; -using OpenHardwareMonitor.Collections; -namespace OpenHardwareMonitor.Hardware.HDD { +namespace OpenHardwareMonitor.Hardware.HDD +{ public abstract class AbstractHarddrive : Hardware { private const int UPDATE_DIVIDER = 30; // update only every 30s @@ -33,14 +33,14 @@ namespace OpenHardwareMonitor.Hardware.HDD { typeof(GenericHarddisk) }; - private string firmwareRevision; + private readonly string firmwareRevision; private readonly ISmart smart; private readonly IntPtr handle; private readonly int index; private int count; - private IList smartAttributes; + private readonly IList smartAttributes; private IDictionary sensors; private DriveInfo[] driveInfos; @@ -178,8 +178,8 @@ namespace OpenHardwareMonitor.Hardware.HDD { sensors = new Dictionary(); if (handle != smart.InvalidHandle) { - IList> sensorTypeAndChannels = - new List>(); + IList<(SensorType, int)> sensorTypeAndChannels = + new List<(SensorType, int)>(); DriveAttributeValue[] values = smart.ReadSmartData(handle, index); @@ -196,9 +196,8 @@ namespace OpenHardwareMonitor.Hardware.HDD { } if (!found) continue; - - Pair pair = new Pair( - attribute.SensorType.Value, attribute.SensorChannel); + var pair = (vaule: attribute.SensorType.Value, + sensorChannel: attribute.SensorChannel); if (!sensorTypeAndChannels.Contains(pair)) { Sensor sensor = new Sensor(attribute.SensorName, @@ -352,7 +351,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { } protected static float RawToInt(byte[] raw, byte value, - IReadOnlyArray parameters) + IReadOnlyList parameters) { return (raw[3] << 24) | (raw[2] << 16) | (raw[1] << 8) | raw[0]; } diff --git a/Hardware/HDD/HDDGeneric.cs b/Hardware/HDD/HDDGeneric.cs index 47d9abe..f3948cf 100644 --- a/Hardware/HDD/HDDGeneric.cs +++ b/Hardware/HDD/HDDGeneric.cs @@ -10,12 +10,10 @@ */ -using System; using System.Collections.Generic; -using System.Text; -using OpenHardwareMonitor.Collections; -namespace OpenHardwareMonitor.Hardware.HDD { +namespace OpenHardwareMonitor.Hardware.HDD +{ [NamePrefix("")] internal class GenericHarddisk : AbstractHarddrive { @@ -83,21 +81,21 @@ namespace OpenHardwareMonitor.Hardware.HDD { new SmartAttribute(0xFE, SmartNames.FreeFallProtection), new SmartAttribute(0xC2, SmartNames.Temperature, - (byte[] r, byte v, IReadOnlyArray p) + (byte[] r, byte v, IReadOnlyList p) => { return r[0] + (p == null ? 0 : p[0].Value); }, 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, - (byte[] r, byte v, IReadOnlyArray p) + (byte[] r, byte v, IReadOnlyList p) => { return r[0] + (p == null ? 0 : p[0].Value); }, 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, - (byte[] r, byte v, IReadOnlyArray p) + (byte[] r, byte v, IReadOnlyList p) => { return r[0] + (p == null ? 0 : p[0].Value); }, SensorType.Temperature, 0, "Temperature", false, new[] { new ParameterDescription("Offset [°C]", diff --git a/Hardware/HDD/HarddriveGroup.cs b/Hardware/HDD/HarddriveGroup.cs index 34cfb13..dd18842 100644 --- a/Hardware/HDD/HarddriveGroup.cs +++ b/Hardware/HDD/HarddriveGroup.cs @@ -38,11 +38,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { } } - public IHardware[] Hardware { - get { - return hardware.ToArray(); - } - } + public IEnumerable Hardware => hardware; public string GetReport() { return null; diff --git a/Hardware/HDD/SSDIntel.cs b/Hardware/HDD/SSDIntel.cs index 8162557..cc572c0 100644 --- a/Hardware/HDD/SSDIntel.cs +++ b/Hardware/HDD/SSDIntel.cs @@ -11,8 +11,6 @@ */ using System.Collections.Generic; -using OpenHardwareMonitor.Collections; - namespace OpenHardwareMonitor.Hardware.HDD { [NamePrefix("INTEL SSD"), @@ -34,18 +32,18 @@ namespace OpenHardwareMonitor.Hardware.HDD { new SmartAttribute(0xB8, SmartNames.EndToEndError), new SmartAttribute(0xC0, SmartNames.UnsafeShutdownCount), new SmartAttribute(0xE1, SmartNames.HostWrites, - (byte[] r, byte v, IReadOnlyArray p) + (byte[] r, byte v, IReadOnlyList p) => { return 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, - (byte[] r, byte v, IReadOnlyArray p) + (byte[] r, byte v, IReadOnlyList p) => { return RawToInt(r, v, p) / 0x20; }, SensorType.Data, 0, SmartNames.HostWrites), new SmartAttribute(0xF2, SmartNames.HostReads, - (byte[] r, byte v, IReadOnlyArray p) + (byte[] r, byte v, IReadOnlyList p) => { return RawToInt(r, v, p) / 0x20; }, SensorType.Data, 1, SmartNames.HostReads), }; diff --git a/Hardware/HDD/SSDMicron.cs b/Hardware/HDD/SSDMicron.cs index 493e0fb..c44575f 100644 --- a/Hardware/HDD/SSDMicron.cs +++ b/Hardware/HDD/SSDMicron.cs @@ -9,7 +9,6 @@ */ using System.Collections.Generic; -using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.Hardware.HDD { @@ -30,7 +29,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { new SmartAttribute(0xAD, SmartNames.WearLevelingCount, RawToInt), new SmartAttribute(0xAE, SmartNames.UnexpectedPowerLossCount, RawToInt), new SmartAttribute(0xB5, SmartNames.Non4kAlignedAccess, - (byte[] raw, byte value, IReadOnlyArray p) + (byte[] raw, byte value, IReadOnlyList p) => { return 6e4f * ((raw[5] << 8) | raw[4]); }), new SmartAttribute(0xB7, SmartNames.SataDownshiftErrorCount, RawToInt), new SmartAttribute(0xBB, SmartNames.ReportedUncorrectableErrors, RawToInt), @@ -41,11 +40,11 @@ namespace OpenHardwareMonitor.Hardware.HDD { new SmartAttribute(0xC6, SmartNames.OffLineUncorrectableErrorCount, RawToInt), new SmartAttribute(0xC7, SmartNames.UltraDmaCrcErrorCount, RawToInt), new SmartAttribute(0xCA, SmartNames.RemainingLife, - (byte[] raw, byte value, IReadOnlyArray p) + (byte[] raw, byte value, IReadOnlyList p) => { return 100 - RawToInt(raw, value, p); }, SensorType.Level, 0, SmartNames.RemainingLife), new SmartAttribute(0xCE, SmartNames.WriteErrorRate, - (byte[] raw, byte value, IReadOnlyArray p) + (byte[] raw, byte value, IReadOnlyList p) => { return 6e4f * ((raw[1] << 8) | raw[0]); }), }; diff --git a/Hardware/HDD/SSDPlextor.cs b/Hardware/HDD/SSDPlextor.cs index 02ed57c..d803e2a 100644 --- a/Hardware/HDD/SSDPlextor.cs +++ b/Hardware/HDD/SSDPlextor.cs @@ -10,8 +10,6 @@ namespace OpenHardwareMonitor.Hardware.HDD { using System.Collections.Generic; - using OpenHardwareMonitor.Collections; - [NamePrefix("PLEXTOR")] internal class SSDPlextor : AbstractHarddrive { @@ -30,7 +28,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { : base(smart, name, firmwareRevision, index, smartAttributes, settings) {} private static float RawToGb(byte[] rawvalue, byte value, - IReadOnlyArray parameters) + IReadOnlyList parameters) { return RawToInt(rawvalue, value, parameters) / 32; } diff --git a/Hardware/HDD/SSDSamsung.cs b/Hardware/HDD/SSDSamsung.cs index ecc349d..4441b67 100644 --- a/Hardware/HDD/SSDSamsung.cs +++ b/Hardware/HDD/SSDSamsung.cs @@ -10,7 +10,6 @@ namespace OpenHardwareMonitor.Hardware.HDD { using System.Collections.Generic; - using OpenHardwareMonitor.Collections; [NamePrefix(""), RequireSmart(0xB1), RequireSmart(0xB3), RequireSmart(0xB5), RequireSmart(0xB6), RequireSmart(0xB7), RequireSmart(0xBB), @@ -37,7 +36,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { new SmartAttribute(0xB7, SmartNames.RuntimeBadBlockTotal, RawToInt), new SmartAttribute(0xBB, SmartNames.UncorrectableErrorCount, RawToInt), new SmartAttribute(0xBE, SmartNames.Temperature, - (byte[] r, byte v, IReadOnlyArray p) + (byte[] r, byte v, IReadOnlyList p) => { return r[0] + (p == null ? 0 : p[0].Value); }, SensorType.Temperature, 0, SmartNames.Temperature, false, new[] { new ParameterDescription("Offset [°C]", @@ -51,7 +50,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { new SmartAttribute(0xCA, SmartNames.ExceptionModeStatus), new SmartAttribute(0xEB, SmartNames.PowerRecoveryCount), new SmartAttribute(0xF1, SmartNames.TotalLbasWritten, - (byte[] r, byte v, IReadOnlyArray p) => { + (byte[] r, byte v, IReadOnlyList p) => { return (((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); diff --git a/Hardware/HDD/SSDSandforce.cs b/Hardware/HDD/SSDSandforce.cs index 115ec5f..8a7d407 100644 --- a/Hardware/HDD/SSDSandforce.cs +++ b/Hardware/HDD/SSDSandforce.cs @@ -10,7 +10,6 @@ */ using System.Collections.Generic; -using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.Hardware.HDD { @@ -31,7 +30,7 @@ namespace OpenHardwareMonitor.Hardware.HDD { new SmartAttribute(0xB6, SmartNames.AlternativeEraseFailCount, RawToInt), new SmartAttribute(0xBB, SmartNames.UncorrectableErrorCount, RawToInt), new SmartAttribute(0xC2, SmartNames.Temperature, - (byte[] raw, byte value, IReadOnlyArray p) + (byte[] raw, byte value, IReadOnlyList p) => { return value + (p == null ? 0 : p[0].Value); }, SensorType.Temperature, 0, SmartNames.Temperature, true, new[] { new ParameterDescription("Offset [°C]", diff --git a/Hardware/HDD/SmartAttribute.cs b/Hardware/HDD/SmartAttribute.cs index e06674a..91424e6 100644 --- a/Hardware/HDD/SmartAttribute.cs +++ b/Hardware/HDD/SmartAttribute.cs @@ -11,7 +11,6 @@ using System; using System.Collections.Generic; -using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.Hardware.HDD { public class SmartAttribute { @@ -92,8 +91,8 @@ namespace OpenHardwareMonitor.Hardware.HDD { } } - public float ConvertValue(DriveAttributeValue value, - IReadOnlyArray parameters) + public float ConvertValue(DriveAttributeValue value, + IReadOnlyList parameters) { if (rawValueConversion == null) { return value.AttrValue; @@ -103,6 +102,6 @@ namespace OpenHardwareMonitor.Hardware.HDD { } public delegate float RawValueConversion(byte[] rawValue, byte value, - IReadOnlyArray parameters); + IReadOnlyList parameters); } } diff --git a/Hardware/Hardware.cs b/Hardware/Hardware.cs index 7b4fc87..d7697f1 100644 --- a/Hardware/Hardware.cs +++ b/Hardware/Hardware.cs @@ -9,16 +9,18 @@ */ using System; -using OpenHardwareMonitor.Collections; +using System.Collections.Generic; +using System.Linq; -namespace OpenHardwareMonitor.Hardware { - public abstract class Hardware : IHardware { +namespace OpenHardwareMonitor.Hardware +{ + public abstract class Hardware : IHardware { private readonly Identifier identifier; protected readonly string name; private string customName; protected readonly ISettings settings; - protected readonly ListSet active = new ListSet(); + protected readonly HashSet active = new HashSet(); public Hardware(string name, Identifier identifier, ISettings settings) { this.settings = settings; @@ -41,15 +43,13 @@ namespace OpenHardwareMonitor.Hardware { } protected virtual void ActivateSensor(ISensor sensor) { - if (active.Add(sensor)) - if (SensorAdded != null) - SensorAdded(sensor); + if (active.Add(sensor)) + SensorAdded?.Invoke(sensor); } protected virtual void DeactivateSensor(ISensor sensor) { if (active.Remove(sensor)) - if (SensorRemoved != null) - SensorRemoved(sensor); + SensorRemoved?.Invoke(sensor); } public string Name { diff --git a/Hardware/Heatmaster/HeatmasterGroup.cs b/Hardware/Heatmaster/HeatmasterGroup.cs index 7174d19..dc927d9 100644 --- a/Hardware/Heatmaster/HeatmasterGroup.cs +++ b/Hardware/Heatmaster/HeatmasterGroup.cs @@ -145,11 +145,7 @@ namespace OpenHardwareMonitor.Hardware.Heatmaster { } } - public IHardware[] Hardware { - get { - return hardware.ToArray(); - } - } + public IEnumerable Hardware => hardware; public string GetReport() { if (report.Length > 0) { diff --git a/Hardware/IGroup.cs b/Hardware/IGroup.cs index f95d6b6..29ad71e 100644 --- a/Hardware/IGroup.cs +++ b/Hardware/IGroup.cs @@ -8,11 +8,13 @@ */ +using System.Collections.Generic; + namespace OpenHardwareMonitor.Hardware { internal interface IGroup { - IHardware[] Hardware { get; } + IEnumerable Hardware { get; } string GetReport(); diff --git a/Hardware/ISensor.cs b/Hardware/ISensor.cs index 1760e06..0ef7e43 100644 --- a/Hardware/ISensor.cs +++ b/Hardware/ISensor.cs @@ -10,9 +10,9 @@ using System; using System.Collections.Generic; -using OpenHardwareMonitor.Collections; -namespace OpenHardwareMonitor.Hardware { +namespace OpenHardwareMonitor.Hardware +{ public enum SensorType { Voltage, // V @@ -56,7 +56,7 @@ namespace OpenHardwareMonitor.Hardware { bool IsDefaultHidden { get; } - IReadOnlyArray Parameters { get; } + IReadOnlyList Parameters { get; } float? Value { get; } float? Min { get; } diff --git a/Hardware/Mainboard/MainboardGroup.cs b/Hardware/Mainboard/MainboardGroup.cs index 0f9b9c1..f7884fc 100644 --- a/Hardware/Mainboard/MainboardGroup.cs +++ b/Hardware/Mainboard/MainboardGroup.cs @@ -8,6 +8,8 @@ */ +using System.Collections.Generic; + namespace OpenHardwareMonitor.Hardware.Mainboard { internal class MainboardGroup : IGroup { @@ -27,7 +29,7 @@ namespace OpenHardwareMonitor.Hardware.Mainboard { return null; } - public IHardware[] Hardware { + public IEnumerable Hardware { get { return mainboards; } } diff --git a/Hardware/Nic/NicGroup.cs b/Hardware/Nic/NicGroup.cs index 2fc66cd..771c73d 100644 --- a/Hardware/Nic/NicGroup.cs +++ b/Hardware/Nic/NicGroup.cs @@ -54,14 +54,8 @@ namespace OpenHardwareMonitor.Hardware.Nic return report.ToString(); } - public IHardware[] Hardware - { - get - { - return hardware.ToArray(); - } - } - public NetworkInterface[] NetworkInterfaces + public IEnumerable Hardware => hardware; + public NetworkInterface[] NetworkInterfaces { get { diff --git a/Hardware/Nvidia/NvidiaGroup.cs b/Hardware/Nvidia/NvidiaGroup.cs index dc2847f..001e462 100644 --- a/Hardware/Nvidia/NvidiaGroup.cs +++ b/Hardware/Nvidia/NvidiaGroup.cs @@ -88,11 +88,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia { report.AppendLine(); } - public IHardware[] Hardware { - get { - return hardware.ToArray(); - } - } + public IEnumerable Hardware => hardware; public string GetReport() { return report.ToString(); diff --git a/Hardware/RAM/RAMGroup.cs b/Hardware/RAM/RAMGroup.cs index 882e86f..a3706fe 100644 --- a/Hardware/RAM/RAMGroup.cs +++ b/Hardware/RAM/RAMGroup.cs @@ -9,6 +9,7 @@ */ using System; +using System.Collections.Generic; namespace OpenHardwareMonitor.Hardware.RAM { internal class RAMGroup : IGroup { @@ -31,11 +32,7 @@ namespace OpenHardwareMonitor.Hardware.RAM { return null; } - public IHardware[] Hardware { - get { - return hardware; - } - } + public IEnumerable Hardware => hardware; public void Close() { foreach (Hardware ram in hardware) diff --git a/Hardware/Sensor.cs b/Hardware/Sensor.cs index b87dbf7..08217fb 100644 --- a/Hardware/Sensor.cs +++ b/Hardware/Sensor.cs @@ -13,7 +13,6 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.IO.Compression; -using OpenHardwareMonitor.Collections; namespace OpenHardwareMonitor.Hardware { @@ -25,12 +24,11 @@ namespace OpenHardwareMonitor.Hardware { private readonly bool defaultHidden; private readonly SensorType sensorType; private readonly Hardware hardware; - private readonly ReadOnlyArray parameters; + private readonly IReadOnlyList parameters; private float? currentValue; private float? minValue; private float? maxValue; - private readonly RingCollection - values = new RingCollection(); + private readonly List values = new List(); private readonly ISettings settings; private IControl control; @@ -124,13 +122,13 @@ namespace OpenHardwareMonitor.Hardware { } private void AppendValue(float value, DateTime time) { - if (values.Count >= 2 && values.Last.Value == value && + if (values.Count >= 2 && values[values.Count - 1].Value == value && values[values.Count - 2].Value == value) { - values.Last = new SensorValue(value, time); + values[values.Count - 1] = new SensorValue(value, time); return; } - values.Append(new SensorValue(value, time)); + values.Add(new SensorValue(value, time)); } public IHardware Hardware { @@ -170,7 +168,7 @@ namespace OpenHardwareMonitor.Hardware { get { return defaultHidden; } } - public IReadOnlyArray Parameters { + public IReadOnlyList Parameters { get { return parameters; } } @@ -180,8 +178,8 @@ namespace OpenHardwareMonitor.Hardware { } set { DateTime now = DateTime.UtcNow; - while (values.Count > 0 && (now - values.First.Time).TotalDays > 1) - values.Remove(); + while (values.Count > 0 && (now - values[0].Time).TotalDays > 1) + values.RemoveAt(0); if (value.HasValue) { sum += value.Value; diff --git a/Hardware/TBalancer/TBalancerGroup.cs b/Hardware/TBalancer/TBalancerGroup.cs index 88c3ce3..79b4a89 100644 --- a/Hardware/TBalancer/TBalancerGroup.cs +++ b/Hardware/TBalancer/TBalancerGroup.cs @@ -129,11 +129,7 @@ namespace OpenHardwareMonitor.Hardware.TBalancer { } } - public IHardware[] Hardware { - get { - return hardware.ToArray(); - } - } + public IEnumerable Hardware => hardware; public string GetReport() { if (report.Length > 0) { diff --git a/OpenHardwareMonitorLib.csproj b/OpenHardwareMonitorLib.csproj index bb720e8..a35ce60 100644 --- a/OpenHardwareMonitorLib.csproj +++ b/OpenHardwareMonitorLib.csproj @@ -26,8 +26,6 @@ - - @@ -111,9 +109,6 @@ - - - @@ -141,5 +136,6 @@ + \ No newline at end of file