# HG changeset patch # User moel.mich # Date 1273173638 0 # Node ID 70d0c31024244f243c780e21b6ef1b544efa408b # Parent 4f569432e14b981f90ee12aa4e334321e6a8e200 Added an Identifier class for IHardware, ISensor and IParameter Identifier properties. diff -r 4f569432e14b -r 70d0c3102424 GUI/SensorNotifyIcon.cs --- a/GUI/SensorNotifyIcon.cs Tue May 04 17:32:41 2010 +0000 +++ b/GUI/SensorNotifyIcon.cs Thu May 06 19:20:38 2010 +0000 @@ -71,7 +71,8 @@ if (sensor.SensorType == SensorType.Load) { defaultColor = Color.FromArgb(0xff, 0x70, 0x8c, 0xf1); } - Color = Config.Get(sensor.Identifier + "/traycolor", defaultColor); + Color = Config.Get(new Identifier(sensor.Identifier, + "traycolor").ToString(), defaultColor); this.pen = new Pen(Color.FromArgb(96, Color.Black)); this.font = new Font(SystemFonts.MessageBoxFont.FontFamily, 9); @@ -88,7 +89,8 @@ dialog.Color = Color; if (dialog.ShowDialog() == DialogResult.OK) { Color = dialog.Color; - Config.Set(sensor.Identifier + "/traycolor", Color); + Config.Set(new Identifier(sensor.Identifier, + "traycolor").ToString(), Color); } }; contextMenuStrip.Items.Add(colorItem); diff -r 4f569432e14b -r 70d0c3102424 GUI/SensorSystemTray.cs --- a/GUI/SensorSystemTray.cs Tue May 04 17:32:41 2010 +0000 +++ b/GUI/SensorSystemTray.cs Thu May 06 19:20:38 2010 +0000 @@ -73,7 +73,8 @@ } private void SensorAdded(ISensor sensor) { - if (Config.Get(sensor.Identifier + "/tray", false)) + if (Config.Get(new Identifier(sensor.Identifier, + "tray").ToString(), false)) Add(sensor, false); } @@ -104,7 +105,7 @@ return; } else { list.Add(new SensorNotifyIcon(this, sensor, balloonTip)); - Config.Set(sensor.Identifier + "/tray", true); + Config.Set(new Identifier(sensor.Identifier, "tray").ToString(), true); } } @@ -114,8 +115,10 @@ private void Remove(ISensor sensor, bool deleteConfig) { if (deleteConfig) { - Config.Remove(sensor.Identifier + "/tray"); - Config.Remove(sensor.Identifier + "/traycolor"); + Config.Remove( + new Identifier(sensor.Identifier, "tray").ToString()); + Config.Remove( + new Identifier(sensor.Identifier, "traycolor").ToString()); } SensorNotifyIcon instance = null; foreach (SensorNotifyIcon icon in list) diff -r 4f569432e14b -r 70d0c3102424 Hardware/ATI/ATIGPU.cs --- a/Hardware/ATI/ATIGPU.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/ATI/ATIGPU.cs Thu May 06 19:20:38 2010 +0000 @@ -69,7 +69,8 @@ this.temperature = new Sensor("GPU Core", 0, SensorType.Temperature, this); - this.fan = new Sensor("GPU", 0, speedInfo.MaxRPM, SensorType.Fan, this); + this.fan = new Sensor("GPU", 0, speedInfo.MaxRPM, SensorType.Fan, this, + null); this.coreClock = new Sensor("GPU Core", 0, SensorType.Clock, this); this.memoryClock = new Sensor("GPU Memory", 1, SensorType.Clock, this); this.coreVoltage = new Sensor("GPU Core", 0, SensorType.Voltage, this); @@ -85,8 +86,8 @@ get { return name; } } - public string Identifier { - get { return "/atigpu/" + adapterIndex; } + public Identifier Identifier { + get { return new Identifier("atigpu", adapterIndex.ToString()); } } public Image Icon { diff -r 4f569432e14b -r 70d0c3102424 Hardware/CPU/AMD0FCPU.cs --- a/Hardware/CPU/AMD0FCPU.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/CPU/AMD0FCPU.cs Thu May 06 19:20:38 2010 +0000 @@ -121,8 +121,8 @@ get { return name; } } - public string Identifier { - get { return "/amdcpu/" + processorIndex; } + public Identifier Identifier { + get { return new Identifier("amdcpu", processorIndex.ToString()); } } public Image Icon { diff -r 4f569432e14b -r 70d0c3102424 Hardware/CPU/AMD10CPU.cs --- a/Hardware/CPU/AMD10CPU.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/CPU/AMD10CPU.cs Thu May 06 19:20:38 2010 +0000 @@ -103,8 +103,8 @@ get { return name; } } - public string Identifier { - get { return "/amdcpu/" + processorIndex; } + public Identifier Identifier { + get { return new Identifier("amdcpu", processorIndex.ToString()); } } public Image Icon { diff -r 4f569432e14b -r 70d0c3102424 Hardware/CPU/IntelCPU.cs --- a/Hardware/CPU/IntelCPU.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/CPU/IntelCPU.cs Thu May 06 19:20:38 2010 +0000 @@ -237,8 +237,8 @@ get { return name; } } - public string Identifier { - get { return "/intelcpu/" + processorIndex; } + public Identifier Identifier { + get { return new Identifier("intelcpu", processorIndex.ToString()); } } public Image Icon { diff -r 4f569432e14b -r 70d0c3102424 Hardware/HDD/HDD.cs --- a/Hardware/HDD/HDD.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/HDD/HDD.cs Thu May 06 19:20:38 2010 +0000 @@ -69,8 +69,8 @@ get { return name; } } - public string Identifier { - get { return "/hdd/" + drive; } + public Identifier Identifier { + get { return new Identifier("hdd", drive.ToString()); } } public Image Icon { diff -r 4f569432e14b -r 70d0c3102424 Hardware/IHardware.cs --- a/Hardware/IHardware.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/IHardware.cs Thu May 06 19:20:38 2010 +0000 @@ -46,7 +46,7 @@ public interface IHardware { string Name { get; } - string Identifier { get; } + Identifier Identifier { get; } Image Icon { get; } diff -r 4f569432e14b -r 70d0c3102424 Hardware/IParameter.cs --- a/Hardware/IParameter.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/IParameter.cs Thu May 06 19:20:38 2010 +0000 @@ -43,7 +43,7 @@ public interface IParameter { ISensor Sensor { get; } - string Identifier { get; } + Identifier Identifier { get; } string Name { get; } string Description { get; } diff -r 4f569432e14b -r 70d0c3102424 Hardware/ISensor.cs --- a/Hardware/ISensor.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/ISensor.cs Thu May 06 19:20:38 2010 +0000 @@ -60,10 +60,13 @@ IHardware Hardware { get; } SensorType SensorType { get; } - string Identifier { get; } + Identifier Identifier { get; } + string Name { get; set; } int Index { get; } + bool IsDefaultHidden { get; } + IReadOnlyArray Parameters { get; } float? Value { get; } diff -r 4f569432e14b -r 70d0c3102424 Hardware/Identifier.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hardware/Identifier.cs Thu May 06 19:20:38 2010 +0000 @@ -0,0 +1,96 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenHardwareMonitor.Hardware { + public class Identifier { + private string identifier; + + private static char SEPARATOR = '/'; + + private void CheckIdentifiers(string[] identifiers) { + foreach (string s in identifiers) + if (s.Contains(" ") || s.Contains(SEPARATOR.ToString())) + throw new ArgumentException("Invalid identifier"); + } + + public Identifier(params string[] identifiers) { + CheckIdentifiers(identifiers); + + StringBuilder s = new StringBuilder(); + for (int i = 0; i < identifiers.Length; i++) { + s.Append(SEPARATOR); + s.Append(identifiers[i]); + } + this.identifier = s.ToString(); + } + + public Identifier(Identifier identifier, params string[] extensions) { + CheckIdentifiers(extensions); + + StringBuilder s = new StringBuilder(); + s.Append(identifier.ToString()); + for (int i = 0; i < extensions.Length; i++) { + s.Append(SEPARATOR); + s.Append(extensions[i]); + } + this.identifier = s.ToString(); + } + + public override string ToString() { + return identifier; + } + + public override bool Equals(System.Object obj) { + if (obj == null) + return false; + + Identifier id = obj as Identifier; + if (id == null) + return false; + + return (identifier == id.identifier); + } + + public override int GetHashCode() { + return identifier.GetHashCode(); + } + } +} diff -r 4f569432e14b -r 70d0c3102424 Hardware/LPC/LPCHardware.cs --- a/Hardware/LPC/LPCHardware.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/LPC/LPCHardware.cs Thu May 06 19:20:38 2010 +0000 @@ -73,8 +73,8 @@ } } - public string Identifier { - get { return "/lpc/" + chip.ToString().ToLower(); } + public Identifier Identifier { + get { return new Identifier("lpc", chip.ToString().ToLower()); } } public Image Icon { diff -r 4f569432e14b -r 70d0c3102424 Hardware/Mainboard/Mainboard.cs --- a/Hardware/Mainboard/Mainboard.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/Mainboard/Mainboard.cs Thu May 06 19:20:38 2010 +0000 @@ -75,8 +75,8 @@ get { return name; } } - public string Identifier { - get { return "/mainboard"; } + public Identifier Identifier { + get { return new Identifier("mainboard"); } } public Image Icon { diff -r 4f569432e14b -r 70d0c3102424 Hardware/Nvidia/NvidiaGPU.cs --- a/Hardware/Nvidia/NvidiaGPU.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/Nvidia/NvidiaGPU.cs Thu May 06 19:20:38 2010 +0000 @@ -75,7 +75,7 @@ default: name = "GPU"; break; } temperatures[i] = new Sensor(name, i, sensor.DefaultMaxTemp, - SensorType.Temperature, this); + SensorType.Temperature, this, new ParameterDescription[0]); ActivateSensor(temperatures[i]); } @@ -93,8 +93,8 @@ get { return name; } } - public string Identifier { - get { return "/nvidiagpu/" + adapterIndex; } + public Identifier Identifier { + get { return new Identifier("nvidiagpu", adapterIndex.ToString()); } } public Image Icon { diff -r 4f569432e14b -r 70d0c3102424 Hardware/Parameter.cs --- a/Hardware/Parameter.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/Parameter.cs Thu May 06 19:20:38 2010 +0000 @@ -68,8 +68,9 @@ public Parameter(ParameterDescription description, ISensor sensor) { this.sensor = sensor; this.description = description; - this.value = Utilities.Config.Get(Identifier, description.DefaultValue); - this.isDefault = !Utilities.Config.Contains(Identifier); + this.value = Utilities.Config.Get(Identifier.ToString(), + description.DefaultValue); + this.isDefault = !Utilities.Config.Contains(Identifier.ToString()); } public ISensor Sensor { @@ -78,10 +79,10 @@ } } - public string Identifier { + public Identifier Identifier { get { - return sensor.Identifier + "/parameter/" + - Name.Replace(" ", "").ToLower(); + return new Identifier(sensor.Identifier, "parameter", + Name.Replace(" ", "").ToLower()); } } @@ -96,7 +97,7 @@ set { this.isDefault = false; this.value = value; - Utilities.Config.Set(Identifier, value); + Utilities.Config.Set(Identifier.ToString(), value); } } @@ -110,7 +111,7 @@ this.isDefault = value; if (value) { this.value = description.DefaultValue; - Utilities.Config.Remove(Identifier); + Utilities.Config.Remove(Identifier.ToString()); } } } diff -r 4f569432e14b -r 70d0c3102424 Hardware/Sensor.cs --- a/Hardware/Sensor.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/Sensor.cs Thu May 06 19:20:38 2010 +0000 @@ -46,6 +46,7 @@ private string defaultName; private string name; private int index; + private bool defaultHidden; private SensorType sensorType; private IHardware hardware; private ReadOnlyArray parameters; @@ -64,31 +65,37 @@ public Sensor(string name, int index, SensorType sensorType, IHardware hardware) : this(name, index, null, sensorType, hardware, - new ParameterDescription[0]) { } + null) { } - public Sensor(string name, int index, float? limit, - SensorType sensorType, IHardware hardware) : this(name, index, limit, - sensorType, hardware, new ParameterDescription[0]) { } + public Sensor(string name, int index, float? limit, SensorType sensorType, + IHardware hardware, ParameterDescription[] parameterDescriptions) : + this(name, index, false, limit, sensorType, hardware, + parameterDescriptions) { } - public Sensor(string name, int index, float? limit, SensorType sensorType, - IHardware hardware, ParameterDescription[] parameterDescriptions) + public Sensor(string name, int index, bool defaultHidden, + float? limit, SensorType sensorType, IHardware hardware, + ParameterDescription[] parameterDescriptions) { this.defaultName = name; this.index = index; + this.defaultHidden = defaultHidden; this.defaultLimit = limit; this.sensorType = sensorType; this.hardware = hardware; - Parameter[] parameters = new Parameter[parameterDescriptions.Length]; + Parameter[] parameters = new Parameter[parameterDescriptions == null ? + 0 : parameterDescriptions.Length]; for (int i = 0; i < parameters.Length; i++ ) parameters[i] = new Parameter(parameterDescriptions[i], this); this.parameters = parameters; - string configName = Config.Settings[Identifier + "/name"]; + string configName = Config.Settings[ + new Identifier(Identifier, "name").ToString()]; if (configName != null) this.name = configName; else this.name = name; - string configLimit = Config.Settings[Identifier + "/limit"]; + string configLimit = Config.Settings[ + new Identifier(Identifier, "limit").ToString()]; if (configLimit != null && configLimit != "") this.limit = float.Parse(configLimit); else @@ -103,10 +110,10 @@ get { return sensorType; } } - public string Identifier { + public Identifier Identifier { get { - return hardware.Identifier + "/" + sensorType.ToString().ToLower() + - "/" + index; + return new Identifier(hardware.Identifier, + sensorType.ToString().ToLower(), index.ToString()); } } @@ -119,7 +126,7 @@ name = value; else name = defaultName; - Config.Settings[Identifier + "/name"] = name; + Config.Settings[new Identifier(Identifier, "name").ToString()] = name; } } @@ -127,6 +134,10 @@ get { return index; } } + public bool IsDefaultHidden { + get { return defaultHidden; } + } + public IReadOnlyArray Parameters { get { return parameters; } } @@ -169,11 +180,11 @@ set { if (value.HasValue) { limit = value; - Config.Settings[Identifier + "/limit"] = + Config.Settings[new Identifier(Identifier, "limit").ToString()] = limit.ToString(); } else { limit = defaultLimit; - Config.Settings[Identifier + "/limit"] = ""; + Config.Settings[new Identifier(Identifier, "limit").ToString()] = ""; } } } diff -r 4f569432e14b -r 70d0c3102424 Hardware/TBalancer/TBalancer.cs --- a/Hardware/TBalancer/TBalancer.cs Tue May 04 17:32:41 2010 +0000 +++ b/Hardware/TBalancer/TBalancer.cs Thu May 06 19:20:38 2010 +0000 @@ -153,7 +153,7 @@ if (miniNGFans[number * 2 + i] == null) miniNGFans[number * 2 + i] = new Sensor("miniNG #" + (number + 1) + " Fan Channel " + (i + 1), - 4 + number * 2 + i, maxRPM, SensorType.Fan, this); + 4 + number * 2 + i, maxRPM, SensorType.Fan, this, null); Sensor sensor = miniNGFans[number * 2 + i]; @@ -251,8 +251,8 @@ get { return "T-Balancer bigNG"; } } - public string Identifier { - get { return "/bigng/" + this.portIndex; } + public Identifier Identifier { + get { return new Identifier("bigng", this.portIndex.ToString()); } } public IHardware[] SubHardware { diff -r 4f569432e14b -r 70d0c3102424 OpenHardwareMonitor.csproj --- a/OpenHardwareMonitor.csproj Tue May 04 17:32:41 2010 +0000 +++ b/OpenHardwareMonitor.csproj Thu May 06 19:20:38 2010 +0000 @@ -85,6 +85,7 @@ + @@ -127,6 +128,7 @@ + UserControl diff -r 4f569432e14b -r 70d0c3102424 Utilities/ListSet.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Utilities/ListSet.cs Thu May 06 19:20:38 2010 +0000 @@ -0,0 +1,70 @@ +/* + + Version: MPL 1.1/GPL 2.0/LGPL 2.1 + + The contents of this file are subject to the Mozilla Public License Version + 1.1 (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" basis, + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + for the specific language governing rights and limitations under the License. + + The Original Code is the Open Hardware Monitor code. + + The Initial Developer of the Original Code is + Michael Möller . + Portions created by the Initial Developer are Copyright (C) 2009-2010 + the Initial Developer. All Rights Reserved. + + Contributor(s): + + Alternatively, the contents of this file may be used under the terms of + either the GNU General Public License Version 2 or later (the "GPL"), or + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + in which case the provisions of the GPL or the LGPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of either the GPL or the LGPL, and not to allow others to + use your version of this file under the terms of the MPL, indicate your + decision by deleting the provisions above and replace them with the notice + and other provisions required by the GPL or the LGPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the MPL, the GPL or the LGPL. + +*/ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenHardwareMonitor.Utilities { + public class ListSet { + + private List list = new List(); + + public ListSet() { } + + 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); + } + + } +}