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.
authormoel.mich
Tue, 25 May 2010 22:33:03 +0000
changeset 128cea5477b4d72
parent 127 76aaf45a01c7
child 129 efb1b414d33e
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.
GUI/CrashReportForm.cs
GUI/MainForm.cs
OpenHardwareMonitor.csproj
Properties/AssemblyInfo.cs
Utilities/Config.cs
     1.1 --- a/GUI/CrashReportForm.cs	Tue May 25 18:57:28 2010 +0000
     1.2 +++ b/GUI/CrashReportForm.cs	Tue May 25 22:33:03 2010 +0000
     1.3 @@ -38,7 +38,6 @@
     1.4  using System;
     1.5  using System.Collections.Generic;
     1.6  using System.ComponentModel;
     1.7 -using System.Data;
     1.8  using System.Drawing;
     1.9  using System.IO;
    1.10  using System.Net;
     2.1 --- a/GUI/MainForm.cs	Tue May 25 18:57:28 2010 +0000
     2.2 +++ b/GUI/MainForm.cs	Tue May 25 22:33:03 2010 +0000
     2.3 @@ -173,8 +173,14 @@
     2.4  
     2.5        // Create a handle, otherwise calling Close() does not fire FormClosed     
     2.6        IntPtr handle = Handle;
     2.7 +
     2.8 +      // Make sure the settings are saved when the user logs off
     2.9 +      Microsoft.Win32.SystemEvents.SessionEnded +=
    2.10 +        delegate(object sender, Microsoft.Win32.SessionEndedEventArgs e) {
    2.11 +          SaveConfiguration();
    2.12 +        };
    2.13      }
    2.14 -
    2.15 +    
    2.16      private void SubHardwareAdded(IHardware hardware, Node node) {
    2.17        Node hardwareNode = new HardwareNode(hardware);
    2.18        node.Nodes.Add(hardwareNode);
    2.19 @@ -262,8 +268,7 @@
    2.20        sensorSystemTray.Redraw();
    2.21      }
    2.22  
    2.23 -    private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
    2.24 -      
    2.25 +    private void SaveConfiguration() {
    2.26        Config.Set(hiddenMenuItem.Name, hiddenMenuItem.Checked);
    2.27        Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
    2.28  
    2.29 @@ -274,7 +279,7 @@
    2.30  
    2.31        Config.Set(startMinMenuItem.Name, startMinMenuItem.Checked);
    2.32        Config.Set(minTrayMenuItem.Name, minTrayMenuItem.Checked);
    2.33 -      Config.Set(hddMenuItem.Name, hddMenuItem.Checked);   
    2.34 +      Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
    2.35  
    2.36        if (WindowState != FormWindowState.Minimized) {
    2.37          Config.Set("mainForm.Location.X", Location.X);
    2.38 @@ -283,12 +288,17 @@
    2.39          Config.Set("mainForm.Height", Height);
    2.40        }
    2.41  
    2.42 -      foreach (TreeColumn column in treeView.Columns) 
    2.43 -        Config.Set("treeView.Columns." + column.Header + ".Width", 
    2.44 +      foreach (TreeColumn column in treeView.Columns)
    2.45 +        Config.Set("treeView.Columns." + column.Header + ".Width",
    2.46            column.Width);
    2.47  
    2.48 +      Config.Save();
    2.49 +    }
    2.50 +
    2.51 +    private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
    2.52 +      SaveConfiguration();
    2.53 +
    2.54        timer.Enabled = false;
    2.55 -
    2.56        sensorSystemTray.Dispose();
    2.57        notifyIcon.Dispose();
    2.58        computer.Close();
     3.1 --- a/OpenHardwareMonitor.csproj	Tue May 25 18:57:28 2010 +0000
     3.2 +++ b/OpenHardwareMonitor.csproj	Tue May 25 22:33:03 2010 +0000
     3.3 @@ -52,12 +52,10 @@
     3.4      </Reference>
     3.5      <Reference Include="System" />
     3.6      <Reference Include="System.Configuration" />
     3.7 -    <Reference Include="System.Data" />
     3.8      <Reference Include="System.Drawing" />
     3.9      <Reference Include="System.Management" />
    3.10      <Reference Include="System.Web" />
    3.11      <Reference Include="System.Windows.Forms" />
    3.12 -    <Reference Include="System.Xml" />
    3.13    </ItemGroup>
    3.14    <ItemGroup>
    3.15      <Compile Include="GUI\CrashReportForm.cs">
     4.1 --- a/Properties/AssemblyInfo.cs	Tue May 25 18:57:28 2010 +0000
     4.2 +++ b/Properties/AssemblyInfo.cs	Tue May 25 22:33:03 2010 +0000
     4.3 @@ -69,5 +69,5 @@
     4.4  // You can specify all the values or you can default the Build and Revision Numbers 
     4.5  // by using the '*' as shown below:
     4.6  // [assembly: AssemblyVersion("1.0.*")]
     4.7 -[assembly: AssemblyVersion("0.1.35.0")]
     4.8 -[assembly: AssemblyFileVersion("0.1.35.0")]
     4.9 +[assembly: AssemblyVersion("0.1.36.0")]
    4.10 +[assembly: AssemblyFileVersion("0.1.36.0")]
     5.1 --- a/Utilities/Config.cs	Tue May 25 18:57:28 2010 +0000
     5.2 +++ b/Utilities/Config.cs	Tue May 25 22:33:03 2010 +0000
     5.3 @@ -60,7 +60,7 @@
     5.4          System.Configuration.ConfigurationUserLevel.None);
     5.5      }
     5.6  
     5.7 -    ~Config() {
     5.8 +    private void SaveConfig() {
     5.9        string tempName = Path.ChangeExtension(fileName, ".tmp");
    5.10  
    5.11        if (File.Exists(tempName))
    5.12 @@ -73,6 +73,10 @@
    5.13        } catch (System.Configuration.ConfigurationErrorsException) { }
    5.14      }
    5.15  
    5.16 +    public static void Save() {
    5.17 +      instance.SaveConfig();
    5.18 +    }
    5.19 +
    5.20      public static Config Settings {
    5.21        get {
    5.22          return instance;