Ejemplo n.º 1
0
        public void AddKey(string filename, string section, string key, string value)
        {
            if (!File.Exists(filename))
            {
                File.WriteAllText(filename, string.Empty);
            }

            IniData iniData = IniParser.ReadFile(filename);

            if (!iniData.Sections.ContainsSection(section))
            {
                iniData.Sections.AddSection(section);
            }

            KeyDataCollection autorunSection = iniData.Sections[section];

            if (!autorunSection.ContainsKey(key))
            {
                autorunSection.AddKey(key);
            }

            autorunSection.GetKeyData(key).Value = value;

            IniParser.WriteFile(filename, iniData);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained.
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section

                if (!Configuration.AllowDuplicateKeys)
                {
                    throw new ParsingException(string.Format("Duplicated key '{0}' found in section '{1}", key, sectionName));
                }
                else if (Configuration.OverrideDuplicateKeys)
                {
                    keyDataCollection[key] = value;
                }
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection" instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData" collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection" is contained.
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
                HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            else
                keyDataCollection.AddKey(key, value);

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
Ejemplo n.º 4
0
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            bool flag = keyDataCollection.ContainsKey(key);

            if (flag)
            {
                this.HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                keyDataCollection.AddKey(key, value);
            }
            keyDataCollection.GetKeyData(key).Comments = this._currentCommentListTemp;
            this._currentCommentListTemp.Clear();
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained.
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section
                HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained. 
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section
                HandleDuplicatedKeyInCollection(key, value, keyDataCollection, sectionName);
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Adds a key to a concrete <see cref="KeyDataCollection"/> instance, checking
        ///     if duplicate keys are allowed in the configuration
        /// </summary>
        /// <param name="key">
        ///     Key name
        /// </param>
        /// <param name="value">
        ///     Key's value
        /// </param>
        /// <param name="keyDataCollection">
        ///     <see cref="KeyData"/> collection where the key should be inserted
        /// </param>
        /// <param name="sectionName">
        ///     Name of the section where the <see cref="KeyDataCollection"/> is contained. 
        ///     Used only for logging purposes.
        /// </param>
        private void AddKeyToKeyValueCollection(string key, string value, KeyDataCollection keyDataCollection, string sectionName)
        {
            // Check for duplicated keys
            if (keyDataCollection.ContainsKey(key))
            {
                // We already have a key with the same name defined in the current section

                if (!Configuration.AllowDuplicateKeys)
                {
                    throw new ParsingException(string.Format("Duplicated key '{0}' found in section '{1}", key, sectionName));
                }
                else if(Configuration.OverrideDuplicateKeys)
                {
                    keyDataCollection[key] = value;
                }
            }
            else
            {
                // Save the keys
                keyDataCollection.AddKey(key, value);
            }

            keyDataCollection.GetKeyData(key).Comments = _currentCommentListTemp;
            _currentCommentListTemp.Clear();
        }
        /// <summary>
        /// Load settings from IniData.
        /// </summary>
        private void LoadSettings()
        {
            foreach (var section in config.VisibleSections)
            {
                // Add section title to window
                AddSectionTitle(section.name);
                MovePosition(spacing);

                // Get section from collection
                SectionDataCollection sectionDataCollection = data.Sections;
                if (!sectionDataCollection.ContainsSection(section.name))
                {
                    sectionDataCollection.AddSection(section.name);
                }
                SectionData sectionData = sectionDataCollection.GetSectionData(section.name);

                foreach (var key in section.keys)
                {
                    // Get key from collection
                    KeyDataCollection keyDataCollection = sectionData.Keys;
                    if (!keyDataCollection.ContainsKey(key.name))
                    {
                        keyDataCollection.AddKey(key.name);
                    }
                    KeyData keyData = keyDataCollection.GetKeyData(key.name);

                    // Add key to window with corrispective control
                    TextLabel settingName = AddKeyName(key.name);
                    settingName.ToolTip     = defaultToolTip;
                    settingName.ToolTipText = key.description;

                    switch (key.type)
                    {
                    case ModSettingsKey.KeyType.Toggle:
                        bool toggle;
                        AddCheckBox(bool.TryParse(keyData.Value, out toggle) ? toggle : key.toggle.value);
                        break;

                    case ModSettingsKey.KeyType.MultipleChoice:
                        int selected;
                        if (!int.TryParse(keyData.Value, out selected))
                        {
                            selected = key.multipleChoice.selected;
                        }
                        var multipleChoice = GetSlider();
                        multipleChoice.SetIndicator(key.multipleChoice.choices, selected);
                        SetSliderIndicator(multipleChoice);
                        break;

                    case ModSettingsKey.KeyType.Slider:
                        var sliderKey = key.slider;
                        int startValue;
                        if (!int.TryParse(keyData.Value, out startValue))
                        {
                            startValue = key.slider.value;
                        }
                        var slider = GetSlider();
                        slider.SetIndicator(sliderKey.min, sliderKey.max, startValue);
                        SetSliderIndicator(slider);
                        break;

                    case ModSettingsKey.KeyType.FloatSlider:
                        var   floatSliderKey = key.floatSlider;
                        float floatStartValue;
                        if (!float.TryParse(keyData.Value, out floatStartValue))
                        {
                            floatStartValue = key.floatSlider.value;
                        }
                        var floatSlider = GetSlider();
                        floatSlider.SetIndicator(floatSliderKey.min, floatSliderKey.max, floatStartValue);
                        SetSliderIndicator(floatSlider);
                        break;

                    case ModSettingsKey.KeyType.Tuple:
                        var tuple = AddTuple(keyData.Value);
                        tuple.First.Numeric = tuple.Second.Numeric = true;
                        break;

                    case ModSettingsKey.KeyType.FloatTuple:
                        AddTuple(keyData.Value);     // TextBox.Numeric doesn't allow dot
                        break;

                    case ModSettingsKey.KeyType.Text:
                        TextBox textBox = GetTextbox(95, 40, keyData.Value);
                        modTextBoxes.Add(textBox);
                        break;

                    case ModSettingsKey.KeyType.Color:
                        AddColorPicker(keyData.Value, key);
                        break;
                    }

                    MovePosition(spacing);
                }
            }
        }
Ejemplo n.º 9
0
 public static string GetKeyValue(this KeyDataCollection keys, string key) => keys.GetKeyData(key)?.Value;
Ejemplo n.º 10
0
 public static KeyData GetKeyData(this KeyDataCollection keys, string key) => keys.GetKeyData(key);