public static void LoadSettings(Game game)
{
try
{
Settings settings;
//If config does not exist, create it and write the default settings
if (!File.Exists(configFile)) {
SaveAndApplyDefault(game);
return;
}
string json = File.ReadAllText(configFile);
//If config is empty, regenerate it
if (string.IsNullOrWhiteSpace(json)) {
SaveAndApplyDefault(game);
return;
}
settings = JsonConvert.DeserializeObject<Settings>(json);
ApplySettings(settings, game);
}
catch (Exception ex)
{
#if DEBUG
throw ex;
#else
System.Windows.Forms.MessageBox.Show(ex.Message + "\nTry deleting your config file!", game.Window.Title + " Configuration Error");
//Default fallback settings
ApplySettings(Settings.GetDefaultSettings(), game);
#endif
}
}