mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-29 21:37:38 +00:00
Added an Identifier class for IHardware, ISensor and IParameter Identifier properties.
This commit is contained in:
parent
d897c6127c
commit
a49919717e
@ -71,7 +71,8 @@ namespace OpenHardwareMonitor.GUI {
|
||||
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 @@ namespace OpenHardwareMonitor.GUI {
|
||||
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);
|
||||
|
@ -73,7 +73,8 @@ namespace OpenHardwareMonitor.GUI {
|
||||
}
|
||||
|
||||
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 @@ namespace OpenHardwareMonitor.GUI {
|
||||
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 @@ namespace OpenHardwareMonitor.GUI {
|
||||
|
||||
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)
|
||||
|
@ -69,7 +69,8 @@ namespace OpenHardwareMonitor.Hardware.ATI {
|
||||
|
||||
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 @@ namespace OpenHardwareMonitor.Hardware.ATI {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Identifier {
|
||||
get { return "/atigpu/" + adapterIndex; }
|
||||
public Identifier Identifier {
|
||||
get { return new Identifier("atigpu", adapterIndex.ToString()); }
|
||||
}
|
||||
|
||||
public Image Icon {
|
||||
|
@ -121,8 +121,8 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Identifier {
|
||||
get { return "/amdcpu/" + processorIndex; }
|
||||
public Identifier Identifier {
|
||||
get { return new Identifier("amdcpu", processorIndex.ToString()); }
|
||||
}
|
||||
|
||||
public Image Icon {
|
||||
|
@ -103,8 +103,8 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Identifier {
|
||||
get { return "/amdcpu/" + processorIndex; }
|
||||
public Identifier Identifier {
|
||||
get { return new Identifier("amdcpu", processorIndex.ToString()); }
|
||||
}
|
||||
|
||||
public Image Icon {
|
||||
|
@ -237,8 +237,8 @@ namespace OpenHardwareMonitor.Hardware.CPU {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Identifier {
|
||||
get { return "/intelcpu/" + processorIndex; }
|
||||
public Identifier Identifier {
|
||||
get { return new Identifier("intelcpu", processorIndex.ToString()); }
|
||||
}
|
||||
|
||||
public Image Icon {
|
||||
|
@ -69,8 +69,8 @@ namespace OpenHardwareMonitor.Hardware.HDD {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Identifier {
|
||||
get { return "/hdd/" + drive; }
|
||||
public Identifier Identifier {
|
||||
get { return new Identifier("hdd", drive.ToString()); }
|
||||
}
|
||||
|
||||
public Image Icon {
|
||||
|
@ -46,7 +46,7 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
public interface IHardware {
|
||||
|
||||
string Name { get; }
|
||||
string Identifier { get; }
|
||||
Identifier Identifier { get; }
|
||||
|
||||
Image Icon { get; }
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
public interface IParameter {
|
||||
|
||||
ISensor Sensor { get; }
|
||||
string Identifier { get; }
|
||||
Identifier Identifier { get; }
|
||||
|
||||
string Name { get; }
|
||||
string Description { get; }
|
||||
|
@ -60,10 +60,13 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
IHardware Hardware { get; }
|
||||
|
||||
SensorType SensorType { get; }
|
||||
string Identifier { get; }
|
||||
Identifier Identifier { get; }
|
||||
|
||||
string Name { get; set; }
|
||||
int Index { get; }
|
||||
|
||||
bool IsDefaultHidden { get; }
|
||||
|
||||
IReadOnlyArray<IParameter> Parameters { get; }
|
||||
|
||||
float? Value { get; }
|
||||
|
96
Hardware/Identifier.cs
Normal file
96
Hardware/Identifier.cs
Normal file
@ -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 <m.moeller@gmx.ch>.
|
||||
Portions created by the Initial Developer are Copyright (C) 2009-2010
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms of
|
||||
either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
of those above. If you wish to allow use of your version of this file only
|
||||
under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
use your version of this file under the terms of the MPL, indicate your
|
||||
decision by deleting the provisions above and replace them with the notice
|
||||
and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the MPL, the GPL or the LGPL.
|
||||
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -73,8 +73,8 @@ namespace OpenHardwareMonitor.Hardware.LPC {
|
||||
}
|
||||
}
|
||||
|
||||
public string Identifier {
|
||||
get { return "/lpc/" + chip.ToString().ToLower(); }
|
||||
public Identifier Identifier {
|
||||
get { return new Identifier("lpc", chip.ToString().ToLower()); }
|
||||
}
|
||||
|
||||
public Image Icon {
|
||||
|
@ -75,8 +75,8 @@ namespace OpenHardwareMonitor.Hardware.Mainboard {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Identifier {
|
||||
get { return "/mainboard"; }
|
||||
public Identifier Identifier {
|
||||
get { return new Identifier("mainboard"); }
|
||||
}
|
||||
|
||||
public Image Icon {
|
||||
|
@ -75,7 +75,7 @@ namespace OpenHardwareMonitor.Hardware.Nvidia {
|
||||
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 @@ namespace OpenHardwareMonitor.Hardware.Nvidia {
|
||||
get { return name; }
|
||||
}
|
||||
|
||||
public string Identifier {
|
||||
get { return "/nvidiagpu/" + adapterIndex; }
|
||||
public Identifier Identifier {
|
||||
get { return new Identifier("nvidiagpu", adapterIndex.ToString()); }
|
||||
}
|
||||
|
||||
public Image Icon {
|
||||
|
@ -68,8 +68,9 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
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 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
set {
|
||||
this.isDefault = false;
|
||||
this.value = value;
|
||||
Utilities.Config.Set(Identifier, value);
|
||||
Utilities.Config.Set(Identifier.ToString(), value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,7 +111,7 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
this.isDefault = value;
|
||||
if (value) {
|
||||
this.value = description.DefaultValue;
|
||||
Utilities.Config.Remove(Identifier);
|
||||
Utilities.Config.Remove(Identifier.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
private string defaultName;
|
||||
private string name;
|
||||
private int index;
|
||||
private bool defaultHidden;
|
||||
private SensorType sensorType;
|
||||
private IHardware hardware;
|
||||
private ReadOnlyArray<IParameter> parameters;
|
||||
@ -64,31 +65,37 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
|
||||
public Sensor(string name, int index, SensorType sensorType,
|
||||
IHardware hardware) : this(name, index, null, sensorType, hardware,
|
||||
new ParameterDescription[0]) { }
|
||||
|
||||
public Sensor(string name, int index, float? limit,
|
||||
SensorType sensorType, IHardware hardware) : this(name, index, limit,
|
||||
sensorType, hardware, new ParameterDescription[0]) { }
|
||||
null) { }
|
||||
|
||||
public Sensor(string name, int index, float? limit, SensorType sensorType,
|
||||
IHardware hardware, ParameterDescription[] parameterDescriptions)
|
||||
IHardware hardware, ParameterDescription[] parameterDescriptions) :
|
||||
this(name, index, false, limit, sensorType, hardware,
|
||||
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 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
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 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
name = value;
|
||||
else
|
||||
name = defaultName;
|
||||
Config.Settings[Identifier + "/name"] = name;
|
||||
Config.Settings[new Identifier(Identifier, "name").ToString()] = name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,6 +134,10 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
get { return index; }
|
||||
}
|
||||
|
||||
public bool IsDefaultHidden {
|
||||
get { return defaultHidden; }
|
||||
}
|
||||
|
||||
public IReadOnlyArray<IParameter> Parameters {
|
||||
get { return parameters; }
|
||||
}
|
||||
@ -169,11 +180,11 @@ namespace OpenHardwareMonitor.Hardware {
|
||||
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()] = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
|
||||
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 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
|
||||
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 {
|
||||
|
@ -85,6 +85,7 @@
|
||||
<Compile Include="Hardware\HDD\HDDGroup.cs" />
|
||||
<Compile Include="Hardware\HDD\SMART.cs" />
|
||||
<Compile Include="Hardware\IComputer.cs" />
|
||||
<Compile Include="Hardware\Identifier.cs" />
|
||||
<Compile Include="Hardware\IParameter.cs" />
|
||||
<Compile Include="Hardware\LPC\Chip.cs" />
|
||||
<Compile Include="Hardware\LPC\F718XX.cs" />
|
||||
@ -127,6 +128,7 @@
|
||||
<Compile Include="Utilities\HexStringArray.cs" />
|
||||
<Compile Include="Utilities\IconFactory.cs" />
|
||||
<Compile Include="Utilities\IReadOnlyArray.cs" />
|
||||
<Compile Include="Utilities\ListSet.cs" />
|
||||
<Compile Include="Utilities\PInvokeDelegateFactory.cs" />
|
||||
<Compile Include="GUI\PlotPanel.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
|
70
Utilities/ListSet.cs
Normal file
70
Utilities/ListSet.cs
Normal file
@ -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 <m.moeller@gmx.ch>.
|
||||
Portions created by the Initial Developer are Copyright (C) 2009-2010
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
||||
Alternatively, the contents of this file may be used under the terms of
|
||||
either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
of those above. If you wish to allow use of your version of this file only
|
||||
under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
use your version of this file under the terms of the MPL, indicate your
|
||||
decision by deleting the provisions above and replace them with the notice
|
||||
and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
the provisions above, a recipient may use your version of this file under
|
||||
the terms of any one of the MPL, the GPL or the LGPL.
|
||||
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenHardwareMonitor.Utilities {
|
||||
public class ListSet<T> {
|
||||
|
||||
private List<T> list = new List<T>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user