Example #1
0
                /// <summary>
                /// Sets the key name
                /// </summary>
                /// <param name="key"></param>
                /// <returns>Returns true on success, fails if the section name key already exists</returns>
                public bool SetName(string key)
                {
                    key = key.Trim();
                    if (key.Length == 0)
                    {
                        return(false);
                    }

                    IniKey k = _section.GetKey(key);

                    if (k != this && k != null)
                    {
                        return(false);
                    }

                    try
                    {
                        // Remove the current key
                        _section._keys.Remove(Name);
                        // Set the new key name to this object
                        _section._keys[key] = this;
                        // Set the new key name
                        Name = key;
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.Message);
                        return(false);
                    }
                }
Example #2
0
 // Sets the key name
 // Returns true on success, fails if the section name sKey already exists
 public bool SetName(string sKey)
 {
     sKey = sKey.Trim();
     if (sKey.Length != 0)
     {
         IniKey k = m_section.GetKey(sKey);
         if (k != this && k != null)
         {
             return(false);
         }
         try
         {
             // Remove the current key
             m_section.m_keys.Remove(m_sKey);
             // Set the new key name to this object
             m_section.m_keys[sKey] = this;
             if (sKey != m_sKey)
             {
                 m_section.m_pIniFile.changed = true;
             }
             // Set the new key name
             m_sKey = sKey;
             return(true);
         }
         catch (Exception ex)
         {
             Trace.WriteLine(ex.Message);
         }
     }
     return(false);
 }
Example #3
0
            /// @brief Set name of key
            ///
            /// @param key_name name of key
            /// @retval	true operation done, false operation failed
            public bool SetName(string key_name)
            {
                IniKey key;

                key_name = key_name.Trim();

                if (key_name.Length != 0)
                {
                    key = Section.GetKey(key_name);

                    if ((key != this) && (key != null))
                    {
                        return(false);
                    }

                    try
                    {
                        Section.KeysArray.Remove(Key_Name);
                        Section.KeysArray.Add(this);

                        Key_Name = key_name;

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                return(false);
            }
Example #4
0
 /// <summary>
 /// Sets the key name Returns true on success, fails if the
 /// section name sKey already exists
 /// </summary>
 /// <param name="sKey">The s key.</param>
 /// <returns></returns>
 public bool SetName(string sKey)
 {
     sKey = sKey.Trim();
     if (sKey.Length != 0)
     {
         IniKey k = m_section.GetKey(sKey);
         if (!ReferenceEquals(k, this) && k != null)
         {
             return(false);
         }
         try
         {
             // Remove the current key
             m_section.m_keys.Remove(m_sKey);
             // Set the new key name to this object
             m_section.m_keys[sKey] = this;
             // Set the new key name
             m_sKey = sKey;
             return(true);
         }
         catch (Exception ex)
         {
             Logger.Error <IniSection>(ex.Message);
         }
     }
     return(false);
 }
Example #5
0
 // Sets the key name
 // Returns true on success, fails if the section name sKey already exists
 public bool ForceSetName(string sKey)
 {
     sKey = sKey.Trim();
     if (sKey.Length != 0)
     {
         IniKey k = m_section.GetKey(sKey);
         if (k == this)
         {
             return(true);
         }
         if (k == null)
         {
             try
             {
                 // Remove the current key
                 m_section.m_keys.Remove(m_sKey);
                 // Set the new key name to this object
                 m_section.m_keys[sKey] = this;
                 // Set the new key name
                 m_sKey = sKey;
                 return(true);
             }
             catch (Exception ex)
             {
                 Trace.WriteLine(ex.Message);
             }
         }
         if (k != null)
         {
             try
             {
                 var tempKey = m_section.m_keys[sKey];
                 m_section.m_keys[sKey]   = m_section.m_keys[m_sKey];
                 m_section.m_keys[m_sKey] = tempKey;
                 return(true);
             }
             catch (Exception ex)
             {
                 Trace.WriteLine(ex.Message);
             }
         }
     }
     return(false);
 }
Example #6
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;
 }
Example #7
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);
    }
Example #8
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;
 }
Example #9
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);
    }
Example #10
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);
        }
Example #11
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);
        }
Example #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);
        }
Example #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));
        }
Example #14
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);
    }
Example #15
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);
    }