Add an error check for invalid JSON when importing a configuration.

master
Glenn Maynard 5 years ago
parent 219f407246
commit f7453a1600
  1. 8
      smx-config/Helpers.cs
  2. 3
      smx-config/SMXJSON.cs

@ -918,7 +918,13 @@ namespace smx_config
// Import a saved JSON configuration to an SMXConfig. // Import a saved JSON configuration to an SMXConfig.
public static void ImportSettingsFromJSON(string json, ref SMX.SMXConfig config) public static void ImportSettingsFromJSON(string json, ref SMX.SMXConfig config)
{ {
Dictionary<string, Object> dict = SMXJSON.ParseJSON.Parse<Dictionary<string, Object>>(json); Dictionary<string, Object> dict;
try {
dict = SMXJSON.ParseJSON.Parse<Dictionary<string, Object>>(json);
} catch(ParseError e) {
MessageBox.Show(e.Message, "Error importing configuration", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
// Read the thresholds. If any values are missing, we'll leave the value in config alone. // Read the thresholds. If any values are missing, we'll leave the value in config alone.
if(config.fsr()) if(config.fsr())

@ -9,7 +9,8 @@ namespace SMXJSON
{ {
public class JSONError: Exception public class JSONError: Exception
{ {
public JSONError(string error) public JSONError(string error):
base(error)
{ {
} }
}; };

Loading…
Cancel
Save