Ejemplo n.º 1
0
        public string ReadString(string section, string ident, string def = "")
        {
            string         result   = def;
            IniFileSection oSection = sectionList.SectionByName(section, CaseSensitive);

            if (oSection != null)
            {
                IniFileKey oKey = oSection.KeyList.KeyByName(ident, CaseSensitive);
                if (oKey != null)
                {
                    if (StripQuotes)
                    {
                        int j = oKey.Value.Length;
                        if (j > 1)
                        {
                            result = oKey.Value.Trim('\'', '"');
                        }
                        else
                        {
                            result = oKey.Value;
                        }
                    }
                    else
                    {
                        result = oKey.Value;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public void ReadSectionValues(string section, List <string> strings)
        {
            bool includeComments = !StripComments;
            bool includeInvalid  = !StripInvalid;
            bool keyIsComment    = false;
            bool doStripQuotes   = StripQuotes;

            strings.Clear();
            IniFileSection oSection = sectionList.SectionByName(section, CaseSensitive);

            if (oSection == null)
            {
                return;
            }
            for (int i = 0; i < oSection.KeyList.Count; i++)
            {
                string     s = null;
                IniFileKey k = oSection.KeyList[i];
                if (includeInvalid || !string.IsNullOrEmpty(k.Ident))
                {
                    s            = k.Value;
                    keyIsComment = IsComment(k.Ident);
                    if (includeComments || !keyIsComment)
                    {
                        if (doStripQuotes)
                        {
                            int j = s.Length;
                            if (j > 1)
                            {
                                s = s.Trim('\'', '"');
                            }
                        }
                        if (keyIsComment)
                        {
                            s = k.Ident;
                        }
                        else if (!string.IsNullOrEmpty(k.Ident))
                        {
                            s = k.Ident + Separator + s;
                        }
                        strings.Add(s);
                    }
                }
            }
        }
Ejemplo n.º 3
0
            public string ReadString(string ident, string def = "")
            {
                string     result = def;
                IniFileKey oKey   = KeyList.KeyByName(ident, true);

                if (oKey != null)
                {
                    int j = oKey.Value.Length;
                    if (j > 1)
                    {
                        result = oKey.Value.Trim('\'', '"');
                    }
                    else
                    {
                        result = oKey.Value;
                    }
                }
                return(result);
            }
Ejemplo n.º 4
0
 public void WriteString(string section, string ident, string value)
 {
     if (!string.IsNullOrEmpty(section) && !string.IsNullOrEmpty(ident))
     {
         IniFileSection oSection = sectionList.SectionByName(section, CaseSensitive);
         if (oSection == null)
         {
             oSection = new IniFileSection(section);
             sectionList.Add(oSection);
         }
         IniFileKey oKey = oSection.KeyList.KeyByName(ident, CaseSensitive);
         if (oKey != null)
         {
             oKey.Value = value;
         }
         else
         {
             oSection.KeyList.Add(new IniFileKey(ident, value));
         }
     }
     MaybeUpdateFile();
 }