Added a dialog for the report filename. Added additional checks to T-Balancer code for cases where the port gets closed. Moved the timer to the Computer class.
1.1 --- a/GUI/MainForm.Designer.cs Fri Mar 26 20:58:10 2010 +0000
1.2 +++ b/GUI/MainForm.Designer.cs Sat Mar 27 12:57:09 2010 +0000
1.3 @@ -102,7 +102,6 @@
1.4 this.hddMenuItem = new System.Windows.Forms.ToolStripMenuItem();
1.5 this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
1.6 this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
1.7 - this.timer = new System.Windows.Forms.Timer(this.components);
1.8 this.splitContainer = new System.Windows.Forms.SplitContainer();
1.9 this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel();
1.10 this.notifyContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
1.11 @@ -110,6 +109,7 @@
1.12 this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
1.13 this.exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
1.14 this.sensorContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
1.15 + this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
1.16 this.columnsContextMenuStrip.SuspendLayout();
1.17 this.menuStrip.SuspendLayout();
1.18 this.splitContainer.Panel1.SuspendLayout();
1.19 @@ -314,14 +314,14 @@
1.20 // saveReportToolStripMenuItem
1.21 //
1.22 this.saveReportToolStripMenuItem.Name = "saveReportToolStripMenuItem";
1.23 - this.saveReportToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
1.24 - this.saveReportToolStripMenuItem.Text = "Save Report";
1.25 + this.saveReportToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
1.26 + this.saveReportToolStripMenuItem.Text = "Save Report...";
1.27 this.saveReportToolStripMenuItem.Click += new System.EventHandler(this.saveReportToolStripMenuItem_Click);
1.28 //
1.29 // exitToolStripMenuItem
1.30 //
1.31 this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
1.32 - this.exitToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
1.33 + this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
1.34 this.exitToolStripMenuItem.Text = "Exit";
1.35 this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
1.36 //
1.37 @@ -486,11 +486,6 @@
1.38 this.aboutToolStripMenuItem.Text = "About";
1.39 this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
1.40 //
1.41 - // timer
1.42 - //
1.43 - this.timer.Interval = 1000;
1.44 - this.timer.Tick += new System.EventHandler(this.timer_Tick);
1.45 - //
1.46 // splitContainer
1.47 //
1.48 this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
1.49 @@ -528,25 +523,25 @@
1.50 this.toolStripMenuItem2,
1.51 this.exitToolStripMenuItem1});
1.52 this.notifyContextMenuStrip.Name = "notifyContextMenuStrip";
1.53 - this.notifyContextMenuStrip.Size = new System.Drawing.Size(153, 76);
1.54 + this.notifyContextMenuStrip.Size = new System.Drawing.Size(137, 54);
1.55 //
1.56 // hideShowToolStripMenuItem
1.57 //
1.58 this.hideShowToolStripMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
1.59 this.hideShowToolStripMenuItem.Name = "hideShowToolStripMenuItem";
1.60 - this.hideShowToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
1.61 + this.hideShowToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
1.62 this.hideShowToolStripMenuItem.Text = "Hide/Show";
1.63 this.hideShowToolStripMenuItem.Click += new System.EventHandler(this.hideShowClick);
1.64 //
1.65 // toolStripMenuItem2
1.66 //
1.67 this.toolStripMenuItem2.Name = "toolStripMenuItem2";
1.68 - this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
1.69 + this.toolStripMenuItem2.Size = new System.Drawing.Size(133, 6);
1.70 //
1.71 // exitToolStripMenuItem1
1.72 //
1.73 this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
1.74 - this.exitToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
1.75 + this.exitToolStripMenuItem1.Size = new System.Drawing.Size(136, 22);
1.76 this.exitToolStripMenuItem1.Text = "Exit";
1.77 this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
1.78 //
1.79 @@ -555,6 +550,14 @@
1.80 this.sensorContextMenuStrip.Name = "sensorContextMenuStrip";
1.81 this.sensorContextMenuStrip.Size = new System.Drawing.Size(61, 4);
1.82 //
1.83 + // saveFileDialog
1.84 + //
1.85 + this.saveFileDialog.DefaultExt = "txt";
1.86 + this.saveFileDialog.FileName = "OpenHardwareMonitor.Report.txt";
1.87 + this.saveFileDialog.Filter = "Text Documents|*.txt|All Files|*.*";
1.88 + this.saveFileDialog.RestoreDirectory = true;
1.89 + this.saveFileDialog.Title = "Save Report As";
1.90 + //
1.91 // MainForm
1.92 //
1.93 this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
1.94 @@ -596,7 +599,6 @@
1.95 private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxValue;
1.96 private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxMin;
1.97 private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxMax;
1.98 - private System.Windows.Forms.Timer timer;
1.99 private System.Windows.Forms.SplitContainer splitContainer;
1.100 private PlotPanel plotPanel;
1.101 private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem;
1.102 @@ -631,6 +633,7 @@
1.103 private System.Windows.Forms.ToolStripMenuItem startMinMenuItem;
1.104 private System.Windows.Forms.ToolStripMenuItem flowsMenuItem;
1.105 private System.Windows.Forms.ToolStripMenuItem startupMenuItem;
1.106 + private System.Windows.Forms.SaveFileDialog saveFileDialog;
1.107 }
1.108 }
1.109
2.1 --- a/GUI/MainForm.cs Fri Mar 26 20:58:10 2010 +0000
2.2 +++ b/GUI/MainForm.cs Sat Mar 27 12:57:09 2010 +0000
2.3 @@ -40,6 +40,7 @@
2.4 using System.ComponentModel;
2.5 using System.Configuration;
2.6 using System.Drawing;
2.7 +using System.IO;
2.8 using System.Text;
2.9 using System.Windows.Forms;
2.10 using Aga.Controls.Tree;
2.11 @@ -112,6 +113,7 @@
2.12
2.13 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
2.14 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
2.15 + computer.Updated += new UpdateEventHandler(Updated);
2.16 computer.Open();
2.17
2.18 plotColorPalette = new Color[14];
2.19 @@ -145,9 +147,7 @@
2.20 loadMenuItem.Checked = Config.Get(loadMenuItem.Name, true);
2.21 tempMenuItem.Checked = Config.Get(tempMenuItem.Name, true);
2.22 fansMenuItem.Checked = Config.Get(fansMenuItem.Name, true);
2.23 - flowsMenuItem.Checked = Config.Get(flowsMenuItem.Name, true);
2.24 -
2.25 - timer.Enabled = true;
2.26 + flowsMenuItem.Checked = Config.Get(flowsMenuItem.Name, true);
2.27
2.28 if (startMinMenuItem.Checked) {
2.29 if (!minTrayMenuItem.Checked) {
2.30 @@ -239,19 +239,7 @@
2.31 Close();
2.32 }
2.33
2.34 - private void timer_Tick(object sender, EventArgs e) {
2.35 -
2.36 - #if !DEBUG
2.37 - try {
2.38 - #endif
2.39 - computer.Update();
2.40 - #if !DEBUG
2.41 - } catch (Exception exception) {
2.42 - CrashReport.Save(exception);
2.43 - Close();
2.44 - }
2.45 - #endif
2.46 -
2.47 + private void Updated() {
2.48 treeView.Invalidate();
2.49 plotPanel.Invalidate();
2.50 sensorSystemTray.Redraw();
2.51 @@ -359,7 +347,12 @@
2.52 }
2.53
2.54 private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
2.55 - computer.SaveReport(new Version(Application.ProductVersion));
2.56 + string report = computer.GetReport();
2.57 + if (saveFileDialog.ShowDialog() == DialogResult.OK) {
2.58 + using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
2.59 + w.Write(report);
2.60 + }
2.61 + }
2.62 }
2.63
2.64 private void hddsensorsToolStripMenuItem_CheckedChanged(object sender,
3.1 --- a/GUI/MainForm.resx Fri Mar 26 20:58:10 2010 +0000
3.2 +++ b/GUI/MainForm.resx Sat Mar 27 12:57:09 2010 +0000
3.3 @@ -118,19 +118,19 @@
3.4 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
3.5 </resheader>
3.6 <metadata name="columnsContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
3.7 - <value>204, 15</value>
3.8 + <value>125, 17</value>
3.9 </metadata>
3.10 <metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
3.11 <value>17, 17</value>
3.12 </metadata>
3.13 - <metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
3.14 - <value>124, 15</value>
3.15 - </metadata>
3.16 <metadata name="notifyContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
3.17 - <value>399, 15</value>
3.18 + <value>322, 17</value>
3.19 </metadata>
3.20 <metadata name="sensorContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
3.21 - <value>571, 15</value>
3.22 + <value>504, 17</value>
3.23 + </metadata>
3.24 + <metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
3.25 + <value>690, 17</value>
3.26 </metadata>
3.27 <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
3.28 <value>55</value>
4.1 --- a/GUI/SensorSystemTray.cs Fri Mar 26 20:58:10 2010 +0000
4.2 +++ b/GUI/SensorSystemTray.cs Sat Mar 27 12:57:09 2010 +0000
4.3 @@ -45,10 +45,10 @@
4.4
4.5 namespace OpenHardwareMonitor.GUI {
4.6 public class SensorSystemTray : IDisposable {
4.7 - private Computer computer;
4.8 + private IComputer computer;
4.9 private List<SensorNotifyIcon> list = new List<SensorNotifyIcon>();
4.10
4.11 - public SensorSystemTray(Computer computer) {
4.12 + public SensorSystemTray(IComputer computer) {
4.13 this.computer = computer;
4.14 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
4.15 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
5.1 --- a/Hardware/Computer.cs Fri Mar 26 20:58:10 2010 +0000
5.2 +++ b/Hardware/Computer.cs Sat Mar 27 12:57:09 2010 +0000
5.3 @@ -40,12 +40,13 @@
5.4 using System.IO;
5.5 using System.Globalization;
5.6 using System.Text;
5.7 +using System.Threading;
5.8
5.9 namespace OpenHardwareMonitor.Hardware {
5.10
5.11 - public delegate void HardwareEventHandler(IHardware hardware);
5.12 + public class Computer : IComputer {
5.13
5.14 - public class Computer {
5.15 + private Timer timer;
5.16
5.17 private List<IGroup> groups = new List<IGroup>();
5.18
5.19 @@ -61,7 +62,7 @@
5.20 groups.Add(group);
5.21
5.22 if (HardwareAdded != null)
5.23 - foreach (IHardware hardware in group.Hardware)
5.24 + foreach (IHardware hardware in group.Hardware)
5.25 HardwareAdded(hardware);
5.26 }
5.27
5.28 @@ -72,7 +73,7 @@
5.29 groups.Remove(group);
5.30
5.31 if (HardwareRemoved != null)
5.32 - foreach (IHardware hardware in group.Hardware)
5.33 + foreach (IHardware hardware in group.Hardware)
5.34 HardwareRemoved(hardware);
5.35 }
5.36
5.37 @@ -86,10 +87,24 @@
5.38 Add(new Nvidia.NvidiaGroup());
5.39 Add(new TBalancer.TBalancerGroup());
5.40
5.41 - if (hddEnabled)
5.42 + if (hddEnabled)
5.43 Add(new HDD.HDDGroup());
5.44
5.45 open = true;
5.46 +
5.47 + timer = new Timer(
5.48 + delegate(Object stateInfo) {
5.49 + #if !DEBUG
5.50 + try {
5.51 + #endif
5.52 + Update();
5.53 + #if !DEBUG
5.54 + } catch (Exception exception) {
5.55 + Utilities.CrashReport.Save(exception);
5.56 + throw;
5.57 + }
5.58 + #endif
5.59 + }, null, 1000, 1000);
5.60 }
5.61
5.62 private void SubHardwareUpdate(IHardware hardware) {
5.63 @@ -99,12 +114,14 @@
5.64 }
5.65 }
5.66
5.67 - public void Update() {
5.68 + private void Update() {
5.69 foreach (IGroup group in groups)
5.70 foreach (IHardware hardware in group.Hardware) {
5.71 hardware.Update();
5.72 SubHardwareUpdate(hardware);
5.73 }
5.74 + if (Updated != null)
5.75 + Updated();
5.76 }
5.77
5.78 public bool HDDEnabled {
5.79 @@ -118,17 +135,19 @@
5.80 if (group is HDD.HDDGroup)
5.81 list.Add(group);
5.82 foreach (IGroup group in list)
5.83 - Remove(group);
5.84 + Remove(group);
5.85 }
5.86 hddEnabled = value;
5.87 }
5.88 }
5.89
5.90 - public IEnumerable<IHardware> Hardware {
5.91 - get {
5.92 + public IHardware[] Hardware {
5.93 + get {
5.94 + List<IHardware> list = new List<IHardware>();
5.95 foreach (IGroup group in groups)
5.96 foreach (IHardware hardware in group.Hardware)
5.97 - yield return hardware;
5.98 + list.Add(hardware);
5.99 + return list.ToArray();
5.100 }
5.101 }
5.102
5.103 @@ -139,11 +158,10 @@
5.104 writer.WriteLine();
5.105 }
5.106
5.107 - private void ReportHardwareTree(IHardware hardware, TextWriter w,
5.108 - string space)
5.109 - {
5.110 + private void ReportHardwareTree(IHardware hardware, TextWriter w,
5.111 + string space) {
5.112 w.WriteLine("{0}|", space);
5.113 - w.WriteLine("{0}+-+ {1} ({2})",
5.114 + w.WriteLine("{0}+-+ {1} ({2})",
5.115 space, hardware.Name, hardware.Identifier);
5.116 foreach (ISensor sensor in hardware.Sensors) {
5.117 w.WriteLine("{0}| +- {1} : {2} : {3} : {4}",
5.118 @@ -171,15 +189,16 @@
5.119 ReportHardware(subHardware, w);
5.120 }
5.121
5.122 - public void SaveReport(Version version) {
5.123 + public string GetReport() {
5.124
5.125 - using (TextWriter w =
5.126 - new StreamWriter("OpenHardwareMonitor.Report.txt")) {
5.127 + using (StringWriter w = new StringWriter()) {
5.128
5.129 w.WriteLine();
5.130 w.WriteLine("Open Hardware Monitor Report");
5.131 w.WriteLine();
5.132
5.133 + Version version = typeof(Computer).Assembly.GetName().Version;
5.134 +
5.135 NewSection(w);
5.136 w.Write("Version: "); w.WriteLine(version.ToString());
5.137 w.WriteLine();
5.138 @@ -187,7 +206,7 @@
5.139 NewSection(w);
5.140 foreach (IGroup group in groups) {
5.141 foreach (IHardware hardware in group.Hardware)
5.142 - ReportHardwareTree(hardware, w, "");
5.143 + ReportHardwareTree(hardware, w, "");
5.144 }
5.145 w.WriteLine();
5.146
5.147 @@ -201,12 +220,16 @@
5.148 IHardware[] hardwareArray = group.Hardware;
5.149 foreach (IHardware hardware in hardwareArray)
5.150 ReportHardware(hardware, w);
5.151 -
5.152 +
5.153 }
5.154 + return w.ToString();
5.155 }
5.156 }
5.157
5.158 - public void Close() {
5.159 + public void Close() {
5.160 + timer.Dispose();
5.161 + timer = null;
5.162 +
5.163 if (!open)
5.164 return;
5.165
5.166 @@ -217,6 +240,7 @@
5.167 open = false;
5.168 }
5.169
5.170 + public event UpdateEventHandler Updated;
5.171 public event HardwareEventHandler HardwareAdded;
5.172 public event HardwareEventHandler HardwareRemoved;
5.173
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/Hardware/IComputer.cs Sat Mar 27 12:57:09 2010 +0000
6.3 @@ -0,0 +1,58 @@
6.4 +/*
6.5 +
6.6 + Version: MPL 1.1/GPL 2.0/LGPL 2.1
6.7 +
6.8 + The contents of this file are subject to the Mozilla Public License Version
6.9 + 1.1 (the "License"); you may not use this file except in compliance with
6.10 + the License. You may obtain a copy of the License at
6.11 +
6.12 + http://www.mozilla.org/MPL/
6.13 +
6.14 + Software distributed under the License is distributed on an "AS IS" basis,
6.15 + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
6.16 + for the specific language governing rights and limitations under the License.
6.17 +
6.18 + The Original Code is the Open Hardware Monitor code.
6.19 +
6.20 + The Initial Developer of the Original Code is
6.21 + Michael Möller <m.moeller@gmx.ch>.
6.22 + Portions created by the Initial Developer are Copyright (C) 2009-2010
6.23 + the Initial Developer. All Rights Reserved.
6.24 +
6.25 + Contributor(s):
6.26 +
6.27 + Alternatively, the contents of this file may be used under the terms of
6.28 + either the GNU General Public License Version 2 or later (the "GPL"), or
6.29 + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
6.30 + in which case the provisions of the GPL or the LGPL are applicable instead
6.31 + of those above. If you wish to allow use of your version of this file only
6.32 + under the terms of either the GPL or the LGPL, and not to allow others to
6.33 + use your version of this file under the terms of the MPL, indicate your
6.34 + decision by deleting the provisions above and replace them with the notice
6.35 + and other provisions required by the GPL or the LGPL. If you do not delete
6.36 + the provisions above, a recipient may use your version of this file under
6.37 + the terms of any one of the MPL, the GPL or the LGPL.
6.38 +
6.39 +*/
6.40 +
6.41 +using System;
6.42 +using System.Collections.Generic;
6.43 +
6.44 +namespace OpenHardwareMonitor.Hardware {
6.45 +
6.46 + public delegate void UpdateEventHandler();
6.47 + public delegate void HardwareEventHandler(IHardware hardware);
6.48 +
6.49 + public interface IComputer {
6.50 +
6.51 + IHardware[] Hardware { get; }
6.52 +
6.53 + bool HDDEnabled { get; set; }
6.54 +
6.55 + string GetReport();
6.56 +
6.57 + event UpdateEventHandler Updated;
6.58 + event HardwareEventHandler HardwareAdded;
6.59 + event HardwareEventHandler HardwareRemoved;
6.60 + }
6.61 +}
7.1 --- a/Hardware/TBalancer/TBalancer.cs Fri Mar 26 20:58:10 2010 +0000
7.2 +++ b/Hardware/TBalancer/TBalancer.cs Sat Mar 27 12:57:09 2010 +0000
7.3 @@ -326,17 +326,23 @@
7.4 }
7.5
7.6 public void Update() {
7.7 - while (serialPort.BytesToRead >= 285)
7.8 - ReadData();
7.9 - if (serialPort.BytesToRead == 1)
7.10 - serialPort.ReadByte();
7.11 + try {
7.12 + while (serialPort.IsOpen && serialPort.BytesToRead >= 285)
7.13 + ReadData();
7.14 + if (serialPort.BytesToRead == 1)
7.15 + serialPort.ReadByte();
7.16
7.17 - serialPort.Write(new byte[] { 0x38 }, 0, 1);
7.18 - alternativeRequest.BeginInvoke(null, null);
7.19 + serialPort.Write(new byte[] { 0x38 }, 0, 1);
7.20 + alternativeRequest.BeginInvoke(null, null);
7.21 + } catch (InvalidOperationException) {
7.22 + foreach (Sensor sensor in active)
7.23 + sensor.Value = null;
7.24 + }
7.25 }
7.26
7.27 public void Close() {
7.28 - serialPort.Close();
7.29 + if (serialPort.IsOpen)
7.30 + serialPort.Close();
7.31 }
7.32
7.33 public event SensorEventHandler SensorAdded;
8.1 --- a/OpenHardwareMonitor.csproj Fri Mar 26 20:58:10 2010 +0000
8.2 +++ b/OpenHardwareMonitor.csproj Sat Mar 27 12:57:09 2010 +0000
8.3 @@ -76,6 +76,7 @@
8.4 <Compile Include="Hardware\HDD\HDD.cs" />
8.5 <Compile Include="Hardware\HDD\HDDGroup.cs" />
8.6 <Compile Include="Hardware\HDD\SMART.cs" />
8.7 + <Compile Include="Hardware\IComputer.cs" />
8.8 <Compile Include="Hardware\IParameter.cs" />
8.9 <Compile Include="Hardware\LPC\Chip.cs" />
8.10 <Compile Include="Hardware\LPC\F718XX.cs" />