diff --git a/FileManager/PersistentDictionary.cs b/FileManager/PersistentDictionary.cs index bbbd46e6..963b51a4 100644 --- a/FileManager/PersistentDictionary.cs +++ b/FileManager/PersistentDictionary.cs @@ -30,8 +30,7 @@ namespace FileManager if (IsReadOnly) return; - File.WriteAllText(Filepath, "{}"); - System.Threading.Thread.Sleep(100); + createNewFile(); } public string GetString(string propertyName) @@ -214,6 +213,13 @@ namespace FileManager } var settingsJsonContents = File.ReadAllText(Filepath); + + if (string.IsNullOrWhiteSpace(settingsJsonContents)) + { + createNewFile(); + settingsJsonContents = File.ReadAllText(Filepath); + } + var jObject = JsonConvert.DeserializeObject(settingsJsonContents); if (jObject is null) @@ -226,5 +232,11 @@ namespace FileManager return jObject; } + + private void createNewFile() + { + File.WriteAllText(Filepath, "{}"); + System.Threading.Thread.Sleep(100); + } } }