private void LoadPage() { #region GetAvailableLanguages string saveDir = Directory.GetCurrentDirectory(); bool ErrorsFound = false; if (Directory.GetFiles(saveDir + "/Languages").Length > 1) { foreach (var file in Directory.GetFiles(saveDir + "/Languages", "*.lang")) { StreamReader langReader = new StreamReader(file); string rawObj = langReader.ReadToEnd(); try { LanguageDataModel tempObj = JsonConvert.DeserializeObject <LanguageDataModel>(rawObj); if (tempObj != null) { AvailableLanguages.Add(tempObj); } // MessageBox.Show(file); } catch (Exception ex) { MessageBox.Show(ex.Message); ErrorsFound = true; } } if (ErrorsFound) { MessageBox.Show("Errors Found"); } } else { SelectedLanguage = new LanguageDataModel(); } #endregion #region LoadSavedSettings if (File.Exists("Settings/settings.json")) { StreamReader settingsReader = new StreamReader("Settings/settings.json"); try { SettingsDataModel serializedData = JsonConvert.DeserializeObject <SettingsDataModel>(settingsReader.ReadToEnd()); // MessageBox.Show("loaded"); SelectedLanguage = AvailableLanguages.Single(lang => lang.LanguageName == serializedData.SelectedLanguage.LanguageName); if (SelectedLanguage == null) { SelectedLanguage = new LanguageDataModel(); } SelectedLanguageIndex = AvailableLanguages.IndexOf(SelectedLanguage); HomeLocation = serializedData.HomeLocation; SelectedUnitIndex = Units.IndexOf(serializedData.Unit); }catch (Exception) { SelectedLanguage = new LanguageDataModel(); } settingsReader.Dispose(); } #endregion }