mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
fix #185. Loading index cache on startup.
This commit is contained in:
45
Wox.Infrastructure/Storage/BinaryStorage.cs
Normal file
45
Wox.Infrastructure/Storage/BinaryStorage.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
{
|
||||
/// <summary>
|
||||
/// Stroage object using binary data
|
||||
/// Normally, it has better performance, but not readable
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public abstract class BinaryStorage<T> : BaseStorage<T> where T : class, IStorage, new()
|
||||
{
|
||||
protected override string FileSuffix
|
||||
{
|
||||
get { return ".dat"; }
|
||||
}
|
||||
|
||||
protected override void LoadInternal()
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream fileStream = new FileStream(ConfigPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||
serializedObject = binaryFormatter.Deserialize(fileStream) as T;
|
||||
fileStream.Close();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
serializedObject = LoadDefault();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SaveInternal()
|
||||
{
|
||||
FileStream fileStream = new FileStream(ConfigPath, FileMode.Create);
|
||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||
binaryFormatter.Serialize(fileStream, serializedObject);
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user