Beispiel #1
0
        /// <summary>
        /// Loads the plugin settings from TSGeoIP\TSGeoIP.json.
        /// </summary>
        public static void LoadSettings()
        {
            try {
                string json_string = File.ReadAllText(TSGeoIP.DataDir + "TSGeoIP.json");
                if (IsJSONValid(json_string))
                {
                    var s = new JsonSerializerSettings();
                    s.NullValueHandling      = NullValueHandling.Ignore;
                    s.ObjectCreationHandling = ObjectCreationHandling.Replace;                     // without this, you end up with duplicates.

                    TSGeoIP.ISettings = JsonConvert.DeserializeObject <Settings>(json_string, s);
                    //TSGeoIP.ConsoleLOG(TSGeoIP.iSettings.PrefixString);
                }
                else
                {
                    SaveSettting();
                    TSGeoIP.ConsoleLOG("Created the new settings!");
                    LoadSettings();
                    TSGeoIP.ConsoleLOG("Loaded the new settings!");
                }
            } catch (Exception) {
                TSGeoIP.ConsoleLOG("No setting found!");
                SaveSettting();
                TSGeoIP.ConsoleLOG("Created the settings!");
                LoadSettings();
                TSGeoIP.ConsoleLOG("Loaded the settings!");
            }
        }
Beispiel #2
0
 /// <summary>
 /// Given the JSON string, validates if it's a correct
 /// JSON string.
 /// </summary>
 /// <param name="json_string">JSON string to validate.</param>
 /// <returns>true or false.</returns>
 public static bool IsJSONValid(string json_string)
 {
     try {
         JToken.Parse(json_string);
         return(true);
     } catch (JsonReaderException) {
         TSGeoIP.ConsoleLOG("The json file wasn't valid!");
         return(false);
     }
 }