bug fix #228 : recover from corrupt BookTags.json

This commit is contained in:
Robert McRackan 2022-04-12 09:16:02 -04:00
parent c95feebd39
commit 2e4c4cf5f7
2 changed files with 12 additions and 6 deletions

View File

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Version>6.7.5.1</Version> <Version>6.7.6.2</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -54,11 +54,17 @@ namespace LibationFileManager
private static void ensureCache() private static void ensureCache()
{ {
if (cache is null) if (cache is not null)
return;
lock (locker) lock (locker)
cache = !File.Exists(TagsFile) {
? new Dictionary<string, string>() if (File.Exists(TagsFile))
: JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(TagsFile)); cache = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(TagsFile));
// if file doesn't exist. or if file is corrupt and deserialize returns null
cache ??= new Dictionary<string, string>();
}
} }
} }
} }