// Loads the default language. If the language does not exist, it will create a default one.
 public void LoadDefaultLanguage(string languageId)
 {
     if (!CheckLanguageWithIdIsValid(languageId))
     {
         Console.WriteLine(string.Format("Language with ID {0} does not exist. Creating language file.", languageId));
         JsonIO.CreateDefaultFile(FileTypeEnum.FT_LANGUAGE);
         LoadLanguages();
     }
     Program.language = GetLanguageById(languageId);
 }
 // Loads in the config file.
 // Checks if a default language is listed. If not, we call SetDefaultLanguage.
 public void LoadConfigFile()
 {
     config = JsonIO.ReadConfigFile();
     try
     {
         if (config.defaultLanguage.Trim().Equals(""))
         {
             //Console.WriteLine("Default language is invalid. Setting default langauge.");
             SetDefaultLanguage("English");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error reading config file. Error: {0}", e);
     }
 }
        // Loads all languages in the /languages folder.
        public void LoadLanguages()
        {
            LangFileObject languageFile;

            //Console.WriteLine(string.Format("Language files found: {0}", Directory.GetFiles(JsonIO.LANGUAGE_PATH).Length)); // Debug garbage.

            // checks to see if the directory exists. If not, we will create it.
            if (!Directory.Exists(JsonIO.LANGUAGE_PATH))
            {
                Directory.CreateDirectory(JsonIO.LANGUAGE_PATH);
            }

            try {
                // We'll clear the list of languages first, in case we're reloading.
                languageFiles.Clear();

                // We run through the list of language JSON files in the languages folder.
                foreach (string path in Directory.GetFiles(JsonIO.LANGUAGE_PATH))
                {
                    if (path.Contains(".json")) // If it's a .json file...
                    {
                        // Create a new language object. If this isn't here, the languageFile data and ID are never updated.
                        languageFile = new LangFileObject();
                        // Console.WriteLine("Language file: {0}", path); // Debug garbage.
                        languageFile.data = JsonIO.ReadJsonFile(path, false).data;
                        languageFile.id   = languageFile.GetValue(LanguageFileConsts.KEY_LANGUAGE);

                        // Make sure we're not loading a duplicate.
                        if (!CheckLanguageWithIdIsValid(languageFile.id))
                        {
                            languageFiles.Add(languageFile);
                        }
                        else
                        {
                            Console.WriteLine("Language file with this ID already exists.");
                        }
                    }
                }
            } catch (Exception e)
            {
                Console.WriteLine(string.Format("Unable to load language files. Error: {0}", e));
            }
        }
 // Sets the config file's default language in memory, and writes it to the config file.
 public void SetDefaultLanguage(string id)
 {
     config.defaultLanguage = id;
     JsonIO.WriteConfigFile(ref config);
 }