/// <summary> /// Fermeture du programme /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ffs2play_FormClosing(object sender, FormClosingEventArgs e) { if (!pm.AutoExit) { DialogResult dialogResult = MessageBox.Show("Etes vous sûr de vouloir quitter ffs2play?", "Confirmation de sortie", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) { e.Cancel = true; return; } } P2P.Init(false); // On ferme la connexion avec simconnect scm.closeConnection(); // Sauvegarde du status de la fenêtre seulement normal ou maximised) switch (WindowState) { case FormWindowState.Normal: case FormWindowState.Maximized: Properties.Settings.Default.WindowState = WindowState; break; default: Properties.Settings.Default.WindowState = FormWindowState.Normal; break; } // Sauvegarde de la configuration settings.Save(); if (pm.IsConnected()) { pm.AutoExit = true; e.Cancel = true; pm.Disconnect(PirepManager.Disco_mode.Close); } }
public void Update <TSetting>(string settingName, TSetting settingValue) { if (!Contains(settingName)) { return; } _settings[settingName] = settingValue; _settings.Save(); }
/// <inheritdoc /> /// <summary> /// Set value of type T /// </summary> /// <param name="setting"></param> /// <param name="value"></param> public void Set(string setting, [NotNull] object value) { if (setting == null) { throw new ArgumentNullException(nameof(setting)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } _settingsBase[setting] = value ?? throw new ArgumentNullException(nameof(value)); _settingsBase.Save(); }
public static void DoUpgrade(ApplicationSettingsBase settings) { try { // attempt to read the upgrade flag if ((bool)settings[UpgradeFlag] == true) { // upgrade the settings to the latest version settings.Upgrade(); // clear the upgrade flag settings[UpgradeFlag] = false; settings.Save(); } else { // the settings are up to date } } catch (SettingsPropertyNotFoundException ex) { // notify the developer that the upgrade // flag should be added to the settings file throw ex; } }
private void Form_FormClosing(object sender, FormClosingEventArgs e) { if (_appSettings == null) { return; } PropertyInfo settingProperty = _appSettings.GetType().GetProperty(_settingName); if (settingProperty == null) { return; } WindowSettings previousSettings = settingProperty.GetValue(_appSettings, null) as WindowSettings; if (previousSettings == null) { previousSettings = new WindowSettings(); } previousSettings.Record(this); settingProperty.SetValue(_appSettings, previousSettings, null); _appSettings.Save(); }
public static void Add <T>(this ApplicationSettingsBase settings, string propertyName, T val) { if (settings.Properties[propertyName] != null) { return; } var p = new SettingsProperty(propertyName) { PropertyType = typeof(T), Provider = settings.Providers["LocalFileSettingsProvider"], SerializeAs = SettingsSerializeAs.String }; p.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute()); settings.Properties.Add(p); settings.Reload(); //finally set value with new value if none was loaded from userConfig.xml var item = settings[propertyName]; if (item == null) { settings[propertyName] = val; settings.Save(); } }
public void Save() { SavePluginsSettings(); SaveStateSettings(); SaveConfigsSettings(); _settings.Save(); }
private string AddNew(string key, string value) { ApplicationSettingsBase settings = Properties.Settings.Default; var p = new SettingsProperty(key) { PropertyType = typeof(string), Provider = settings.Providers["LocalFileSettingsProvider"], SerializeAs = SettingsSerializeAs.Xml }; p.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute()); settings.Properties.Add(p); settings.Reload(); //finally set value with new value if none was loaded from userConfig.xml var item = settings[key]; if (item == null) { settings[key] = value; settings.Save(); return(value); } else { return(item.ToString()); } }
public void OnSaveOptions() { _Saving = true; if (OptionsSaving != null) { OptionsSaving(this, EventArgs.Empty); } foreach (SettingsProperty sett in _Settings) { try { _AppSettings[sett.Name] = sett.DefaultValue; } catch { } } if (_AutomaticSaveSettings) { _AppSettings.Save(); _AppSettings.Reload(); if (OptionsSaved != null) { OptionsSaved(this, EventArgs.Empty); } } _Saving = false; }
public static void EnsureMaintainUserSettings(this ApplicationSettingsBase settings, string keyName) { if (settings == null) { return; } var keyValue = settings[keyName]; var defaultValue = settings.Properties[keyName]?.DefaultValue; if (keyValue != defaultValue) { return; } foreach (SettingsProperty prop in settings.Properties) { if (!prop.Attributes.ContainsKey(typeof(UserScopedSettingAttribute))) { continue; } var result = settings.GetPreviousVersion(prop.Name); settings[prop.Name] = result; } settings.Save(); }
/// <summary> /// IEnumerableなKeyValuePairでそれぞれ指定したプロパティ名へ値をセットして保存する /// </summary> /// <param name="settings"></param> /// <param name="keyValues">IEnumerableなプロパティ名と値のペア</param> public static void SaveSettings(ApplicationSettingsBase settings, IEnumerable <KeyValuePair <string, object> > keyValues) { foreach (var keyValue in keyValues) { settings[keyValue.Key] = keyValue.Value; } settings.Save(); }
public void SaveUnencryptedSetting(string settingName, string settingEntropyName, string plainTextValue) { (string cypherText, string entropy) = Encryption.Encrypt(plainTextValue); _settings[settingName] = cypherText; _settings[settingEntropyName] = entropy; _settings.Save(); }
/// <summary> /// 現在のアセンブリバージョンが指定バージョンより高ければSettingsをアップグレードして保存する /// </summary> /// <param name="settings"></param> /// <param name="version">比較するアセンブリバージョン</param> public static void UpgradeSettings(ApplicationSettingsBase settings, Version version) { var currentVersion = System.Reflection.Assembly.GetCallingAssembly().GetName().Version; if (version < currentVersion) { settings.Upgrade(); settings.Save(); } }
public static void SaveSettings() { try { Settings.Save(); } catch (Exception ex) { ExceptionManager.Register(ex, "The preferences were not saved properly.", "Could not save preferences."); ExceptionManager.ShowErrorDialog(false); } }
private static void SaveIfDirty(ApplicationSettingsBase settings) { foreach (SettingsPropertyValue property in settings.PropertyValues) { if (!property.IsDirty) { continue; } settings.Save(); return; } }
void ISettingsEngine.SetSetting(string key, string value) { ApplicationSettingsBase settings = Properties.Settings.Default; if (settings.Properties.Cast <SettingsProperty>().All(s => s.Name != key)) { AddNew(key, value); } else { settings[key] = value; settings.Save(); } }
public static DialogResult ShowDialogWithLastChosenValue(this FolderBrowserDialog dialog, ApplicationSettingsBase settings, string key) { _ = key ?? throw new ArgumentNullException(nameof(key)); _ = settings ?? throw new ArgumentNullException(nameof(settings)); _ = dialog ?? throw new ArgumentNullException(nameof(dialog)); return(dialog.ShowDialogWithLastChosenValue( settings[key].ToString(), path => { settings[key] = dialog.SelectedPath; settings.Save(); })); }
/// <summary> /// 指定したプロパティ名の値がfalseならSettingsをアップグレードして指定プロパティの値をtrueにして保存する /// </summary> /// <param name="settings"></param> /// <param name="isUpgratedPropertyName">アップグレードするかのフラグを持ったプロパティ名</param> public static void UpgradeSettings(ApplicationSettingsBase settings, string isUpgratedPropertyName) { var isUpgrated = settings[isUpgratedPropertyName]; if (!(isUpgrated is bool)) { return; } if (!(bool)isUpgrated) { settings.Upgrade(); settings[isUpgratedPropertyName] = true; settings.Save(); } }
private void SetValue <T>(string key, T value) { var entry = _settings.PropertyValues[key]; if (entry != null) { entry.PropertyValue = value; _settings.Save(); } else { throw new ConfigurationKeyNotFoundException(string.Format("Cannot set value to configuration for key {0}", key), key); } _eventAggregator.Publish(new ConfigurationChangedEvent(key, value)); }
/// <summary> /// 檢查更新時載入舊版本設定參數,請先建立參數 bool _SettingUpgrade = false /// </summary> /// <param name="settings"></param> static public void Run(ApplicationSettingsBase settings) { //檢查是否為新版本未更新參數值 if (Upgraded == false) { //從舊版本載入設定 settings.Upgrade(); //存檔 settings.Save(); //設定為已載入舊版本參數 Upgraded = true; } //重載入設定參數值 settings.Reload(); }
public static ControllerSettings GetControllerSettings(ApplicationSettingsBase settings, Type controllerType) { if (controllerType == null) { return(null); } string propKey = controllerType.FullName; Type settingsType = Controllers.GetControllerSettingsType(controllerType); if (settingsType == null) { return(null); } // Add entry for custom settings property (required for it to be accessable) var prop = new SettingsProperty(propKey); prop.DefaultValue = null; prop.IsReadOnly = false; prop.PropertyType = settingsType; // Must match the actual type being used for it to serialize properly prop.Provider = settings.Providers["LocalFileSettingsProvider"]; prop.Attributes.Add(typeof(System.Configuration.UserScopedSettingAttribute), new System.Configuration.UserScopedSettingAttribute()); prop.SerializeAs = SettingsSerializeAs.Xml; prop.ThrowOnErrorSerializing = true; prop.ThrowOnErrorDeserializing = true; try { settings.Properties.Add(prop); settings.Reload(); } catch (System.ArgumentException) { } // Ignore if it's already been added // Load the settings for the specific controller var conf = settings[propKey]; if (conf == null) { // Set defaults conf = (ControllerSettings)Activator.CreateInstance(settingsType); settings[propKey] = conf; settings.Save(); } return((ControllerSettings)conf); }
public void OnSaveOptions(CancelEventArgs e) { OnSaveOptionsStart(); _Saving = true; try { if (OptionsSaving != null) { OptionsSaving(this, e); } } catch { // string msg = ServiceManager.ErrorHandler.GetExceptionMessages(ex); // MessageBox.Show(msg, "Invalid setup item...", MessageBoxButtons.OK, MessageBoxIcon.Error); // CancelEventArgs cancelClose = (CancelEventArgs)e; // cancelClose.Cancel = true; } foreach (SettingsProperty sett in _Settings) { try { _AppSettings[sett.Name] = sett.DefaultValue; } catch { } } if (_AutomaticSaveSettings) { _AppSettings.Save(); _AppSettings.Reload(); if (OptionsSaved != null) { OptionsSaved(this, e); } } _Saving = false; OnSaveOptionsEnd(); }
public static Result SaveSizeAndPosition(this Window window, ApplicationSettingsBase settings, string name = "") { if (window == null) { return(Result.Failure("Windows was null")); } if (window.Name.IsEmpty() && name.IsEmpty()) { return(Result.Failure("Cannot save settings for a window with no name.")); } var sizeRes = window.SaveSize(settings, name); var posRes = window.SavePosition(settings, name); settings.Save(); return(Result.Success()); }
/// <summary> /// Saves the given <see cref="ApplicationSettingsBase"/> data without raising an <see cref="Exception"/>. /// </summary> /// <param name="settingsBase">The <see cref="ApplicationSettingsBase"/> instance to save.</param> /// <returns><c>True</c> on success, otherwise <c>false</c>.</returns> public static bool SaveSettings(this ApplicationSettingsBase settingsBase) { if (settingsBase == null) { return(false); } try { settingsBase.Save(); } catch { return(false); } return(true); }
public static bool ShowModal(ApplicationSettingsBase settings) { if (settings == null) throw new ArgumentNullException("settings"); using (CommonForm fm = new CommonForm()) { UcOptions ucOptions = new UcOptions(settings); fm.AddControlForDialog(ucOptions, "Options"); if (fm.ShowDialog() == DialogResult.OK) { settings.Save(); return true; } else { settings.Reload(); return false; } } }
private void Button_Click(object sender, EventArgs e) { try { if (sender == this.buttonApply) { // Get Property Grids List <PropertyGrid> propertyGrids = this.GetPropertyGrids(this.tabControlOptions); // Loop through each Property Grid foreach (PropertyGrid propertyGrid in propertyGrids) { // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Reload Application Settings settings.Save(); // Reload Application Settings propertyGrid.Refresh(); } // Disable Edited Button this.m_edited = false; } else if (sender == this.buttonCancel) { // Get Property Grids List <PropertyGrid> propertyGrids = this.GetPropertyGrids(this.tabControlOptions); // Reload foreach (PropertyGrid propertyGrid in propertyGrids) { // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Reload Application Settings settings.Reload(); } // Close this.Close(); } else if (sender == this.buttonReset) { DialogResult dialogResult = MessageBox.Show( Resources.TEXT_RESET_CURRENT_TAB_WARNING, Resources.TEXT_ARCDIAGRAMMER, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3, MessageBoxOptions.DefaultDesktopOnly); switch (dialogResult) { case DialogResult.Cancel: case DialogResult.No: break; case DialogResult.Yes: // Find Current Tab PropertyGrid propertyGrid = this.SelectedPropertGrid(this.tabControlOptions); if (propertyGrid == null) { return; } if (propertyGrid.SelectedObject == null) { return; } if (!(propertyGrid.SelectedObject is ApplicationSettingsBase)) { return; } // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Reset Application Settings settings.Reset(); // Refresh Application Settings propertyGrid.Refresh(); break; } } else if (sender == this.buttonResetAll) { DialogResult dialogResult = MessageBox.Show( Resources.TEXT_RESET_ALL_TABS_WARNING, Resources.TEXT_ARCDIAGRAMMER, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3, MessageBoxOptions.DefaultDesktopOnly); switch (dialogResult) { case DialogResult.Cancel: case DialogResult.No: break; case DialogResult.Yes: // Get Property Grids List <PropertyGrid> propertyGrids = this.GetPropertyGrids(this.tabControlOptions); // Loop for each Grid foreach (PropertyGrid propertyGrid in propertyGrids) { // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Reset Application Settings settings.Reset(); // Refresh Application Settings propertyGrid.Refresh(); } // Disable Edited Button this.m_edited = false; break; } } else if (sender == this.buttonOK) { // Get Property Grids List <PropertyGrid> propertyGrids = this.GetPropertyGrids(this.tabControlOptions); // Loop for each Grid foreach (PropertyGrid propertyGrid in propertyGrids) { // Get Application Settings ApplicationSettingsBase settings = (ApplicationSettingsBase)propertyGrid.SelectedObject; // Save Application Settings settings.Save(); } //Close this.Close(); } } catch (Exception ex) { ExceptionDialog.HandleException(ex); } }
protected void SetValue(string propName, object value) { _settings[propName] = value; _settings.Save(); }
private void SaveSettingsToUserConfig() { _userSettings.Save(); }
public static void SaveAndProtect(this ApplicationSettingsBase settings) { settings.Save(); settings.Protect(); }
private void btnOk_Click(object sender, EventArgs e) { // Properties.Settings.Default.Save(); settings.Save(); }