Search all possible registry locations for the Heatmaster serial port.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
41 using System.Globalization;
43 using System.Threading;
44 using System.Security;
45 using System.Security.Permissions;
48 namespace OpenHardwareMonitor.Hardware {
50 public class Computer : IComputer {
52 private List<IGroup> groups = new List<IGroup>();
54 private bool open = false;
55 private bool hddEnabled = false;
56 private ISettings settings;
59 this.settings = new Settings();
62 public Computer(ISettings settings) {
64 this.settings = settings;
66 this.settings = new Settings();
70 private void Add(IGroup group) {
71 if (groups.Contains(group))
76 if (HardwareAdded != null)
77 foreach (IHardware hardware in group.Hardware)
78 HardwareAdded(hardware);
81 private void Remove(IGroup group) {
82 if (!groups.Contains(group))
87 if (HardwareRemoved != null)
88 foreach (IHardware hardware in group.Hardware)
89 HardwareRemoved(hardware);
92 [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
99 Add(new Mainboard.MainboardGroup(settings));
100 Add(new CPU.CPUGroup(settings));
101 Add(new ATI.ATIGroup(settings));
102 Add(new Nvidia.NvidiaGroup(settings));
103 Add(new TBalancer.TBalancerGroup(settings));
104 Add(new Heatmaster.HeatmasterGroup(settings));
107 Add(new HDD.HDDGroup(settings));
112 public bool HDDEnabled {
113 get { return hddEnabled; }
115 [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
117 if (open && value && !hddEnabled) {
118 Add(new HDD.HDDGroup(settings));
119 } else if (open && !value && hddEnabled) {
120 List<IGroup> list = new List<IGroup>();
121 foreach (IGroup group in groups)
122 if (group is HDD.HDDGroup)
124 foreach (IGroup group in list)
131 public IHardware[] Hardware {
133 List<IHardware> list = new List<IHardware>();
134 foreach (IGroup group in groups)
135 foreach (IHardware hardware in group.Hardware)
137 return list.ToArray();
141 private static void NewSection(TextWriter writer) {
142 for (int i = 0; i < 8; i++)
143 writer.Write("----------");
148 private int CompareSensor(ISensor a, ISensor b) {
149 int c = a.SensorType.CompareTo(b.SensorType);
151 return a.Index.CompareTo(b.Index);
156 private void ReportHardwareSensorTree(IHardware hardware, TextWriter w,
158 w.WriteLine("{0}|", space);
159 w.WriteLine("{0}+-+ {1} ({2})",
160 space, hardware.Name, hardware.Identifier);
161 ISensor[] sensors = hardware.Sensors;
162 Array.Sort<ISensor>(sensors, CompareSensor);
163 foreach (ISensor sensor in sensors) {
164 w.WriteLine("{0}| +- {1}[{2}] : {3} : {4}",
165 space, sensor.SensorType, sensor.Index,
166 string.Format(CultureInfo.InvariantCulture, "{0} : {1} : {2}",
167 sensor.Value, sensor.Min, sensor.Max), sensor.Name);
169 foreach (IHardware subHardware in hardware.SubHardware)
170 ReportHardwareSensorTree(subHardware, w, "| ");
173 private void ReportHardwareParameterTree(IHardware hardware, TextWriter w,
175 w.WriteLine("{0}|", space);
176 w.WriteLine("{0}+-+ {1} ({2})",
177 space, hardware.Name, hardware.Identifier);
178 ISensor[] sensors = hardware.Sensors;
179 Array.Sort<ISensor>(sensors, CompareSensor);
180 foreach (ISensor sensor in sensors) {
181 if (sensor.Parameters.Length > 0) {
182 w.WriteLine("{0}| +- {1}[{2}] : {3}",
183 space, sensor.SensorType, sensor.Index, sensor.Name);
184 foreach (IParameter parameter in sensor.Parameters) {
185 w.WriteLine("{0}| +- {1} : {2}",
186 space, parameter.Name,
187 string.Format(CultureInfo.InvariantCulture, "{0} : {1}",
188 parameter.DefaultValue, parameter.Value));
192 foreach (IHardware subHardware in hardware.SubHardware)
193 ReportHardwareParameterTree(subHardware, w, "| ");
196 private void ReportHardware(IHardware hardware, TextWriter w) {
197 string hardwareReport = hardware.GetReport();
198 if (!string.IsNullOrEmpty(hardwareReport)) {
200 w.Write(hardwareReport);
202 foreach (IHardware subHardware in hardware.SubHardware)
203 ReportHardware(subHardware, w);
206 public string GetReport() {
208 using (StringWriter w = new StringWriter(CultureInfo.InvariantCulture)) {
211 w.WriteLine("Open Hardware Monitor Report");
214 Version version = typeof(Computer).Assembly.GetName().Version;
217 w.Write("Version: "); w.WriteLine(version.ToString());
221 w.Write("Common Language Runtime: ");
222 w.WriteLine(Environment.Version.ToString());
223 w.Write("Operating System: ");
224 w.WriteLine(Environment.OSVersion.ToString());
225 w.Write("Process Type: ");
226 w.WriteLine(IntPtr.Size == 4 ? "32-Bit" : "64-Bit");
230 w.WriteLine("Sensors");
232 foreach (IGroup group in groups) {
233 foreach (IHardware hardware in group.Hardware)
234 ReportHardwareSensorTree(hardware, w, "");
239 w.WriteLine("Parameters");
241 foreach (IGroup group in groups) {
242 foreach (IHardware hardware in group.Hardware)
243 ReportHardwareParameterTree(hardware, w, "");
247 foreach (IGroup group in groups) {
248 string report = group.GetReport();
249 if (!string.IsNullOrEmpty(report)) {
254 IHardware[] hardwareArray = group.Hardware;
255 foreach (IHardware hardware in hardwareArray)
256 ReportHardware(hardware, w);
263 public void Close() {
267 foreach (IGroup group in groups)
276 public event HardwareEventHandler HardwareAdded;
277 public event HardwareEventHandler HardwareRemoved;
279 public void Accept(IVisitor visitor) {
281 throw new ArgumentNullException("visitor");
282 visitor.VisitComputer(this);
285 public void Traverse(IVisitor visitor) {
286 foreach (IGroup group in groups)
287 foreach (IHardware hardware in group.Hardware)
288 hardware.Accept(visitor);
291 private class Settings : ISettings {
293 public bool Contains(string name) {
297 public void SetValue(string name, string value) { }
299 public string GetValue(string name, string value) {
303 public void Remove(string name) { }