From d993d7c13a62db6f8c55b1f8e77b52df94702562 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Mon, 17 May 2021 17:54:08 +0200 Subject: [PATCH] Sort JSON config on save, null check --- Code/IO/Config.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Code/IO/Config.cs b/Code/IO/Config.cs index 4e26f23..748e369 100644 --- a/Code/IO/Config.cs +++ b/Code/IO/Config.cs @@ -40,7 +40,8 @@ namespace Flowframes.IO private static void WriteConfig() { - File.WriteAllText(configPath, JsonConvert.SerializeObject(cachedValues, Formatting.Indented)); + SortedDictionary cachedValuesSorted = new SortedDictionary(cachedValues); + File.WriteAllText(configPath, JsonConvert.SerializeObject(cachedValuesSorted, Formatting.Indented)); } private static void Reload() @@ -50,6 +51,9 @@ namespace Flowframes.IO Dictionary newDict = new Dictionary(); Dictionary deserializedConfig = JsonConvert.DeserializeObject>(File.ReadAllText(configPath)); + if (deserializedConfig == null) + deserializedConfig = new Dictionary(); + foreach (KeyValuePair entry in deserializedConfig) newDict.Add(entry.Key, entry.Value);