public void SaveIni(Ini ini)
 {
     for (int i = 0; i < m_alsUnitGroups.Count; i++)
     {
         Ini.Section sec = new Ini.Section("UnitGroup " + i);
         ((UnitGroup)m_alsUnitGroups[i]).AddIniProperties(sec);
         ini.Add(sec);
     }
 }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var section = txtNewSection.Text;
            var key     = txtNewKey.Text;
            var value   = txtNewValue.Text;

            if (section.Length > 0 && key.Length > 0 && value.Length > 0)
            {
                ini.Add(section, key, value, false);
                Log($"New entry added: '{key}' in '{section}': '{value}'");
            }
            refreshTreeView();
        }
Beispiel #3
0
        public static void Set <T>(string section, string key, T value)
        {
            if (string.IsNullOrEmpty(section))
            {
                throw new ArgumentNullException(nameof(section));
            }
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (value is null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (!TypeDescriptor.GetConverter(typeof(T)).CanConvertTo(typeof(string)))
            {
                throw new ContextMarshalException($"Cast '{typeof(T).Name}' to 'string' not supported.");
            }

            var c = new Ini(Dirs.ConfigFile);

            if (c[section] is null)
            {
                c.Add(new Section(section)
                {
                    new Property(key, Convert.ToString(value, CultureInfo.InvariantCulture))
                });
            }
            else
            {
                c[section][key] = Convert.ToString(value, CultureInfo.InvariantCulture);
            }


            c.SaveTo(Dirs.ConfigFile);
        }