Esempio n. 1
0
        /// @brief Add empty key to section
        ///
        /// @param key_name	name of key
        /// @retval	reference to related key
        public IniKey AddKey(string key_name)
        {
            int id;

            IniSection.IniKey key;

            key_name = key_name.Trim();
            key      = null;

            if (key_name.Length != 0)
            {
                id = _Keys_Array.IndexOf(key_name);

                if (id == -1)
                {
                    key = new IniSection.IniKey(this, key_name);
                    _Keys_Array.Add(key);
                }
                else
                {
                    key = (IniKey)_Keys_Array[id];
                }
            }

            return(key);
        }
Esempio n. 2
0
        // Adds a key to the IniSection object, returns a IniKey object to the new or existing object
        public IniKey AddKey(string sKey, object value = null)
        {
            sKey = (sKey + "").Trim();
            IniSection.IniKey k = null;
            if (sKey.Length != 0)
            {
                sKey = sKey
                       .Replace("\r\n", "┘")
                       .Replace("\n", "┘")
                       .Replace("[", "┤")
                       .Replace("]", "├");
                if (m_keys.ContainsKey(sKey))
                {
                    k = (IniKey)m_keys[sKey];
                }
                else
                {
                    k                  = new IniSection.IniKey(this, sKey);
                    m_keys[sKey]       = k;
                    m_pIniFile.changed = true;
                }
                if (value != null)
                {
                    k.SetValue(value + "");
                }
            }

            return(k);
        }
Esempio n. 3
0
 //  Returns a KeyValue in a certain section
 public string GetKeyValue(string sSection, string sKey)
 {
     IniSection s = GetSection(sSection);
     IniSection.IniKey k = s?.GetKey(sKey);
     if (k != null)
     {
         return k.Value;
     }
     return string.Empty;
 }
Esempio n. 4
0
 // Sets a KeyValuePair in a certain section
 public bool SetKeyValue(string sSection, string sKey, string sValue)
 {
     IniSection s = AddSection(sSection);
     IniSection.IniKey k = s?.AddKey(sKey);
     if (k != null)
     {
         k.Value = sValue;
         return true;
     }
     return false;
 }
Esempio n. 5
0
        public void Save(string sFileName)
        {
            IEnumerator  enumerator;
            StreamWriter writer = new StreamWriter(sFileName, false);

            try
            {
                enumerator = this.Sections.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    IEnumerator enumerator2;
                    IniSection  current = (IniSection)enumerator.Current;
                    Trace.WriteLine($"Writing Section: [{current.Name}]");
                    writer.WriteLine($"[{current.Name}]");
                    try
                    {
                        enumerator2 = current.Keys.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            IniSection.IniKey key = (IniSection.IniKey)enumerator2.Current;
                            if (key.Value != string.Empty)
                            {
                                Trace.WriteLine($"Writing Key: {key.Name}={key.Value}");
                                writer.WriteLine($"{key.Name}={key.Value}");
                            }
                            else
                            {
                                Trace.WriteLine($"Writing Key: {key.Name}");
                                writer.WriteLine($"{key.Name}");
                            }
                        }
                        continue;
                    }
                    finally
                    {
                        if (enumerator2 is IDisposable)
                        {
                            (enumerator2 as IDisposable).Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            writer.Close();
        }
Esempio n. 6
0
 // Renames an existing key returns true on success, false if the key didn't exist or there was another section with the same sNewKey
 public bool RenameKey(string sSection, string sKey, string sNewKey)
 {
     //  Note string trims are done in lower calls.
     IniSection s = GetSection(sSection);
     if (s != null)
     {
         IniSection.IniKey k = s.GetKey(sKey);
         if (k != null)
         {
             return k.SetName(sNewKey);
         }
     }
     return false;
 }
Esempio n. 7
0
        public string GetKeyValue(string sSection, string sKey)
        {
            IniSection section = this.GetSection(sSection);

            if (section != null)
            {
                IniSection.IniKey key = section.GetKey(sKey);
                if (key != null)
                {
                    return(key.Value);
                }
            }
            return(string.Empty);
        }
Esempio n. 8
0
        public bool RenameKey(string sSection, string sKey, string sNewKey)
        {
            IniSection section = this.GetSection(sSection);

            if (section != null)
            {
                IniSection.IniKey key = section.GetKey(sKey);
                if (key != null)
                {
                    return(key.SetName(sNewKey));
                }
            }
            return(false);
        }
Esempio n. 9
0
    //  Returns a KeyValue in a certain section
    public string GetKeyValue(string sSection, string sKey)
    {
        IniSection s = GetSection(sSection);

        if (s != null)
        {
            IniSection.IniKey k = s.GetKey(sKey);
            if (k != null)
            {
                return(k.Value);
            }
        }
        return(String.Empty);
    }
Esempio n. 10
0
    public string GetString(string sSection, string sKey, string def = "")
    {
        IniSection s = GetSection(sSection);

        if (s != null)
        {
            IniSection.IniKey k = s.GetKey(sKey);
            if (k != null)
            {
                return(k.Value);
            }
        }
        return(def);
    }
Esempio n. 11
0
        public bool SetKeyValue(string sSection, string sKey, string sValue)
        {
            IniSection section = this.AddSection(sSection);

            if (section != null)
            {
                IniSection.IniKey key = section.AddKey(sKey);
                if (key != null)
                {
                    key.Value = sValue;
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 12
0
        /// <summary>
        /// Returns a KeyValue in a certain section
        /// </summary>
        /// <param name="section"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public string GetKeyValue(string section, string key)
        {
            IniSection s = GetSection(section);

            if (s == null)
            {
                return(string.Empty);
            }

            IniSection.IniKey k = s.GetKey(key);
            if (k == null)
            {
                return(string.Empty);
            }

            return(k.Value);
        }
Esempio n. 13
0
        /// <summary>
        /// Renames an existing key
        /// </summary>
        /// <param name="section"></param>
        /// <param name="key"></param>
        /// <param name="newKey"></param>
        /// <returns>returns true on success, false if the key didn't exist or there was another section with the same sNewKey</returns>
        public bool RenameKey(string section, string key, string newKey)
        {
            //  Note string trims are done in lower calls.
            IniSection s = GetSection(section);

            if (s == null)
            {
                return(false);
            }

            IniSection.IniKey k = s.GetKey(key);
            if (k == null)
            {
                return(false);
            }

            return(k.SetName(newKey));
        }
Esempio n. 14
0
 // Adds a key to the IniSection object, returns a IniKey object to the new or existing object
 public IniKey AddKey(string sKey)
 {
     sKey = sKey.Trim();
     IniSection.IniKey k = null;
     if (sKey.Length != 0)
     {
         if (m_keys.ContainsKey(sKey))
         {
             k = (IniKey)m_keys[sKey];
         }
         else
         {
             k            = new IniSection.IniKey(this, sKey);
             m_keys[sKey] = k;
         }
     }
     return(k);
 }
Esempio n. 15
0
        /// <summary>
        /// Sets a KeyValuePair in a certain section
        /// </summary>
        /// <param name="section"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SetKeyValue(string section, string key, string value)
        {
            IniSection s = AddSection(section);

            if (s == null)
            {
                return(false);
            }

            IniSection.IniKey k = s.AddKey(key);
            if (k == null)
            {
                return(false);
            }

            k.Value = value;
            return(true);
        }
Esempio n. 16
0
    // Sets a KeyValuePair in a certain section
    public bool SetKeyValue(string sSection, string sKey, string sValue)
    {
        IniSection s = AddSection(sSection);

        if (s != null)
        {
            IniSection.IniKey k = s.AddKey(sKey);
            if (k != null)
            {
                if (k.Value != sValue)
                {
                    k.Value = sValue;
                    changed = true;
                }
                return(true);
            }
        }
        return(false);
    }
Esempio n. 17
0
    //  Returns a KeyValue in a certain section
    public string GetKeyValue(string sSection, string sKey, string DefaultValue = "")
    {
        IniSection s = GetSection(sSection);

        if (s != null)
        {
            IniSection.IniKey k = s.GetKey(sKey);

            if (k != null)
            {
                return(k.Value);
            }
            else
            {
                return(DefaultValue);
            }
        }
        return(DefaultValue);
    }
Esempio n. 18
0
    // Sets a KeyValuePair in a certain section
    public bool SetKeyValue(string sSection, string sKey, string sValue, string DefaultValue = "")
    {
        IniSection s = AddSection(sSection);

        if (s != null)
        {
            IniSection.IniKey k = s.AddKey(sKey);
            if (k != null)
            {
                k.Value = sValue;
                return(true);
            }
            else
            {
                k.Value = DefaultValue;
            }
        }
        return(false);
    }
Esempio n. 19
0
    public bool ForceRenameKey(string sSection, string sKey, string sNewKey)
    {
        //  Note string trims are done in lower calls.
        IniSection s = GetSection(sSection);

        if (s != null)
        {
            IniSection.IniKey k = s.GetKey(sKey);
            if (k != null)
            {
                return(k.ForceSetName(sNewKey));
            }
            if (sKey.Length == 0)
            {
                s.AddKey(sNewKey);
                return(true);
            }
        }
        return(false);
    }
Esempio n. 20
0
 // Adds a key to the IniSection object, returns a IniKey object to the new or existing object
 public IniKey AddKey(string sKey)
 {
     sKey = sKey.Trim();
     IniSection.IniKey k = null;
     if (sKey.Length != 0)
     {
         if (m_keys.ContainsKey(sKey))
         {
             k = (IniKey)m_keys[sKey];
         }
         else
         {
             k = new IniSection.IniKey(this, sKey);
             m_keys[sKey] = k;
         }
     }
     return k;
 }