Refactoring: New class Computer manages all the hardware and creates events.
1.1 --- a/GUI/MainForm.Designer.cs Fri Feb 05 22:45:15 2010 +0000
1.2 +++ b/GUI/MainForm.Designer.cs Sun Feb 07 16:37:15 2010 +0000
1.3 @@ -94,6 +94,8 @@
1.4 this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
1.5 this.plotMenuItem = new System.Windows.Forms.ToolStripMenuItem();
1.6 this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
1.7 + this.minTrayMenuItem = new System.Windows.Forms.ToolStripMenuItem();
1.8 + this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripSeparator();
1.9 this.hddMenuItem = new System.Windows.Forms.ToolStripMenuItem();
1.10 this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
1.11 this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
1.12 @@ -409,16 +411,32 @@
1.13 // optionsToolStripMenuItem
1.14 //
1.15 this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
1.16 + this.minTrayMenuItem,
1.17 + this.toolStripMenuItem3,
1.18 this.hddMenuItem});
1.19 this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
1.20 this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
1.21 this.optionsToolStripMenuItem.Text = "Options";
1.22 //
1.23 + // minTrayMenuItem
1.24 + //
1.25 + this.minTrayMenuItem.Checked = true;
1.26 + this.minTrayMenuItem.CheckOnClick = true;
1.27 + this.minTrayMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
1.28 + this.minTrayMenuItem.Name = "minTrayMenuItem";
1.29 + this.minTrayMenuItem.Size = new System.Drawing.Size(166, 22);
1.30 + this.minTrayMenuItem.Text = "Minimize To Tray";
1.31 + //
1.32 + // toolStripMenuItem3
1.33 + //
1.34 + this.toolStripMenuItem3.Name = "toolStripMenuItem3";
1.35 + this.toolStripMenuItem3.Size = new System.Drawing.Size(163, 6);
1.36 + //
1.37 // hddMenuItem
1.38 //
1.39 this.hddMenuItem.CheckOnClick = true;
1.40 this.hddMenuItem.Name = "hddMenuItem";
1.41 - this.hddMenuItem.Size = new System.Drawing.Size(141, 22);
1.42 + this.hddMenuItem.Size = new System.Drawing.Size(166, 22);
1.43 this.hddMenuItem.Text = "HDD sensors";
1.44 this.hddMenuItem.CheckedChanged += new System.EventHandler(this.hddsensorsToolStripMenuItem_CheckedChanged);
1.45 //
1.46 @@ -477,7 +495,7 @@
1.47 this.notifyIcon.ContextMenuStrip = this.notifyContextMenuStrip;
1.48 this.notifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon.Icon")));
1.49 this.notifyIcon.Text = "Open Hardware Monitor";
1.50 - this.notifyIcon.Click += new System.EventHandler(this.notifyIcon_Click);
1.51 + this.notifyIcon.DoubleClick += new System.EventHandler(this.restoreClick);
1.52 //
1.53 // notifyContextMenuStrip
1.54 //
1.55 @@ -486,25 +504,25 @@
1.56 this.toolStripMenuItem2,
1.57 this.exitToolStripMenuItem1});
1.58 this.notifyContextMenuStrip.Name = "notifyContextMenuStrip";
1.59 - this.notifyContextMenuStrip.Size = new System.Drawing.Size(153, 76);
1.60 + this.notifyContextMenuStrip.Size = new System.Drawing.Size(119, 54);
1.61 //
1.62 // restoreToolStripMenuItem
1.63 //
1.64 - this.restoreToolStripMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F);
1.65 + this.restoreToolStripMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
1.66 this.restoreToolStripMenuItem.Name = "restoreToolStripMenuItem";
1.67 - this.restoreToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
1.68 + this.restoreToolStripMenuItem.Size = new System.Drawing.Size(118, 22);
1.69 this.restoreToolStripMenuItem.Text = "Restore";
1.70 - this.restoreToolStripMenuItem.Click += new System.EventHandler(this.restoreToolStripMenuItem_Click);
1.71 + this.restoreToolStripMenuItem.Click += new System.EventHandler(this.restoreClick);
1.72 //
1.73 // toolStripMenuItem2
1.74 //
1.75 this.toolStripMenuItem2.Name = "toolStripMenuItem2";
1.76 - this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
1.77 + this.toolStripMenuItem2.Size = new System.Drawing.Size(115, 6);
1.78 //
1.79 // exitToolStripMenuItem1
1.80 //
1.81 this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
1.82 - this.exitToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
1.83 + this.exitToolStripMenuItem1.Size = new System.Drawing.Size(118, 22);
1.84 this.exitToolStripMenuItem1.Text = "Exit";
1.85 this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
1.86 //
1.87 @@ -579,6 +597,8 @@
1.88 private System.Windows.Forms.ToolStripMenuItem restoreToolStripMenuItem;
1.89 private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
1.90 private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem1;
1.91 + private System.Windows.Forms.ToolStripMenuItem minTrayMenuItem;
1.92 + private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3;
1.93 }
1.94 }
1.95
2.1 --- a/GUI/MainForm.cs Fri Feb 05 22:45:15 2010 +0000
2.2 +++ b/GUI/MainForm.cs Sun Feb 07 16:37:15 2010 +0000
2.3 @@ -45,19 +45,19 @@
2.4 using Aga.Controls.Tree;
2.5 using Aga.Controls.Tree.NodeControls;
2.6 using OpenHardwareMonitor.Hardware;
2.7 +using OpenHardwareMonitor.Utilities;
2.8
2.9 namespace OpenHardwareMonitor.GUI {
2.10 public partial class MainForm : Form {
2.11
2.12 + private Computer computer = new Computer();
2.13 private Node root;
2.14 - private List<IGroup> groupList = new List<IGroup>();
2.15 private TreeModel treeModel;
2.16 private IDictionary<ISensor, Color> sensorPlotColors =
2.17 new Dictionary<ISensor, Color>();
2.18 private Color[] plotColorPalette;
2.19
2.20 - public MainForm() {
2.21 -
2.22 + public MainForm() {
2.23 InitializeComponent();
2.24 this.Font = SystemFonts.MessageBoxFont;
2.25 treeView.Font = SystemFonts.MessageBoxFont;
2.26 @@ -99,13 +99,10 @@
2.27 treeModel.Nodes.Add(root);
2.28 treeView.Model = treeModel;
2.29
2.30 - AddGroup(new Hardware.SMBIOS.SMBIOSGroup());
2.31 - AddGroup(new Hardware.LPC.LPCGroup());
2.32 - AddGroup(new Hardware.CPU.CPUGroup());
2.33 - AddGroup(new Hardware.ATI.ATIGroup());
2.34 - AddGroup(new Hardware.Nvidia.NvidiaGroup());
2.35 - AddGroup(new Hardware.TBalancer.TBalancerGroup());
2.36 -
2.37 + computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
2.38 + computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
2.39 + computer.Open();
2.40 +
2.41 plotColorPalette = new Color[14];
2.42 plotColorPalette[0] = Color.Blue;
2.43 plotColorPalette[1] = Color.OrangeRed;
2.44 @@ -122,38 +119,36 @@
2.45 plotColorPalette[12] = Color.Olive;
2.46 plotColorPalette[13] = Color.Firebrick;
2.47
2.48 - plotMenuItem.Checked = Utilities.Config.Get(plotMenuItem.Name, false);
2.49 - minMenuItem.Checked = Utilities.Config.Get(minMenuItem.Name, false);
2.50 - maxMenuItem.Checked = Utilities.Config.Get(maxMenuItem.Name, true);
2.51 - limitMenuItem.Checked = Utilities.Config.Get(limitMenuItem.Name, false);
2.52 - hddMenuItem.Checked = Utilities.Config.Get(hddMenuItem.Name, true);
2.53 + plotMenuItem.Checked = Config.Get(plotMenuItem.Name, false);
2.54 + minMenuItem.Checked = Config.Get(minMenuItem.Name, false);
2.55 + maxMenuItem.Checked = Config.Get(maxMenuItem.Name, true);
2.56 + limitMenuItem.Checked = Config.Get(limitMenuItem.Name, false);
2.57
2.58 - voltMenuItem.Checked = Utilities.Config.Get(voltMenuItem.Name, true);
2.59 - clocksMenuItem.Checked = Utilities.Config.Get(clocksMenuItem.Name, true);
2.60 - loadMenuItem.Checked = Utilities.Config.Get(loadMenuItem.Name, true);
2.61 - tempMenuItem.Checked = Utilities.Config.Get(tempMenuItem.Name, true);
2.62 - fansMenuItem.Checked = Utilities.Config.Get(fansMenuItem.Name, true);
2.63 + minTrayMenuItem.Checked = Config.Get(minTrayMenuItem.Name, true);
2.64 + hddMenuItem.Checked = Config.Get(hddMenuItem.Name, true);
2.65
2.66 - timer.Enabled = true;
2.67 + voltMenuItem.Checked = Config.Get(voltMenuItem.Name, true);
2.68 + clocksMenuItem.Checked = Config.Get(clocksMenuItem.Name, true);
2.69 + loadMenuItem.Checked = Config.Get(loadMenuItem.Name, true);
2.70 + tempMenuItem.Checked = Config.Get(tempMenuItem.Name, true);
2.71 + fansMenuItem.Checked = Config.Get(fansMenuItem.Name, true);
2.72 +
2.73 + timer.Enabled = true;
2.74 }
2.75
2.76 - private void AddGroup(IGroup group) {
2.77 - groupList.Add(group);
2.78 - foreach (IHardware hardware in group.Hardware)
2.79 - root.Nodes.Add(new HardwareNode(hardware));
2.80 + private void HardwareAdded(IHardware hardware) {
2.81 + root.Nodes.Add(new HardwareNode(hardware));
2.82 }
2.83
2.84 - private void RemoveGroup(IGroup group) {
2.85 + private void HardwareRemoved(IHardware hardware) {
2.86 List<Node> nodesToRemove = new List<Node>();
2.87 - foreach (IHardware hardware in group.Hardware)
2.88 - foreach (Node node in root.Nodes) {
2.89 - HardwareNode hardwareNode = node as HardwareNode;
2.90 - if (hardwareNode != null && hardwareNode.Hardware == hardware)
2.91 - nodesToRemove.Add(node);
2.92 - }
2.93 + foreach (Node node in root.Nodes) {
2.94 + HardwareNode hardwareNode = node as HardwareNode;
2.95 + if (hardwareNode != null && hardwareNode.Hardware == hardware)
2.96 + nodesToRemove.Add(node);
2.97 + }
2.98 foreach (Node node in nodesToRemove)
2.99 root.Nodes.Remove(node);
2.100 - groupList.Remove(group);
2.101 }
2.102
2.103 private void nodeTextBoxLimit_DrawText(object sender, DrawEventArgs e) {
2.104 @@ -213,12 +208,10 @@
2.105 #if !DEBUG
2.106 try {
2.107 #endif
2.108 - foreach (IGroup group in groupList)
2.109 - foreach (IHardware hardware in group.Hardware)
2.110 - hardware.Update();
2.111 + computer.Update();
2.112 #if !DEBUG
2.113 } catch (Exception exception) {
2.114 - Utilities.CrashReport.Save(exception);
2.115 + CrashReport.Save(exception);
2.116 Close();
2.117 }
2.118 #endif
2.119 @@ -228,27 +221,29 @@
2.120 }
2.121
2.122 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
2.123 - Utilities.Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
2.124 - Utilities.Config.Set(minMenuItem.Name, minMenuItem.Checked);
2.125 - Utilities.Config.Set(maxMenuItem.Name, maxMenuItem.Checked);
2.126 - Utilities.Config.Set(limitMenuItem.Name, limitMenuItem.Checked);
2.127 - Utilities.Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
2.128 +
2.129 + Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
2.130 + Config.Set(minMenuItem.Name, minMenuItem.Checked);
2.131 + Config.Set(maxMenuItem.Name, maxMenuItem.Checked);
2.132 + Config.Set(limitMenuItem.Name, limitMenuItem.Checked);
2.133
2.134 - Utilities.Config.Set(voltMenuItem.Name, voltMenuItem.Checked);
2.135 - Utilities.Config.Set(clocksMenuItem.Name, clocksMenuItem.Checked);
2.136 - Utilities.Config.Set(loadMenuItem.Name, loadMenuItem.Checked);
2.137 - Utilities.Config.Set(tempMenuItem.Name, tempMenuItem.Checked);
2.138 - Utilities.Config.Set(fansMenuItem.Name, fansMenuItem.Checked);
2.139 + Config.Set(minTrayMenuItem.Name, minTrayMenuItem.Checked);
2.140 + Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
2.141 +
2.142 + Config.Set(voltMenuItem.Name, voltMenuItem.Checked);
2.143 + Config.Set(clocksMenuItem.Name, clocksMenuItem.Checked);
2.144 + Config.Set(loadMenuItem.Name, loadMenuItem.Checked);
2.145 + Config.Set(tempMenuItem.Name, tempMenuItem.Checked);
2.146 + Config.Set(fansMenuItem.Name, fansMenuItem.Checked);
2.147
2.148 if (WindowState != FormWindowState.Minimized) {
2.149 - Utilities.Config.Set("mainForm.Location.X", Location.X);
2.150 - Utilities.Config.Set("mainForm.Location.Y", Location.Y);
2.151 - Utilities.Config.Set("mainForm.Width", Width);
2.152 - Utilities.Config.Set("mainForm.Height", Height);
2.153 + Config.Set("mainForm.Location.X", Location.X);
2.154 + Config.Set("mainForm.Location.Y", Location.Y);
2.155 + Config.Set("mainForm.Width", Width);
2.156 + Config.Set("mainForm.Height", Height);
2.157 }
2.158
2.159 - foreach (IGroup group in groupList)
2.160 - group.Close();
2.161 + computer.Close();
2.162 }
2.163
2.164 private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
2.165 @@ -290,31 +285,21 @@
2.166 return;
2.167
2.168 NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
2.169 - if (info.Control == null)
2.170 + if (info.Control == null) {
2.171 columnsContextMenuStrip.Show(treeView, m.X, m.Y);
2.172 + }
2.173 }
2.174
2.175 private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
2.176 - ReportWriter.Save(groupList, new Version(Application.ProductVersion));
2.177 + computer.SaveReport(new Version(Application.ProductVersion));
2.178 }
2.179
2.180 private void hddsensorsToolStripMenuItem_CheckedChanged(object sender,
2.181 EventArgs e)
2.182 {
2.183 - if (hddMenuItem.Checked) {
2.184 - AddGroup(new Hardware.HDD.HDDGroup());
2.185 - UpdateSensorTypeChecked(null, null);
2.186 - } else {
2.187 - List<IGroup> groupsToRemove = new List<IGroup>();
2.188 - foreach (IGroup group in groupList)
2.189 - if (group is Hardware.HDD.HDDGroup)
2.190 - groupsToRemove.Add(group);
2.191 - foreach (IGroup group in groupsToRemove) {
2.192 - group.Close();
2.193 - RemoveGroup(group);
2.194 - }
2.195 - UpdatePlotSelection(null, null);
2.196 - }
2.197 + computer.HDDEnabled = hddMenuItem.Checked;
2.198 + UpdateSensorTypeChecked(null, null);
2.199 + UpdatePlotSelection(null, null);
2.200 }
2.201
2.202 private void UpdateSensorTypeChecked(object sender, EventArgs e) {
2.203 @@ -334,29 +319,24 @@
2.204 } else {
2.205 Visible = true;
2.206 notifyIcon.Visible = false;
2.207 + BringToFront();
2.208 }
2.209 }
2.210
2.211 protected override void WndProc(ref Message m) {
2.212 const int WM_SYSCOMMAND = 0x112;
2.213 const int SC_MINIMIZE = 0xF020;
2.214 - if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
2.215 + if (minTrayMenuItem.Checked &&
2.216 + m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
2.217 ToggleSysTray();
2.218 } else {
2.219 base.WndProc(ref m);
2.220 }
2.221 }
2.222
2.223 - private void notifyIcon_Click(object sender, EventArgs e) {
2.224 - MouseEventArgs m = e as MouseEventArgs;
2.225 - if (m == null || m.Button != MouseButtons.Left)
2.226 - return;
2.227 -
2.228 - ToggleSysTray();
2.229 + private void restoreClick(object sender, EventArgs e) {
2.230 + ToggleSysTray();
2.231 }
2.232
2.233 - private void restoreToolStripMenuItem_Click(object sender, EventArgs e) {
2.234 - ToggleSysTray();
2.235 - }
2.236 }
2.237 }
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/Hardware/Computer.cs Sun Feb 07 16:37:15 2010 +0000
3.3 @@ -0,0 +1,197 @@
3.4 +/*
3.5 +
3.6 + Version: MPL 1.1/GPL 2.0/LGPL 2.1
3.7 +
3.8 + The contents of this file are subject to the Mozilla Public License Version
3.9 + 1.1 (the "License"); you may not use this file except in compliance with
3.10 + the License. You may obtain a copy of the License at
3.11 +
3.12 + http://www.mozilla.org/MPL/
3.13 +
3.14 + Software distributed under the License is distributed on an "AS IS" basis,
3.15 + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
3.16 + for the specific language governing rights and limitations under the License.
3.17 +
3.18 + The Original Code is the Open Hardware Monitor code.
3.19 +
3.20 + The Initial Developer of the Original Code is
3.21 + Michael Möller <m.moeller@gmx.ch>.
3.22 + Portions created by the Initial Developer are Copyright (C) 2009-2010
3.23 + the Initial Developer. All Rights Reserved.
3.24 +
3.25 + Contributor(s):
3.26 +
3.27 + Alternatively, the contents of this file may be used under the terms of
3.28 + either the GNU General Public License Version 2 or later (the "GPL"), or
3.29 + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
3.30 + in which case the provisions of the GPL or the LGPL are applicable instead
3.31 + of those above. If you wish to allow use of your version of this file only
3.32 + under the terms of either the GPL or the LGPL, and not to allow others to
3.33 + use your version of this file under the terms of the MPL, indicate your
3.34 + decision by deleting the provisions above and replace them with the notice
3.35 + and other provisions required by the GPL or the LGPL. If you do not delete
3.36 + the provisions above, a recipient may use your version of this file under
3.37 + the terms of any one of the MPL, the GPL or the LGPL.
3.38 +
3.39 +*/
3.40 +
3.41 +using System;
3.42 +using System.Collections.Generic;
3.43 +using System.IO;
3.44 +using System.Text;
3.45 +
3.46 +namespace OpenHardwareMonitor.Hardware {
3.47 +
3.48 + public delegate void HardwareEventHandler(IHardware hardware);
3.49 +
3.50 + public class Computer {
3.51 +
3.52 + private List<IGroup> groups = new List<IGroup>();
3.53 +
3.54 + private bool open = false;
3.55 + private bool hddEnabled = false;
3.56 +
3.57 + public Computer() { }
3.58 +
3.59 + private void Add(IGroup group) {
3.60 + if (groups.Contains(group))
3.61 + return;
3.62 +
3.63 + groups.Add(group);
3.64 +
3.65 + if (HardwareAdded != null)
3.66 + foreach (IHardware hardware in group.Hardware)
3.67 + HardwareAdded(hardware);
3.68 + }
3.69 +
3.70 + private void Remove(IGroup group) {
3.71 + if (!groups.Contains(group))
3.72 + return;
3.73 +
3.74 + groups.Remove(group);
3.75 +
3.76 + if (HardwareRemoved != null)
3.77 + foreach (IHardware hardware in group.Hardware)
3.78 + HardwareRemoved(hardware);
3.79 + }
3.80 +
3.81 + public void Open() {
3.82 + if (open)
3.83 + return;
3.84 +
3.85 + Add(new SMBIOS.SMBIOSGroup());
3.86 + Add(new LPC.LPCGroup());
3.87 + Add(new CPU.CPUGroup());
3.88 + Add(new ATI.ATIGroup());
3.89 + Add(new Nvidia.NvidiaGroup());
3.90 + Add(new TBalancer.TBalancerGroup());
3.91 +
3.92 + if (hddEnabled)
3.93 + Add(new HDD.HDDGroup());
3.94 +
3.95 + open = true;
3.96 + }
3.97 +
3.98 + public void Update() {
3.99 + foreach (IGroup group in groups)
3.100 + foreach (IHardware hardware in group.Hardware)
3.101 + hardware.Update();
3.102 + }
3.103 +
3.104 + public bool HDDEnabled {
3.105 + get { return hddEnabled; }
3.106 + set {
3.107 + if (open && value && !hddEnabled) {
3.108 + Add(new HDD.HDDGroup());
3.109 + } else if (open && !value && hddEnabled) {
3.110 + List<IGroup> list = new List<IGroup>();
3.111 + foreach (IGroup group in groups)
3.112 + if (group is HDD.HDDGroup)
3.113 + list.Add(group);
3.114 + foreach (IGroup group in list)
3.115 + Remove(group);
3.116 + }
3.117 + hddEnabled = value;
3.118 + }
3.119 + }
3.120 +
3.121 + public IEnumerable<IHardware> Hardware {
3.122 + get {
3.123 + foreach (IGroup group in groups)
3.124 + foreach (IHardware hardware in group.Hardware)
3.125 + yield return hardware;
3.126 + }
3.127 + }
3.128 +
3.129 + private void NewSection(TextWriter writer) {
3.130 + for (int i = 0; i < 8; i++)
3.131 + writer.Write("----------");
3.132 + writer.WriteLine();
3.133 + writer.WriteLine();
3.134 + }
3.135 +
3.136 + public void SaveReport(Version version) {
3.137 +
3.138 + using (TextWriter w =
3.139 + new StreamWriter("OpenHardwareMonitor.Report.txt")) {
3.140 +
3.141 + w.WriteLine();
3.142 + w.WriteLine("Open Hardware Monitor Report");
3.143 + w.WriteLine();
3.144 +
3.145 + NewSection(w);
3.146 + w.Write("Version: "); w.WriteLine(version.ToString());
3.147 + w.WriteLine();
3.148 +
3.149 + NewSection(w);
3.150 + foreach (IGroup group in groups) {
3.151 + foreach (IHardware hardware in group.Hardware) {
3.152 + w.WriteLine("|");
3.153 + w.WriteLine("+-+ {0} ({1})",
3.154 + new object[] { hardware.Name, hardware.Identifier });
3.155 + foreach (ISensor sensor in hardware.Sensors) {
3.156 + w.WriteLine("| +- {0} : {1} : {2} : {3}",
3.157 + new object[] { sensor.SensorType, sensor.Index, sensor.Name,
3.158 + sensor.Value });
3.159 + }
3.160 + }
3.161 + }
3.162 + w.WriteLine();
3.163 +
3.164 + foreach (IGroup group in groups) {
3.165 + string report = group.GetReport();
3.166 + if (report != null) {
3.167 + NewSection(w);
3.168 + w.Write(report);
3.169 + }
3.170 +
3.171 + IHardware[] hardwareArray = group.Hardware;
3.172 + foreach (IHardware hardware in hardwareArray) {
3.173 + string hardwareReport = hardware.GetReport();
3.174 + if (hardwareReport != null) {
3.175 + NewSection(w);
3.176 + w.Write(hardwareReport);
3.177 + }
3.178 + }
3.179 + }
3.180 + }
3.181 + }
3.182 +
3.183 + public void Close() {
3.184 + if (!open)
3.185 + return;
3.186 +
3.187 + foreach (IGroup group in groups)
3.188 + group.Close();
3.189 + groups.Clear();
3.190 +
3.191 + open = false;
3.192 + }
3.193 +
3.194 + public event HardwareEventHandler HardwareAdded;
3.195 + public event HardwareEventHandler HardwareRemoved;
3.196 +
3.197 +
3.198 +
3.199 + }
3.200 +}
4.1 --- a/Hardware/ISensor.cs Fri Feb 05 22:45:15 2010 +0000
4.2 +++ b/Hardware/ISensor.cs Sun Feb 07 16:37:15 2010 +0000
4.3 @@ -54,7 +54,9 @@
4.4 }
4.5
4.6 public interface ISensor {
4.7 + IHardware Hardware { get; }
4.8 SensorType SensorType { get; }
4.9 + string Identifier { get; }
4.10 string Name { get; set; }
4.11 int Index { get; }
4.12 float? Value { get; }
5.1 --- a/Hardware/ReportWriter.cs Fri Feb 05 22:45:15 2010 +0000
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,63 +0,0 @@
5.4 -using System;
5.5 -using System.Collections.Generic;
5.6 -using System.IO;
5.7 -using System.Text;
5.8 -
5.9 -namespace OpenHardwareMonitor.Hardware {
5.10 - public class ReportWriter {
5.11 -
5.12 - private static void NewSection(TextWriter writer) {
5.13 - for (int i = 0; i < 8; i++)
5.14 - writer.Write("----------");
5.15 - writer.WriteLine();
5.16 - writer.WriteLine();
5.17 - }
5.18 -
5.19 - public static void Save(List<IGroup> groupList, Version version) {
5.20 -
5.21 - using (TextWriter w =
5.22 - new StreamWriter("OpenHardwareMonitor.Report.txt")) {
5.23 -
5.24 - w.WriteLine();
5.25 - w.WriteLine("Open Hardware Monitor Report");
5.26 - w.WriteLine();
5.27 -
5.28 - NewSection(w);
5.29 - w.Write("Version: "); w.WriteLine(version.ToString());
5.30 - w.WriteLine();
5.31 -
5.32 - NewSection(w);
5.33 - foreach (IGroup group in groupList) {
5.34 - foreach (IHardware hardware in group.Hardware) {
5.35 - w.WriteLine("|");
5.36 - w.WriteLine("+-+ {0} ({1})",
5.37 - new object[] { hardware.Name, hardware.Identifier });
5.38 - foreach (ISensor sensor in hardware.Sensors) {
5.39 - w.WriteLine("| +- {0} : {1} : {2} : {3}",
5.40 - new object[] { sensor.SensorType, sensor.Index, sensor.Name,
5.41 - sensor.Value });
5.42 - }
5.43 - }
5.44 - }
5.45 - w.WriteLine();
5.46 -
5.47 - foreach (IGroup group in groupList) {
5.48 - string report = group.GetReport();
5.49 - if (report != null) {
5.50 - NewSection(w);
5.51 - w.Write(report);
5.52 - }
5.53 -
5.54 - IHardware[] hardwareArray = group.Hardware;
5.55 - foreach (IHardware hardware in hardwareArray) {
5.56 - string hardwareReport = hardware.GetReport();
5.57 - if (hardwareReport != null) {
5.58 - NewSection(w);
5.59 - w.Write(hardwareReport);
5.60 - }
5.61 - }
5.62 - }
5.63 - }
5.64 - }
5.65 - }
5.66 -}
6.1 --- a/Hardware/Sensor.cs Fri Feb 05 22:45:15 2010 +0000
6.2 +++ b/Hardware/Sensor.cs Sun Feb 07 16:37:15 2010 +0000
6.3 @@ -59,12 +59,7 @@
6.4 private int count = 0;
6.5
6.6 private const int MAX_MINUTES = 120;
6.7 -
6.8 - private string GetIdentifier() {
6.9 - return hardware.Identifier + "/" + sensorType.ToString().ToLower() +
6.10 - "/" + index;
6.11 - }
6.12 -
6.13 +
6.14 public Sensor(string name, int index, SensorType sensorType,
6.15 IHardware hardware)
6.16 : this(name, index, null, sensorType, hardware) { }
6.17 @@ -77,24 +72,35 @@
6.18 this.defaultLimit = limit;
6.19 this.sensorType = sensorType;
6.20 this.hardware = hardware;
6.21 - string configName =
6.22 - Utilities.Config.Settings[GetIdentifier() + "/name"];
6.23 + string configName =
6.24 + Utilities.Config.Settings[Identifier + "/name"];
6.25 if (configName != null)
6.26 this.name = configName;
6.27 else
6.28 this.name = name;
6.29 string configLimit =
6.30 - Utilities.Config.Settings[GetIdentifier() + "/limit"];
6.31 + Utilities.Config.Settings[Identifier + "/limit"];
6.32 if (configLimit != null && configLimit != "")
6.33 this.limit = float.Parse(configLimit);
6.34 else
6.35 this.limit = limit;
6.36 }
6.37
6.38 + public IHardware Hardware {
6.39 + get { return hardware; }
6.40 + }
6.41 +
6.42 public SensorType SensorType {
6.43 get { return sensorType; }
6.44 }
6.45
6.46 + public string Identifier {
6.47 + get {
6.48 + return hardware.Identifier + "/" + sensorType.ToString().ToLower() +
6.49 + "/" + index;
6.50 + }
6.51 + }
6.52 +
6.53 public string Name {
6.54 get {
6.55 return name;
6.56 @@ -104,7 +110,7 @@
6.57 name = value;
6.58 else
6.59 name = defaultName;
6.60 - Utilities.Config.Settings[GetIdentifier() + "/name"] = name;
6.61 + Utilities.Config.Settings[Identifier + "/name"] = name;
6.62 }
6.63 }
6.64
6.65 @@ -150,11 +156,11 @@
6.66 set {
6.67 if (value.HasValue) {
6.68 limit = value;
6.69 - Utilities.Config.Settings[GetIdentifier() + "/limit"] =
6.70 + Utilities.Config.Settings[Identifier + "/limit"] =
6.71 limit.ToString();
6.72 } else {
6.73 limit = defaultLimit;
6.74 - Utilities.Config.Settings[GetIdentifier() + "/limit"] = "";
6.75 + Utilities.Config.Settings[Identifier + "/limit"] = "";
6.76 }
6.77 }
6.78 }
7.1 --- a/OpenHardwareMonitor.csproj Fri Feb 05 22:45:15 2010 +0000
7.2 +++ b/OpenHardwareMonitor.csproj Sun Feb 07 16:37:15 2010 +0000
7.3 @@ -69,7 +69,7 @@
7.4 <Compile Include="Hardware\LPC\F718XX.cs" />
7.5 <Compile Include="Hardware\SMBIOS\SMBIOSGroup.cs" />
7.6 <Compile Include="Hardware\LPC\W83627DHG.cs" />
7.7 - <Compile Include="Hardware\ReportWriter.cs" />
7.8 + <Compile Include="Hardware\Computer.cs" />
7.9 <Compile Include="Properties\AssemblyInfo.cs" />
7.10 <Compile Include="GUI\AboutBox.cs">
7.11 <SubType>Form</SubType>
7.12 @@ -80,6 +80,7 @@
7.13 <Compile Include="Hardware\ATI\ADL.cs" />
7.14 <Compile Include="Hardware\ATI\ATIGroup.cs" />
7.15 <Compile Include="Hardware\ATI\ATIGPU.cs" />
7.16 + <Compile Include="Utilities\IconFactory.cs" />
7.17 <Compile Include="Utilities\Configuration.cs" />
7.18 <Compile Include="Utilities\CrashReport.cs" />
7.19 <Compile Include="Utilities\EmbeddedResources.cs" />
7.20 @@ -137,7 +138,7 @@
7.21 <ItemGroup>
7.22 <EmbeddedResource Include="Resources\chip.png" />
7.23 <EmbeddedResource Include="Resources\hdd.png" />
7.24 - <Content Include="Resources\icon.ico" />
7.25 + <None Include="Resources\icon.ico" />
7.26 <EmbeddedResource Include="Resources\load.png" />
7.27 <EmbeddedResource Include="Resources\voltage.png" />
7.28 <EmbeddedResource Include="Resources\nvidia.png" />
8.1 --- a/Utilities/Configuration.cs Fri Feb 05 22:45:15 2010 +0000
8.2 +++ b/Utilities/Configuration.cs Sun Feb 07 16:37:15 2010 +0000
8.3 @@ -99,6 +99,10 @@
8.4 return element != null;
8.5 }
8.6
8.7 + public static void Remove(string name) {
8.8 + instance.config.AppSettings.Settings.Remove(name);
8.9 + }
8.10 +
8.11 public static void Set(string name, bool value) {
8.12 instance[name] = value ? "true" : "false";
8.13 }
9.1 --- a/Utilities/EmbeddedResources.cs Fri Feb 05 22:45:15 2010 +0000
9.2 +++ b/Utilities/EmbeddedResources.cs Sun Feb 07 16:37:15 2010 +0000
9.3 @@ -56,6 +56,20 @@
9.4
9.5 return new Bitmap(1, 1);
9.6 }
9.7 +
9.8 + public static Icon GetIcon(string name) {
9.9 + name = "OpenHardwareMonitor.Resources." + name;
9.10 +
9.11 + string[] names =
9.12 + Assembly.GetExecutingAssembly().GetManifestResourceNames();
9.13 + for (int i = 0; i < names.Length; i++) {
9.14 + if (names[i].Replace('\\', '.') == name)
9.15 + return new Icon(Assembly.GetExecutingAssembly().
9.16 + GetManifestResourceStream(names[i]));
9.17 + }
9.18 +
9.19 + return null;
9.20 + }
9.21
9.22 }
9.23 }