void LoadDictionary(Dictionary<int, string> dic, IniSection section)
        {
            dic.Clear();

            if (section == null)
                return;

            foreach (IniKey iKey in section.Keys)
            {
                if (iKey.IsComment)
                    continue; // entry is commented out

                string key = iKey.Name;
                string value = iKey.Value;
#if DEBUG
                if (key.Trim().StartsWith("EOF"))
                    break; // for testing purposes
#else
                if (key.Trim().StartsWith("EOF"))
                    continue; // ignore
#endif
                if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
                    dic.Add(int.Parse(key), value);
            }
        }
        private static void FillDictionary(Dictionary<string, string> dic, IniSection sec, string[] names)
        {
            dic.Clear();

            foreach (string name in names)
            {
                IniKey key = sec[name];
                if (key == null)
                    throw new ApplicationException("Missing eneumeration key.");

                dic.Add(name, key.Value);
            }
        }
示例#3
0
        public void SetKeyValue(string sectionName, string keyName, string value)
        {
            // Get / create section
            IniSection section = this[sectionName];
            if (section == null)
            {
                section = new IniSection(sectionName);
                this.Sections.Add(section);
            }

            // Get / create Key
            IniKey key = section[keyName];
            if (key == null)
            {
                key = new IniKey();
                key.Name = keyName;
                section.Keys.Add(key);
                key.OnChange += new EventHandler(_sections_OnChange);
            }

            // Set new Value
            key.Value = value;

            SetChanged();
        }
示例#4
0
        public void SetKeyValue(string sectionName, string keyName, int lineIndex, string value)
        {
            // Get / create section
            IniSection section = this[sectionName];
            if (section == null)
            {
                section = new IniSection(sectionName);
                this.Sections.Add(section);
            }

            // Get / create Key
            IniKey key = section[keyName];
            if (key == null)
            {
                key = new IniKey();
                key.Name = keyName;
                key.OnChange += new EventHandler(_sections_OnChange);
                section.Keys.Add(key);
            }

            // Calculate new values array
            int arrayDim = lineIndex + 1;
            if (key.Multiline)
            {
                arrayDim = Math.Max(arrayDim, key.Values.Length);
            }
            else
            {
                if (arrayDim < 1)
                    arrayDim = 1;
            }

            string[] array = new string[arrayDim];

            // Copy old values
            if (key.Multiline)
            {
                for (int i = 0; i < key.Values.Length; i++)
                    array[i] = key.Values[i];
            }
            else
                array[0] = key.Value;

            // insert new value
            array[lineIndex] = value;

            // Keep new values array in Key
            key.Values = array;

            SetChanged();
        }
示例#5
0
        public void SetKeyValuesDimension(string sectionName, string keyName, int newDimension)
        {
            // Get / create section
            IniSection section = this[sectionName];
            if (section == null)
            {
                section = new IniSection(sectionName);
                this.Sections.Add(section);
            }

            // Get / create Key
            IniKey key = section[keyName];
            if (key == null)
            {
                key = new IniKey();
                key.Name = keyName;
                key.OnChange += new EventHandler(_sections_OnChange);
                section.Keys.Add(key);
            }

            // Setting dimension 0 - causes to not use multiple values
            if (newDimension < 1)
            {
                key.Values = null;
                key.Value = null;
                return;
            }

            // Create new array with values
            string[] array = new string[newDimension];


            // Copy old values
            if (key.Multiline)
            {
                for (int i = 0; i < Math.Min(key.Values.Length, newDimension); i++)
                    array[i] = key.Values[i];
            }
            else
                array[0] = key.Value;

            // Keep new values array in Key
            key.Values = array;

            SetChanged();
        }
        internal static IniSection FromStream(ref string line, StreamReader stream)
        {
            if (line != null)
            {
                line = line.Trim();
                
                IniSection section = null;

                // return section being comment
                if (line.StartsWith(";"))
                {
                    section = new IniSection(line.Substring(1));
                    section._isComment = true;

                    // proceed to the next line
                    line = stream.ReadLine();

                    return section;
                }                

                if (line.StartsWith("[") && line.EndsWith("]"))
                    section = new IniSection(line.Substring(1, line.Length - 2));

                // proceed to the next line
                line = stream.ReadLine();
                if (line != null)
                    line = line.Trim();

                while (line != null && !(line.StartsWith("[") && line.EndsWith("]")))
                {
                    IniKey key = IniKey.FromStream(ref line, stream);
                    if (key != null)
                    {
                        section._keys.Add(key);
                        key.OnChange += new EventHandler(section._keys_OnChange);
                    }

                    // Trim returned line
                    if (line != null)
                        line = line.Trim();
                }
                
                return section;
            }

            return null;
        }