public void Set(SettingsSection section, string keyName, string value) { Dictionary <string, Setting> sectionSettings; if (!_allSettings.TryGetValue(section.ToString(), out sectionSettings)) { sectionSettings = new Dictionary <string, Setting>(); _allSettings.Add(section.ToString(), sectionSettings); } Setting setting; if (!sectionSettings.TryGetValue(keyName, out setting)) { sectionSettings.Add( keyName, new Setting(value) { IsDirty = true }); } else if (setting.Value != value) { setting.Value = value; setting.IsDirty = true; } }
private string ReadString(SettingsSection section, SettingName name, string defaultValue, bool decrypt = false) { try { var sb = new StringBuilder(Win32.MAX_PATH); Win32.GetPrivateProfileString(section.ToString(), name.ToString(), defaultValue, sb, (uint)sb.Capacity, _iniFilePath); var result = sb.ToString(); if (decrypt) { var data = Convert.FromBase64String(result); result = Encoding.UTF8.GetString(data); } return(result); } catch (Exception ex) { MessageBox.Show(new WindowWrapper(PluginBase.nppData._nppHandle), ex.Message, Main.PluginName, MessageBoxButtons.OK); return(defaultValue); } }
private void WriteString(SettingsSection section, SettingName name, string value, bool encrypt = false) { if (encrypt) { var bytes = Encoding.UTF8.GetBytes(value); value = Convert.ToBase64String(bytes); } Win32.WritePrivateProfileString(section.ToString(), name.ToString(), value, _iniFilePath); }
public int GetInt(SettingsSection section, string keyName, int defaultValue) { var setting = GetSetting(section.ToString(), keyName); if (setting == null) { return(defaultValue); } int value; return(int.TryParse(setting.Value, out value) ? value : defaultValue); }
public bool GetBool(SettingsSection section, string keyName, bool defaultValue) { var setting = GetSetting(section.ToString(), keyName); if (setting == null || string.IsNullOrEmpty(setting.Value)) return defaultValue; if (setting.Value.Equals("true", StringComparison.CurrentCultureIgnoreCase) || setting.Value == "1") return true; if (setting.Value.Equals("false", StringComparison.CurrentCultureIgnoreCase) || setting.Value == "0") return false; return defaultValue; }
public bool GetBool(SettingsSection section, string keyName, bool defaultValue) { var setting = GetSetting(section.ToString(), keyName); if (setting == null || string.IsNullOrEmpty(setting.Value)) { return(defaultValue); } if (setting.Value.Equals("true", StringComparison.CurrentCultureIgnoreCase) || setting.Value == "1") { return(true); } if (setting.Value.Equals("false", StringComparison.CurrentCultureIgnoreCase) || setting.Value == "0") { return(false); } return(defaultValue); }
public string Get(SettingsSection section, string keyName, string defaultValue) { var setting = GetSetting(section.ToString(), keyName); return(setting == null ? defaultValue : setting.Value ?? defaultValue); }
public int GetInt(SettingsSection section, string keyName, int defaultValue) { var setting = GetSetting(section.ToString(), keyName); if (setting == null) return defaultValue; int value; return int.TryParse(setting.Value, out value) ? value : defaultValue; }
public string Get(SettingsSection section, string keyName, string defaultValue) { var setting = GetSetting(section.ToString(), keyName); return setting == null ? defaultValue : setting.Value ?? defaultValue; }
public void Set(SettingsSection section, string keyName, string value) { Dictionary<string, Setting> sectionSettings; if (!_allSettings.TryGetValue(section.ToString(), out sectionSettings)) { sectionSettings = new Dictionary<string, Setting>(); _allSettings.Add(section.ToString(), sectionSettings); } Setting setting; if (!sectionSettings.TryGetValue(keyName, out setting)) { sectionSettings.Add( keyName, new Setting(value) {IsDirty = true}); } else if (setting.Value != value) { setting.Value = value; setting.IsDirty = true; } }
public SettingsSelectionItem(SettingsSection section, string name = "") { Section = section; SectionName = string.IsNullOrEmpty(name) ? section.ToString() : name; }