internal void SaveCurrentSettings(bool checkForGeneralChanges) { SaveSettings(_currentSettings, GetCurrentSettingsFullName()); if (checkForGeneralChanges) { CheckForGeneralChanges(GetCurrentSettingsFullName()); } UpdateOutputFieldOnRunDialoguesIfDefault(); // check if the Run Dialogues need to update their output folder _bkupCurrentSettings = _currentSettings.Copy() as UserSettings; }
static void SaveSettings(UserSettings settings, string settingsPath) { try { if (!Directory.Exists(EnvironmentInfo.GetUserSettingsFolder())) { Directory.CreateDirectory(EnvironmentInfo.GetUserSettingsFolder()); //EUROMOD folder does not yet exist } Stream fileStream = new FileStream(settingsPath, FileMode.Create); UserSettings encSettings = settings.Copy() as UserSettings; using (XmlTextCDATAWriter xmlWriter = new XmlTextCDATAWriter(fileStream, DefGeneral.DEFAULT_ENCODING)) encSettings.WriteXml(xmlWriter); //MessageBox.Show("File created"); } catch (Exception exception) { Tools.UserInfoHandler.ShowException(exception); } }
internal void LoadCurrentSettings(string settingsPath = "", bool checkAndUpdatePath = false, string projectPath = "") { // if there is no AppData/Roaming folder but there is an AppData/Local folder from a previous version, then copy over all the settings files if (!Directory.Exists(EnvironmentInfo.GetUserSettingsFolder()) && Directory.Exists(oldLocalSettingsFolder())) { copyLocalSettings(); } if (_currentSettings != null && File.Exists(GetCurrentSettingsFullName())) //UI's current UserSettings are changed (i.e. a new project is loaded) { string anySettingsFullName = GetAnySettingsFullName(); File.Move(GetCurrentSettingsFullName(), anySettingsFullName); //move UserSettings.txt to GuidUserSettings.txt ... SaveSettings(_currentSettings, anySettingsFullName); //... and save any changes CheckForGeneralChanges(anySettingsFullName); //check if any of the (changed) settings should be transfered to all existing (project's) user settings } if (settingsPath != string.Empty && settingsPath != GetCurrentSettingsFullName())//should correspond to _currentUserSettings!=null (i.e. a new project is loaded) { if (checkAndUpdatePath && !File.Exists(settingsPath)) { List <string> pathsUserSettings = null; List <string> projectPaths = UserSettingsAdministrator.GetAvailableProjectPaths(out pathsUserSettings); if (projectPaths.Contains(projectPath)) { //loading a project with existing user-settings settingsPath = pathsUserSettings.ElementAt(projectPaths.IndexOf(projectPath)); } } File.Move(settingsPath, GetCurrentSettingsFullName()); //rename the corresponding settings-file from GuidUserSetting.txt to UserSetting.txt, to make it current } _currentSettings = ReadSettings(GetCurrentSettingsFullName()); _bkupCurrentSettings = _currentSettings.Copy() as UserSettings; EM_AppContext.Instance.GetVCAdministrator().InitButtons(); //request VCAdministrator to initialise }