# HG changeset patch
# User moel.mich
# Date 1269694629 0
# Node ID 3fdadd4a830f35a9fb5c34102517f8fe54d66763
# Parent 91edecb084a13b90918fa89e0da41d530023bda2
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.
diff -r 91edecb084a1 -r 3fdadd4a830f GUI/MainForm.Designer.cs
--- a/GUI/MainForm.Designer.cs Fri Mar 26 20:58:10 2010 +0000
+++ b/GUI/MainForm.Designer.cs Sat Mar 27 12:57:09 2010 +0000
@@ -102,7 +102,6 @@
this.hddMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.timer = new System.Windows.Forms.Timer(this.components);
this.splitContainer = new System.Windows.Forms.SplitContainer();
this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel();
this.notifyContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
@@ -110,6 +109,7 @@
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.sensorContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
+ this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.columnsContextMenuStrip.SuspendLayout();
this.menuStrip.SuspendLayout();
this.splitContainer.Panel1.SuspendLayout();
@@ -314,14 +314,14 @@
// saveReportToolStripMenuItem
//
this.saveReportToolStripMenuItem.Name = "saveReportToolStripMenuItem";
- this.saveReportToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
- this.saveReportToolStripMenuItem.Text = "Save Report";
+ this.saveReportToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
+ this.saveReportToolStripMenuItem.Text = "Save Report...";
this.saveReportToolStripMenuItem.Click += new System.EventHandler(this.saveReportToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
- this.exitToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
+ this.exitToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
@@ -486,11 +486,6 @@
this.aboutToolStripMenuItem.Text = "About";
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
//
- // timer
- //
- this.timer.Interval = 1000;
- this.timer.Tick += new System.EventHandler(this.timer_Tick);
- //
// splitContainer
//
this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -528,25 +523,25 @@
this.toolStripMenuItem2,
this.exitToolStripMenuItem1});
this.notifyContextMenuStrip.Name = "notifyContextMenuStrip";
- this.notifyContextMenuStrip.Size = new System.Drawing.Size(153, 76);
+ this.notifyContextMenuStrip.Size = new System.Drawing.Size(137, 54);
//
// hideShowToolStripMenuItem
//
this.hideShowToolStripMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
this.hideShowToolStripMenuItem.Name = "hideShowToolStripMenuItem";
- this.hideShowToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
+ this.hideShowToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
this.hideShowToolStripMenuItem.Text = "Hide/Show";
this.hideShowToolStripMenuItem.Click += new System.EventHandler(this.hideShowClick);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
- this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
+ this.toolStripMenuItem2.Size = new System.Drawing.Size(133, 6);
//
// exitToolStripMenuItem1
//
this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
- this.exitToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
+ this.exitToolStripMenuItem1.Size = new System.Drawing.Size(136, 22);
this.exitToolStripMenuItem1.Text = "Exit";
this.exitToolStripMenuItem1.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
@@ -555,6 +550,14 @@
this.sensorContextMenuStrip.Name = "sensorContextMenuStrip";
this.sensorContextMenuStrip.Size = new System.Drawing.Size(61, 4);
//
+ // saveFileDialog
+ //
+ this.saveFileDialog.DefaultExt = "txt";
+ this.saveFileDialog.FileName = "OpenHardwareMonitor.Report.txt";
+ this.saveFileDialog.Filter = "Text Documents|*.txt|All Files|*.*";
+ this.saveFileDialog.RestoreDirectory = true;
+ this.saveFileDialog.Title = "Save Report As";
+ //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -596,7 +599,6 @@
private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxValue;
private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxMin;
private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBoxMax;
- private System.Windows.Forms.Timer timer;
private System.Windows.Forms.SplitContainer splitContainer;
private PlotPanel plotPanel;
private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem;
@@ -631,6 +633,7 @@
private System.Windows.Forms.ToolStripMenuItem startMinMenuItem;
private System.Windows.Forms.ToolStripMenuItem flowsMenuItem;
private System.Windows.Forms.ToolStripMenuItem startupMenuItem;
+ private System.Windows.Forms.SaveFileDialog saveFileDialog;
}
}
diff -r 91edecb084a1 -r 3fdadd4a830f GUI/MainForm.cs
--- a/GUI/MainForm.cs Fri Mar 26 20:58:10 2010 +0000
+++ b/GUI/MainForm.cs Sat Mar 27 12:57:09 2010 +0000
@@ -40,6 +40,7 @@
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
+using System.IO;
using System.Text;
using System.Windows.Forms;
using Aga.Controls.Tree;
@@ -112,6 +113,7 @@
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
+ computer.Updated += new UpdateEventHandler(Updated);
computer.Open();
plotColorPalette = new Color[14];
@@ -145,9 +147,7 @@
loadMenuItem.Checked = Config.Get(loadMenuItem.Name, true);
tempMenuItem.Checked = Config.Get(tempMenuItem.Name, true);
fansMenuItem.Checked = Config.Get(fansMenuItem.Name, true);
- flowsMenuItem.Checked = Config.Get(flowsMenuItem.Name, true);
-
- timer.Enabled = true;
+ flowsMenuItem.Checked = Config.Get(flowsMenuItem.Name, true);
if (startMinMenuItem.Checked) {
if (!minTrayMenuItem.Checked) {
@@ -239,19 +239,7 @@
Close();
}
- private void timer_Tick(object sender, EventArgs e) {
-
- #if !DEBUG
- try {
- #endif
- computer.Update();
- #if !DEBUG
- } catch (Exception exception) {
- CrashReport.Save(exception);
- Close();
- }
- #endif
-
+ private void Updated() {
treeView.Invalidate();
plotPanel.Invalidate();
sensorSystemTray.Redraw();
@@ -359,7 +347,12 @@
}
private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
- computer.SaveReport(new Version(Application.ProductVersion));
+ string report = computer.GetReport();
+ if (saveFileDialog.ShowDialog() == DialogResult.OK) {
+ using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
+ w.Write(report);
+ }
+ }
}
private void hddsensorsToolStripMenuItem_CheckedChanged(object sender,
diff -r 91edecb084a1 -r 3fdadd4a830f GUI/MainForm.resx
--- a/GUI/MainForm.resx Fri Mar 26 20:58:10 2010 +0000
+++ b/GUI/MainForm.resx Sat Mar 27 12:57:09 2010 +0000
@@ -118,19 +118,19 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- 204, 15
+ 125, 17
17, 17
-
- 124, 15
-
- 399, 15
+ 322, 17
- 571, 15
+ 504, 17
+
+
+ 690, 17
55
diff -r 91edecb084a1 -r 3fdadd4a830f GUI/SensorSystemTray.cs
--- a/GUI/SensorSystemTray.cs Fri Mar 26 20:58:10 2010 +0000
+++ b/GUI/SensorSystemTray.cs Sat Mar 27 12:57:09 2010 +0000
@@ -45,10 +45,10 @@
namespace OpenHardwareMonitor.GUI {
public class SensorSystemTray : IDisposable {
- private Computer computer;
+ private IComputer computer;
private List list = new List();
- public SensorSystemTray(Computer computer) {
+ public SensorSystemTray(IComputer computer) {
this.computer = computer;
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
diff -r 91edecb084a1 -r 3fdadd4a830f Hardware/Computer.cs
--- a/Hardware/Computer.cs Fri Mar 26 20:58:10 2010 +0000
+++ b/Hardware/Computer.cs Sat Mar 27 12:57:09 2010 +0000
@@ -40,12 +40,13 @@
using System.IO;
using System.Globalization;
using System.Text;
+using System.Threading;
namespace OpenHardwareMonitor.Hardware {
- public delegate void HardwareEventHandler(IHardware hardware);
+ public class Computer : IComputer {
- public class Computer {
+ private Timer timer;
private List groups = new List();
@@ -61,7 +62,7 @@
groups.Add(group);
if (HardwareAdded != null)
- foreach (IHardware hardware in group.Hardware)
+ foreach (IHardware hardware in group.Hardware)
HardwareAdded(hardware);
}
@@ -72,7 +73,7 @@
groups.Remove(group);
if (HardwareRemoved != null)
- foreach (IHardware hardware in group.Hardware)
+ foreach (IHardware hardware in group.Hardware)
HardwareRemoved(hardware);
}
@@ -86,10 +87,24 @@
Add(new Nvidia.NvidiaGroup());
Add(new TBalancer.TBalancerGroup());
- if (hddEnabled)
+ if (hddEnabled)
Add(new HDD.HDDGroup());
open = true;
+
+ timer = new Timer(
+ delegate(Object stateInfo) {
+ #if !DEBUG
+ try {
+ #endif
+ Update();
+ #if !DEBUG
+ } catch (Exception exception) {
+ Utilities.CrashReport.Save(exception);
+ throw;
+ }
+ #endif
+ }, null, 1000, 1000);
}
private void SubHardwareUpdate(IHardware hardware) {
@@ -99,12 +114,14 @@
}
}
- public void Update() {
+ private void Update() {
foreach (IGroup group in groups)
foreach (IHardware hardware in group.Hardware) {
hardware.Update();
SubHardwareUpdate(hardware);
}
+ if (Updated != null)
+ Updated();
}
public bool HDDEnabled {
@@ -118,17 +135,19 @@
if (group is HDD.HDDGroup)
list.Add(group);
foreach (IGroup group in list)
- Remove(group);
+ Remove(group);
}
hddEnabled = value;
}
}
- public IEnumerable Hardware {
- get {
+ public IHardware[] Hardware {
+ get {
+ List list = new List();
foreach (IGroup group in groups)
foreach (IHardware hardware in group.Hardware)
- yield return hardware;
+ list.Add(hardware);
+ return list.ToArray();
}
}
@@ -139,11 +158,10 @@
writer.WriteLine();
}
- private void ReportHardwareTree(IHardware hardware, TextWriter w,
- string space)
- {
+ private void ReportHardwareTree(IHardware hardware, TextWriter w,
+ string space) {
w.WriteLine("{0}|", space);
- w.WriteLine("{0}+-+ {1} ({2})",
+ w.WriteLine("{0}+-+ {1} ({2})",
space, hardware.Name, hardware.Identifier);
foreach (ISensor sensor in hardware.Sensors) {
w.WriteLine("{0}| +- {1} : {2} : {3} : {4}",
@@ -171,15 +189,16 @@
ReportHardware(subHardware, w);
}
- public void SaveReport(Version version) {
+ public string GetReport() {
- using (TextWriter w =
- new StreamWriter("OpenHardwareMonitor.Report.txt")) {
+ using (StringWriter w = new StringWriter()) {
w.WriteLine();
w.WriteLine("Open Hardware Monitor Report");
w.WriteLine();
+ Version version = typeof(Computer).Assembly.GetName().Version;
+
NewSection(w);
w.Write("Version: "); w.WriteLine(version.ToString());
w.WriteLine();
@@ -187,7 +206,7 @@
NewSection(w);
foreach (IGroup group in groups) {
foreach (IHardware hardware in group.Hardware)
- ReportHardwareTree(hardware, w, "");
+ ReportHardwareTree(hardware, w, "");
}
w.WriteLine();
@@ -201,12 +220,16 @@
IHardware[] hardwareArray = group.Hardware;
foreach (IHardware hardware in hardwareArray)
ReportHardware(hardware, w);
-
+
}
+ return w.ToString();
}
}
- public void Close() {
+ public void Close() {
+ timer.Dispose();
+ timer = null;
+
if (!open)
return;
@@ -217,6 +240,7 @@
open = false;
}
+ public event UpdateEventHandler Updated;
public event HardwareEventHandler HardwareAdded;
public event HardwareEventHandler HardwareRemoved;
diff -r 91edecb084a1 -r 3fdadd4a830f Hardware/IComputer.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Hardware/IComputer.cs Sat Mar 27 12:57:09 2010 +0000
@@ -0,0 +1,58 @@
+/*
+
+ 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 .
+ 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;
+
+namespace OpenHardwareMonitor.Hardware {
+
+ public delegate void UpdateEventHandler();
+ public delegate void HardwareEventHandler(IHardware hardware);
+
+ public interface IComputer {
+
+ IHardware[] Hardware { get; }
+
+ bool HDDEnabled { get; set; }
+
+ string GetReport();
+
+ event UpdateEventHandler Updated;
+ event HardwareEventHandler HardwareAdded;
+ event HardwareEventHandler HardwareRemoved;
+ }
+}
diff -r 91edecb084a1 -r 3fdadd4a830f Hardware/TBalancer/TBalancer.cs
--- a/Hardware/TBalancer/TBalancer.cs Fri Mar 26 20:58:10 2010 +0000
+++ b/Hardware/TBalancer/TBalancer.cs Sat Mar 27 12:57:09 2010 +0000
@@ -326,17 +326,23 @@
}
public void Update() {
- while (serialPort.BytesToRead >= 285)
- ReadData();
- if (serialPort.BytesToRead == 1)
- serialPort.ReadByte();
+ try {
+ while (serialPort.IsOpen && serialPort.BytesToRead >= 285)
+ ReadData();
+ if (serialPort.BytesToRead == 1)
+ serialPort.ReadByte();
- serialPort.Write(new byte[] { 0x38 }, 0, 1);
- alternativeRequest.BeginInvoke(null, null);
+ serialPort.Write(new byte[] { 0x38 }, 0, 1);
+ alternativeRequest.BeginInvoke(null, null);
+ } catch (InvalidOperationException) {
+ foreach (Sensor sensor in active)
+ sensor.Value = null;
+ }
}
public void Close() {
- serialPort.Close();
+ if (serialPort.IsOpen)
+ serialPort.Close();
}
public event SensorEventHandler SensorAdded;
diff -r 91edecb084a1 -r 3fdadd4a830f OpenHardwareMonitor.csproj
--- a/OpenHardwareMonitor.csproj Fri Mar 26 20:58:10 2010 +0000
+++ b/OpenHardwareMonitor.csproj Sat Mar 27 12:57:09 2010 +0000
@@ -76,6 +76,7 @@
+