(GUI): settings upgrade moved to ApplicationStartup handler.

This commit is contained in:
morkt 2016-06-14 18:10:27 +04:00
parent 95e7aa7614
commit 7920af7fe9
2 changed files with 25 additions and 16 deletions

View File

@ -48,6 +48,8 @@ namespace GARbro.GUI
void ApplicationStartup (object sender, StartupEventArgs e)
{
UpgradeSettings();
string exe_dir = Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly().Location);
#if DEBUG
Trace.Listeners.Add (new TextWriterTraceListener (Path.Combine (exe_dir, "trace.log")));
@ -86,7 +88,7 @@ namespace GARbro.GUI
}
catch (Exception X)
{
Trace.WriteLine (X.Message, "scheme deserialization failed");
Trace.WriteLine (string.Format ("Scheme deserialization failed: {0}", X.Message), "[GARbro.GUI.App]");
}
}
@ -95,6 +97,27 @@ namespace GARbro.GUI
Settings.Default.Save();
}
void UpgradeSettings ()
{
if (Settings.Default.UpgradeRequired)
{
try
{
Settings.Default.Upgrade();
Settings.Default.UpgradeRequired = false;
Settings.Default.Save();
}
catch (System.Exception X)
{
Trace.WriteLine (string.Format ("Settings upgrade failed: {0}", X.Message), "[GARbro.GUI.App]");
}
}
// do not restore in minimized state
if (Settings.Default.winState == System.Windows.WindowState.Minimized)
Settings.Default.winState = System.Windows.WindowState.Normal;
}
void DeserializeScheme (Stream file)
{
using (var reader = new BinaryReader (file))

View File

@ -15,21 +15,7 @@
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
this.SettingsLoaded += OnSettingsLoadedHandler;
}
void OnSettingsLoadedHandler (object sender, System.Configuration.SettingsLoadedEventArgs e)
{
if (Settings.Default.UpgradeRequired)
{
Settings.Default.Upgrade();
Settings.Default.UpgradeRequired = false;
Settings.Default.Save();
}
// do not restore in minimized state
if (Settings.Default.winState == System.Windows.WindowState.Minimized)
Settings.Default.winState = System.Windows.WindowState.Normal;
// this.SettingsLoaded += OnSettingsLoadedHandler;
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {