Skip to content

Commit

Permalink
Catch empty settings.json file
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkl58 committed Feb 21, 2023
1 parent c8d009b commit d5e0ebc
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion NotEnoughAV1Encodes/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,21 @@ private void Initialize()
TextBoxWorkerCount.Text = coreCount.ToString();

// Load Settings from JSON
try { settingsDB = JsonConvert.DeserializeObject<Settings>(File.ReadAllText(Path.Combine(Global.AppData, "NEAV1E", "settings.json"))); } catch { }
try
{
settingsDB = JsonConvert.DeserializeObject<Settings>(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();

Expand Down

0 comments on commit d5e0ebc

Please sign in to comment.