mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 03:37:10 +08:00
Fix crash issues when deserialize failed
This commit is contained in:
parent
4243843951
commit
4d65b4c7a5
@ -79,7 +79,7 @@ namespace Wox.Infrastructure.Storage
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected virtual T LoadDefault()
|
protected virtual T LoadDefault()
|
||||||
{
|
{
|
||||||
return serializedObject;
|
return new T();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void LoadInternal();
|
protected abstract void LoadInternal();
|
||||||
|
@ -25,10 +25,20 @@ namespace Wox.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
using (FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
{
|
||||||
serializedObject = binaryFormatter.Deserialize(fileStream) as T;
|
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||||
fileStream.Close();
|
serializedObject = binaryFormatter.Deserialize(fileStream) as T;
|
||||||
|
if (serializedObject == null)
|
||||||
|
{
|
||||||
|
serializedObject = LoadDefault();
|
||||||
|
#if (DEBUG)
|
||||||
|
{
|
||||||
|
throw new Exception("deserialize failed");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -153,7 +153,7 @@ namespace Wox.Infrastructure.Storage.UserSettings
|
|||||||
{
|
{
|
||||||
DontPromptUpdateMsg = false;
|
DontPromptUpdateMsg = false;
|
||||||
Theme = "Dark";
|
Theme = "Dark";
|
||||||
Language = "English";
|
Language = "en";
|
||||||
ReplaceWinR = true;
|
ReplaceWinR = true;
|
||||||
WebSearches = LoadDefaultWebSearches();
|
WebSearches = LoadDefaultWebSearches();
|
||||||
ProgramSources = new List<ProgramSource>();
|
ProgramSources = new List<ProgramSource>();
|
||||||
@ -189,7 +189,7 @@ namespace Wox.Infrastructure.Storage.UserSettings
|
|||||||
}
|
}
|
||||||
if (storage.Language == null)
|
if (storage.Language == null)
|
||||||
{
|
{
|
||||||
storage.Language = "English";
|
storage.Language = "en";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user