Release version 0.1.6. Fixed F71882 temperature reading. Added error handling for ATI GPUs (ADL). Fixed sensor events.
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;
40 using System.ComponentModel;
41 using System.Configuration;
44 using System.Windows.Forms;
45 using Aga.Controls.Tree;
46 using Aga.Controls.Tree.NodeControls;
47 using OpenHardwareMonitor.Hardware;
49 namespace OpenHardwareMonitor.GUI {
50 public partial class MainForm : Form {
53 private List<IGroup> groupList = new List<IGroup>();
54 private TreeModel treeModel;
55 private IDictionary<ISensor, Color> sensorPlotColors =
56 new Dictionary<ISensor, Color>();
57 private Color[] plotColorPalette;
61 InitializeComponent();
62 this.Font = SystemFonts.MessageBoxFont;
63 treeView.Font = SystemFonts.MessageBoxFont;
64 plotPanel.Font = SystemFonts.MessageBoxFont;
66 nodeCheckBox.IsVisibleValueNeeded +=
67 new EventHandler<NodeControlValueEventArgs>(
68 nodeCheckBox_IsVisibleValueNeeded);
69 nodeCheckBox.CheckStateChanged +=
70 new EventHandler<TreePathEventArgs>(UpdatePlotSelection);
71 nodeTextBoxText.DrawText +=
72 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
73 nodeTextBoxValue.DrawText +=
74 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
75 nodeTextBoxMin.DrawText +=
76 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
77 nodeTextBoxMax.DrawText +=
78 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
79 nodeTextBoxLimit.DrawText +=
80 new EventHandler<DrawEventArgs>(nodeTextBoxLimit_DrawText);
82 if (Utilities.Config.Contains("mainForm.Location.X")) {
83 int x = Utilities.Config.Get("mainForm.Location.X", Location.X);
85 int y = Utilities.Config.Get("mainForm.Location.Y", Location.Y);
87 this.Location = new Point(x, y);
89 StartPosition = FormStartPosition.CenterScreen;
92 Width = Utilities.Config.Get("mainForm.Width", Width);
93 Height = Utilities.Config.Get("mainForm.Height", Height);
95 treeModel = new TreeModel();
96 root = new Node(System.Environment.MachineName);
97 root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
99 treeModel.Nodes.Add(root);
100 treeView.Model = treeModel;
102 AddGroup(new Hardware.SMBIOS.SMBIOSGroup());
103 AddGroup(new Hardware.LPC.LPCGroup());
104 AddGroup(new Hardware.CPU.CPUGroup());
105 AddGroup(new Hardware.ATI.ATIGroup());
106 AddGroup(new Hardware.Nvidia.NvidiaGroup());
107 AddGroup(new Hardware.TBalancer.TBalancerGroup());
109 plotColorPalette = new Color[14];
110 plotColorPalette[0] = Color.Blue;
111 plotColorPalette[1] = Color.OrangeRed;
112 plotColorPalette[2] = Color.Green;
113 plotColorPalette[3] = Color.LightSeaGreen;
114 plotColorPalette[4] = Color.Goldenrod;
115 plotColorPalette[5] = Color.DarkViolet;
116 plotColorPalette[6] = Color.YellowGreen;
117 plotColorPalette[7] = Color.SaddleBrown;
118 plotColorPalette[8] = Color.Gray;
119 plotColorPalette[9] = Color.RoyalBlue;
120 plotColorPalette[10] = Color.DeepPink;
121 plotColorPalette[11] = Color.MediumSeaGreen;
122 plotColorPalette[12] = Color.Olive;
123 plotColorPalette[13] = Color.Firebrick;
125 plotMenuItem.Checked = Utilities.Config.Get(plotMenuItem.Name, false);
126 minMenuItem.Checked = Utilities.Config.Get(minMenuItem.Name, false);
127 maxMenuItem.Checked = Utilities.Config.Get(maxMenuItem.Name, true);
128 limitMenuItem.Checked = Utilities.Config.Get(limitMenuItem.Name, false);
129 hddMenuItem.Checked = Utilities.Config.Get(hddMenuItem.Name, true);
131 voltMenuItem.Checked = Utilities.Config.Get(voltMenuItem.Name, true);
132 clocksMenuItem.Checked = Utilities.Config.Get(clocksMenuItem.Name, true);
133 tempMenuItem.Checked = Utilities.Config.Get(tempMenuItem.Name, true);
134 fansMenuItem.Checked = Utilities.Config.Get(fansMenuItem.Name, true);
136 timer.Enabled = true;
139 private void AddGroup(IGroup group) {
140 groupList.Add(group);
141 foreach (IHardware hardware in group.Hardware)
142 root.Nodes.Add(new HardwareNode(hardware));
145 private void RemoveGroup(IGroup group) {
146 List<Node> nodesToRemove = new List<Node>();
147 foreach (IHardware hardware in group.Hardware)
148 foreach (Node node in root.Nodes) {
149 HardwareNode hardwareNode = node as HardwareNode;
150 if (hardwareNode != null && hardwareNode.Hardware == hardware)
151 nodesToRemove.Add(node);
153 foreach (Node node in nodesToRemove)
154 root.Nodes.Remove(node);
155 groupList.Remove(group);
158 private void nodeTextBoxLimit_DrawText(object sender, DrawEventArgs e) {
159 SensorNode sensorNode = e.Node.Tag as SensorNode;
160 if (sensorNode != null)
161 e.Text = sensorNode.ValueToString(sensorNode.Sensor.Limit);
164 private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {
165 if (!plotMenuItem.Checked)
168 SensorNode sensorNode = e.Node.Tag as SensorNode;
169 if (sensorNode != null) {
171 if (sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
176 private void UpdatePlotSelection(object sender,
179 List<ISensor> selected = new List<ISensor>();
180 IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
182 foreach (TreeNodeAdv node in treeView.AllNodes) {
183 SensorNode sensorNode = node.Tag as SensorNode;
184 if (sensorNode != null &&
185 sensorNode.Sensor.SensorType == SensorType.Temperature) {
186 if (sensorNode.Plot) {
187 colors.Add(sensorNode.Sensor,
188 plotColorPalette[colorIndex % plotColorPalette.Length]);
189 selected.Add(sensorNode.Sensor);
194 sensorPlotColors = colors;
195 plotPanel.SetSensors(selected, colors);
198 private void nodeCheckBox_IsVisibleValueNeeded(object sender,
199 NodeControlValueEventArgs e) {
200 SensorNode node = e.Node.Tag as SensorNode;
201 e.Value = (node != null) &&
202 (node.Sensor.SensorType == SensorType.Temperature) &&
203 plotMenuItem.Checked;
206 private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
210 private void timer_Tick(object sender, EventArgs e) {
215 foreach (IGroup group in groupList)
216 foreach (IHardware hardware in group.Hardware)
219 } catch (Exception exception) {
220 Utilities.CrashReport.Save(exception);
225 treeView.Invalidate();
226 plotPanel.Invalidate();
229 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
230 Utilities.Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
231 Utilities.Config.Set(minMenuItem.Name, minMenuItem.Checked);
232 Utilities.Config.Set(maxMenuItem.Name, maxMenuItem.Checked);
233 Utilities.Config.Set(limitMenuItem.Name, limitMenuItem.Checked);
234 Utilities.Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
236 Utilities.Config.Set(voltMenuItem.Name, voltMenuItem.Checked);
237 Utilities.Config.Set(clocksMenuItem.Name, clocksMenuItem.Checked);
238 Utilities.Config.Set(tempMenuItem.Name, tempMenuItem.Checked);
239 Utilities.Config.Set(fansMenuItem.Name, fansMenuItem.Checked);
241 if (WindowState != FormWindowState.Minimized) {
242 Utilities.Config.Set("mainForm.Location.X", Location.X);
243 Utilities.Config.Set("mainForm.Location.Y", Location.Y);
244 Utilities.Config.Set("mainForm.Width", Width);
245 Utilities.Config.Set("mainForm.Height", Height);
248 foreach (IGroup group in groupList)
252 private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
253 new AboutBox().ShowDialog();
256 private void plotToolStripMenuItem_CheckedChanged(object sender,
259 splitContainer.Panel2Collapsed = !plotMenuItem.Checked;
260 treeView.Invalidate();
263 private void valueToolStripMenuItem_CheckedChanged(object sender,
266 treeView.Columns[1].IsVisible = valueToolStripMenuItem.Checked;
269 private void minToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
271 treeView.Columns[2].IsVisible = minMenuItem.Checked;
274 private void maxToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
276 treeView.Columns[3].IsVisible = maxMenuItem.Checked;
279 private void limitToolStripMenuItem_CheckedChanged(object sender,
281 treeView.Columns[4].IsVisible = limitMenuItem.Checked;
284 private void treeView_Click(object sender, EventArgs e) {
286 MouseEventArgs m = e as MouseEventArgs;
287 if (m == null || m.Button != MouseButtons.Right)
290 NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
291 if (info.Control == null)
292 columnsContextMenuStrip.Show(treeView, m.X, m.Y);
295 private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
296 ReportWriter.Save(groupList, new Version(Application.ProductVersion));
299 private void hddsensorsToolStripMenuItem_CheckedChanged(object sender,
302 if (hddMenuItem.Checked) {
303 AddGroup(new Hardware.HDD.HDDGroup());
304 UpdateSensorTypeChecked(null, null);
306 List<IGroup> groupsToRemove = new List<IGroup>();
307 foreach (IGroup group in groupList)
308 if (group is Hardware.HDD.HDDGroup)
309 groupsToRemove.Add(group);
310 foreach (IGroup group in groupsToRemove) {
314 UpdatePlotSelection(null, null);
318 private void UpdateSensorTypeChecked(object sender, EventArgs e) {
319 foreach (HardwareNode node in root.Nodes) {
320 node.SetVisible(SensorType.Voltage, voltMenuItem.Checked);
321 node.SetVisible(SensorType.Clock, clocksMenuItem.Checked);
322 node.SetVisible(SensorType.Temperature, tempMenuItem.Checked);
323 node.SetVisible(SensorType.Fan, fansMenuItem.Checked);