Exemple #1
0
        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;
            }
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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;
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        public string Get(SettingsSection section, string keyName, string defaultValue)
        {
            var setting = GetSetting(section.ToString(), keyName);

            return(setting == null ? defaultValue : setting.Value ?? defaultValue);
        }
Exemple #8
0
 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;
 }
Exemple #9
0
 public string Get(SettingsSection section, string keyName, string defaultValue)
 {
     var setting = GetSetting(section.ToString(), keyName);
     return setting == null ? defaultValue : setting.Value ?? defaultValue;
 }
Exemple #10
0
 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;
 }