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.

This commit is contained in:
Michael Möller 2010-03-27 12:57:09 +00:00
parent e0e30c4b55
commit d5ed83e09a
8 changed files with 151 additions and 66 deletions

View File

@ -102,7 +102,6 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
// 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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
private System.Windows.Forms.ToolStripMenuItem startMinMenuItem;
private System.Windows.Forms.ToolStripMenuItem flowsMenuItem;
private System.Windows.Forms.ToolStripMenuItem startupMenuItem;
private System.Windows.Forms.SaveFileDialog saveFileDialog;
}
}

View File

@ -40,6 +40,7 @@ using System.Collections.Generic;
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 @@ namespace OpenHardwareMonitor.GUI {
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
computer.Updated += new UpdateEventHandler(Updated);
computer.Open();
plotColorPalette = new Color[14];
@ -147,8 +149,6 @@ namespace OpenHardwareMonitor.GUI {
fansMenuItem.Checked = Config.Get(fansMenuItem.Name, true);
flowsMenuItem.Checked = Config.Get(flowsMenuItem.Name, true);
timer.Enabled = true;
if (startMinMenuItem.Checked) {
if (!minTrayMenuItem.Checked) {
WindowState = FormWindowState.Minimized;
@ -239,19 +239,7 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
}
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,

View File

@ -118,19 +118,19 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="columnsContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>204, 15</value>
<value>125, 17</value>
</metadata>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>124, 15</value>
</metadata>
<metadata name="notifyContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>399, 15</value>
<value>322, 17</value>
</metadata>
<metadata name="sensorContextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>571, 15</value>
<value>504, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>690, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>55</value>

View File

@ -45,10 +45,10 @@ using OpenHardwareMonitor.Utilities;
namespace OpenHardwareMonitor.GUI {
public class SensorSystemTray : IDisposable {
private Computer computer;
private IComputer computer;
private List<SensorNotifyIcon> list = new List<SensorNotifyIcon>();
public SensorSystemTray(Computer computer) {
public SensorSystemTray(IComputer computer) {
this.computer = computer;
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);

View File

@ -40,12 +40,13 @@ using System.Collections.Generic;
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<IGroup> groups = new List<IGroup>();
@ -90,6 +91,20 @@ namespace OpenHardwareMonitor.Hardware {
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 @@ namespace OpenHardwareMonitor.Hardware {
}
}
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 {
@ -124,11 +141,13 @@ namespace OpenHardwareMonitor.Hardware {
}
}
public IEnumerable<IHardware> Hardware {
public IHardware[] Hardware {
get {
List<IHardware> list = new List<IHardware>();
foreach (IGroup group in groups)
foreach (IHardware hardware in group.Hardware)
yield return hardware;
list.Add(hardware);
return list.ToArray();
}
}
@ -140,8 +159,7 @@ namespace OpenHardwareMonitor.Hardware {
}
private void ReportHardwareTree(IHardware hardware, TextWriter w,
string space)
{
string space) {
w.WriteLine("{0}|", space);
w.WriteLine("{0}+-+ {1} ({2})",
space, hardware.Name, hardware.Identifier);
@ -171,15 +189,16 @@ namespace OpenHardwareMonitor.Hardware {
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();
@ -203,10 +222,14 @@ namespace OpenHardwareMonitor.Hardware {
ReportHardware(hardware, w);
}
return w.ToString();
}
}
public void Close() {
timer.Dispose();
timer = null;
if (!open)
return;
@ -217,6 +240,7 @@ namespace OpenHardwareMonitor.Hardware {
open = false;
}
public event UpdateEventHandler Updated;
public event HardwareEventHandler HardwareAdded;
public event HardwareEventHandler HardwareRemoved;

58
Hardware/IComputer.cs Normal file
View File

@ -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 <m.moeller@gmx.ch>.
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;
}
}

View File

@ -326,16 +326,22 @@ namespace OpenHardwareMonitor.Hardware.TBalancer {
}
public void Update() {
while (serialPort.BytesToRead >= 285)
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);
} catch (InvalidOperationException) {
foreach (Sensor sensor in active)
sensor.Value = null;
}
}
public void Close() {
if (serialPort.IsOpen)
serialPort.Close();
}

View File

@ -76,6 +76,7 @@
<Compile Include="Hardware\HDD\HDD.cs" />
<Compile Include="Hardware\HDD\HDDGroup.cs" />
<Compile Include="Hardware\HDD\SMART.cs" />
<Compile Include="Hardware\IComputer.cs" />
<Compile Include="Hardware\IParameter.cs" />
<Compile Include="Hardware\LPC\Chip.cs" />
<Compile Include="Hardware\LPC\F718XX.cs" />