mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-09-03 15:55:26 +00:00
Added an event handler to save the configuration when the user logs off without closing the application first (http://blogs.msdn.com/b/oldnewthing/archive/2008/04/21/8413175.aspx), because FormClosed is not called in that case.
This commit is contained in:
@@ -38,7 +38,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
@@ -173,8 +173,14 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
|
|
||||||
// Create a handle, otherwise calling Close() does not fire FormClosed
|
// Create a handle, otherwise calling Close() does not fire FormClosed
|
||||||
IntPtr handle = Handle;
|
IntPtr handle = Handle;
|
||||||
}
|
|
||||||
|
|
||||||
|
// Make sure the settings are saved when the user logs off
|
||||||
|
Microsoft.Win32.SystemEvents.SessionEnded +=
|
||||||
|
delegate(object sender, Microsoft.Win32.SessionEndedEventArgs e) {
|
||||||
|
SaveConfiguration();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private void SubHardwareAdded(IHardware hardware, Node node) {
|
private void SubHardwareAdded(IHardware hardware, Node node) {
|
||||||
Node hardwareNode = new HardwareNode(hardware);
|
Node hardwareNode = new HardwareNode(hardware);
|
||||||
node.Nodes.Add(hardwareNode);
|
node.Nodes.Add(hardwareNode);
|
||||||
@@ -262,8 +268,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
sensorSystemTray.Redraw();
|
sensorSystemTray.Redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
|
private void SaveConfiguration() {
|
||||||
|
|
||||||
Config.Set(hiddenMenuItem.Name, hiddenMenuItem.Checked);
|
Config.Set(hiddenMenuItem.Name, hiddenMenuItem.Checked);
|
||||||
Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
|
Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
|
||||||
|
|
||||||
@@ -274,7 +279,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
|
|
||||||
Config.Set(startMinMenuItem.Name, startMinMenuItem.Checked);
|
Config.Set(startMinMenuItem.Name, startMinMenuItem.Checked);
|
||||||
Config.Set(minTrayMenuItem.Name, minTrayMenuItem.Checked);
|
Config.Set(minTrayMenuItem.Name, minTrayMenuItem.Checked);
|
||||||
Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
|
Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
|
||||||
|
|
||||||
if (WindowState != FormWindowState.Minimized) {
|
if (WindowState != FormWindowState.Minimized) {
|
||||||
Config.Set("mainForm.Location.X", Location.X);
|
Config.Set("mainForm.Location.X", Location.X);
|
||||||
@@ -283,12 +288,17 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
Config.Set("mainForm.Height", Height);
|
Config.Set("mainForm.Height", Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (TreeColumn column in treeView.Columns)
|
foreach (TreeColumn column in treeView.Columns)
|
||||||
Config.Set("treeView.Columns." + column.Header + ".Width",
|
Config.Set("treeView.Columns." + column.Header + ".Width",
|
||||||
column.Width);
|
column.Width);
|
||||||
|
|
||||||
timer.Enabled = false;
|
Config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
|
||||||
|
SaveConfiguration();
|
||||||
|
|
||||||
|
timer.Enabled = false;
|
||||||
sensorSystemTray.Dispose();
|
sensorSystemTray.Dispose();
|
||||||
notifyIcon.Dispose();
|
notifyIcon.Dispose();
|
||||||
computer.Close();
|
computer.Close();
|
||||||
|
@@ -52,12 +52,10 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Management" />
|
<Reference Include="System.Management" />
|
||||||
<Reference Include="System.Web" />
|
<Reference Include="System.Web" />
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="GUI\CrashReportForm.cs">
|
<Compile Include="GUI\CrashReportForm.cs">
|
||||||
|
@@ -69,5 +69,5 @@ using System.Runtime.InteropServices;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("0.1.35.0")]
|
[assembly: AssemblyVersion("0.1.36.0")]
|
||||||
[assembly: AssemblyFileVersion("0.1.35.0")]
|
[assembly: AssemblyFileVersion("0.1.36.0")]
|
||||||
|
@@ -60,7 +60,7 @@ namespace OpenHardwareMonitor.Utilities {
|
|||||||
System.Configuration.ConfigurationUserLevel.None);
|
System.Configuration.ConfigurationUserLevel.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Config() {
|
private void SaveConfig() {
|
||||||
string tempName = Path.ChangeExtension(fileName, ".tmp");
|
string tempName = Path.ChangeExtension(fileName, ".tmp");
|
||||||
|
|
||||||
if (File.Exists(tempName))
|
if (File.Exists(tempName))
|
||||||
@@ -73,6 +73,10 @@ namespace OpenHardwareMonitor.Utilities {
|
|||||||
} catch (System.Configuration.ConfigurationErrorsException) { }
|
} catch (System.Configuration.ConfigurationErrorsException) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Save() {
|
||||||
|
instance.SaveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
public static Config Settings {
|
public static Config Settings {
|
||||||
get {
|
get {
|
||||||
return instance;
|
return instance;
|
||||||
|
Reference in New Issue
Block a user