From b8864224165d187a284f0a9300b062fe10b5c5f6 Mon Sep 17 00:00:00 2001 From: Boris Makogonyuk Vasylev Date: Fri, 22 Dec 2017 16:59:55 +0100 Subject: [PATCH] Added file length check before loading cache and removed BinaryStorage.Save when file was already locked. --- Wox.Infrastructure/Storage/BinaryStorage.cs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Wox.Infrastructure/Storage/BinaryStorage.cs b/Wox.Infrastructure/Storage/BinaryStorage.cs index 1c49714bd2..d2c5a2da82 100644 --- a/Wox.Infrastructure/Storage/BinaryStorage.cs +++ b/Wox.Infrastructure/Storage/BinaryStorage.cs @@ -30,19 +30,17 @@ namespace Wox.Infrastructure.Storage { if (File.Exists(FilePath)) { + if (new FileInfo(FilePath).Length == 0) + { + Log.Error($"|BinaryStorage.TryLoad|Zero length cache file <{FilePath}>"); + Save(defaultData); + return defaultData; + } + using (var stream = new FileStream(FilePath, FileMode.Open)) { - if (stream.Length > 0) - { - var d = Deserialize(stream, defaultData); - return d; - } - else - { - Log.Error($"|BinaryStorage.TryLoad|Zero length cache file <{FilePath}>"); - Save(defaultData); - return defaultData; - } + var d = Deserialize(stream, defaultData); + return d; } } else