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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="OnAppStartup" Startup="OnAppStartup"
Deactivated="OnAppDeactivated" Deactivated="OnAppDeactivated">
Exit="OnAppExit">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>

View file

@ -119,16 +119,8 @@ namespace SourceGit {
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void OnAppDeactivated(object sender, EventArgs e) { 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(); Git.Preference.Save();
GC.Collect();
} }
} }
} }

View file

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

View file

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