public static void Reload() { ready = false; plugin = SCPDiscord.plugin; languagesPath = FileManager.GetAppFolder(true, !plugin.GetConfigBool("scpdiscord_languages_global")) + "SCPDiscord/Languages/"; // Save default language files SaveDefaultLanguages(); // Read primary language file plugin.Info("Loading primary language file..."); try { LoadLanguageFile(Config.GetString("settings.language"), false); } catch (Exception e) { switch (e) { case DirectoryNotFoundException _: plugin.Error("Language directory not found."); break; case UnauthorizedAccessException _: plugin.Error("Primary language file access denied."); break; case FileNotFoundException _: plugin.Error("'" + languagesPath + Config.GetString("settings.language") + ".yml' was not found."); break; case JsonReaderException _: case YamlException _: plugin.Error("'" + languagesPath + Config.GetString("settings.language") + ".yml' formatting error."); break; } plugin.Error("Error reading primary language file '" + languagesPath + Config.GetString("settings.language") + ".yml'. Attempting to initialize backup system..."); plugin.Debug(e.ToString()); } // Read backup language file if not the same as the primary if (Config.GetString("settings.language") != "english") { plugin.Info("Loading backup language file..."); try { LoadLanguageFile("english", true); } catch (Exception e) { switch (e) { case DirectoryNotFoundException _: plugin.Error("Language directory not found."); break; case UnauthorizedAccessException _: plugin.Error("Backup language file access denied."); break; case FileNotFoundException _: plugin.Error("'" + languagesPath + Config.GetString("settings.language") + ".yml' was not found."); break; case JsonReaderException _: case YamlException _: plugin.Error("'" + languagesPath + Config.GetString("settings.language") + ".yml' formatting error."); break; } plugin.Error("Error reading backup language file '" + languagesPath + "english.yml'."); plugin.Debug(e.ToString()); } } if (primary == null && backup == null) { plugin.Error("NO LANGUAGE FILE LOADED! DEACTIVATING SCPDISCORD."); plugin.Disable(); } if (Config.GetBool("settings.verbose")) { ValidateLanguageStrings(); } ready = true; }
internal static void Reload(SCPDiscord plugin) { ready = false; plugin.SetUpFileSystem(); // Reads file contents into FileStream FileStream stream = File.OpenRead(FileManager.GetAppFolder(true, !plugin.GetConfigBool("scpdiscord_config_global")) + "SCPDiscord/config.yml"); // Converts the FileStream into a YAML Dictionary object IDeserializer deserializer = new DeserializerBuilder().Build(); object yamlObject = deserializer.Deserialize(new StreamReader(stream)); // Converts the YAML Dictionary into JSON String ISerializer serializer = new SerializerBuilder() .JsonCompatible() .Build(); string jsonString = serializer.Serialize(yamlObject); JObject json = JObject.Parse(jsonString); plugin.Verbose("Reading config validation"); // Reads the configvalidation node first as it is used for reading the others try { configBools["settings.configvalidation"] = json.SelectToken("settings.configvalidation").Value <bool>(); } catch (ArgumentNullException) { plugin.Warn("Config bool 'settings.configvalidation' not found, using default value: true"); } // Read config strings foreach (KeyValuePair <string, string> node in configStrings.ToList()) { try { configStrings[node.Key] = json.SelectToken(node.Key).Value <string>(); } catch (ArgumentNullException) { plugin.Warn("Config string '" + node.Key + "' not found, using default value: \"" + node.Value + "\""); } } // Read config ints foreach (KeyValuePair <string, int> node in configInts.ToList()) { try { configInts[node.Key] = json.SelectToken(node.Key).Value <int>(); } catch (ArgumentNullException) { plugin.Warn("Config int '" + node.Key + "' not found, using default value: \"" + node.Value + "\""); } } // Read config bools foreach (KeyValuePair <string, bool> node in configBools.ToList().Where(kvm => kvm.Key != "settings.configvalidation")) { try { configBools[node.Key] = json.SelectToken(node.Key).Value <bool>(); } catch (ArgumentNullException) { plugin.Warn("Config bool '" + node.Key + "' not found, using default value: " + node.Value); } } // Read config arrays foreach (KeyValuePair <string, string[]> node in configArrays.ToList()) { try { configArrays[node.Key] = json.SelectToken(node.Key).Value <JArray>().Values <string>().ToArray(); } catch (ArgumentNullException) { plugin.Warn("Config array '" + node.Key + "' not found, using default value: []"); } } // Read config dictionaries foreach (KeyValuePair <string, Dictionary <string, ulong> > node in configDicts.ToList()) { try { configDicts[node.Key] = json.SelectToken(node.Key).Value <JArray>().ToDictionary(k => ((JObject)k).Properties().First().Name, v => v.Values().First().Value <ulong>()); } catch (ArgumentNullException) { plugin.Warn("Config dictionary '" + node.Key + "' not found, using default value: []"); } } // Read rolesync system if (GetBool("settings.rolesync")) { try { plugin.roleSync.roleDictionary = json.SelectToken("rolesync").Value <JArray>().ToDictionary(k => ulong.Parse(((JObject)k).Properties().First().Name), v => v.Values().First().Value <JArray>().Values <string>().ToArray()); } catch (Exception) { plugin.Warn("The rolesync config list is invalid, rolesync disabled."); SetBool("settings.rolesync", false); } } if (GetBool("settings.configvalidation") && GetBool("settings.verbose")) { ValidateConfig(plugin); } ready = true; }
public void Reload() { plugin.SetUpFileSystem(); syncedPlayers = JArray.Parse(File.ReadAllText(FileManager.GetAppFolder(plugin.GetConfigBool("scpdiscord_rolesync_global")) + "SCPDiscord/rolesync.json")).ToDictionary(k => ((JObject)k).Properties().First().Name, v => v.Values().First().Value <string>()); plugin.Info("Successfully loaded config '" + FileManager.GetAppFolder(plugin.GetConfigBool("scpdiscord_rolesync_global")) + "SCPDiscord/rolesync.json'."); }