Fix crash due to load invalid preference.xml

This commit is contained in:
leo 2020-07-16 09:26:21 +08:00
parent a82943d649
commit b5002cb89d
4 changed files with 10 additions and 16 deletions

View file

@ -2,8 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="OnAppStartup"
Deactivated="OnAppDeactivated"
Exit="OnAppExit">
Deactivated="OnAppDeactivated">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

View file

@ -119,16 +119,8 @@ namespace SourceGit {
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnAppDeactivated(object sender, EventArgs e) {
GC.Collect();
}
/// <summary>
/// Quit event.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnAppExit(object sender, ExitEventArgs e) {
Git.Preference.Save();
GC.Collect();
}
}
}

View file

@ -134,10 +134,14 @@ namespace SourceGit.Git {
return;
}
try {
var stream = new FileStream(SAVE_PATH, FileMode.Open);
var reader = new XmlSerializer(typeof(Preference));
instance = (Preference)reader.Deserialize(stream);
stream.Close();
} catch {
instance = new Preference();
}
}
/// <summary>

View file

@ -4,7 +4,6 @@ using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Windows.Threading;
using System.Xml.Serialization;