From d5e0ebc378b195050205f1de883623d02ade92e6 Mon Sep 17 00:00:00 2001 From: alkl58 Date: Tue, 21 Feb 2023 23:27:40 +0100 Subject: [PATCH] Catch empty settings.json file --- NotEnoughAV1Encodes/MainWindow.xaml.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/NotEnoughAV1Encodes/MainWindow.xaml.cs b/NotEnoughAV1Encodes/MainWindow.xaml.cs index 140c604..8ad0681 100644 --- a/NotEnoughAV1Encodes/MainWindow.xaml.cs +++ b/NotEnoughAV1Encodes/MainWindow.xaml.cs @@ -95,7 +95,21 @@ private void Initialize() TextBoxWorkerCount.Text = coreCount.ToString(); // Load Settings from JSON - try { settingsDB = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(Global.AppData, "NEAV1E", "settings.json"))); } catch { } + try + { + settingsDB = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(Global.AppData, "NEAV1E", "settings.json"))); + + if (settingsDB == null) + { + settingsDB = new(); + MessageBox.Show("Program Settings File under %appdata%\\NEAV1E\\settings.json corrupted.\nProgram Settings has been reset.\nPresets are not affected.","That shouldn't have happened!"); + try + { + File.WriteAllText(Path.Combine(Global.AppData, "NEAV1E", "settings.json"), JsonConvert.SerializeObject(settingsDB, Formatting.Indented)); + } + catch (Exception ex) { MessageBox.Show(ex.Message); } + } + } catch { } LoadSettings();