Exemple #1
0
        public static void Reload()
        {
            ready  = false;
            plugin = SCPDiscord.plugin;

            // 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)
            {
                if (e is DirectoryNotFoundException)
                {
                    plugin.Error("Language directory not found.");
                }
                else if (e is UnauthorizedAccessException)
                {
                    plugin.Error("Primary language file access denied.");
                }
                else if (e is FileNotFoundException)
                {
                    plugin.Error("'" + Config.GetString("settings.language") + ".yml' was not found.");
                }
                else if (e is JsonReaderException || e is YamlException)
                {
                    plugin.Error("'" + Config.GetString("settings.language") + ".yml' formatting error.");
                }
                plugin.Error("Error reading language file '" + 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)
                {
                    if (e is DirectoryNotFoundException)
                    {
                        plugin.Error("Language directory not found.");
                    }
                    else if (e is UnauthorizedAccessException)
                    {
                        plugin.Error("Backup language file access denied.");
                    }
                    else if (e is FileNotFoundException)
                    {
                        plugin.Error("'" + Config.GetString("settings.language") + ".yml' was not found.");
                    }
                    else if (e is JsonReaderException || e is YamlException)
                    {
                        plugin.Error("'" + Config.GetString("settings.language") + ".yml' formatting error.");
                    }
                    plugin.Error("Error reading backup language file 'english.yml'.");
                    plugin.Debug(e.ToString());
                }
            }
            if (primary == null && backup == null)
            {
                plugin.Error("NO LANGUAGE FILE LOADED! DEACTIVATING SCPDISCORD.");
                plugin.Disable();
            }

            ValidateLanguageStrings();

            ready = true;
        }
        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;
        }