Exemplo n.º 1
0
        internal IniParser(string iniPath)
        {
            IniParser.SectionPair sectionPair = new IniParser.SectionPair();
            string str = null;

            this.iniFilePath = iniPath;
            this.Name        = Path.GetFileNameWithoutExtension(iniPath);
            if (!File.Exists(iniPath))
            {
                throw new FileNotFoundException(string.Concat("Unable to locate ", iniPath));
            }
            try
            {
                using (TextReader streamReader = new StreamReader(iniPath))
                {
                    for (string i = streamReader.ReadLine(); i != null; i = streamReader.ReadLine())
                    {
                        i = i.Trim();
                        if (i != "")
                        {
                            if (!i.StartsWith("[") || !i.EndsWith("]"))
                            {
                                if (i.StartsWith(";"))
                                {
                                    i = string.Concat(i.Replace("=", "%eq%"), "=%comment%");
                                }
                                string[] strArrays = i.Split(new char[] { '=' }, 2);
                                string   str1      = null;
                                if (str == null)
                                {
                                    str = "ROOT";
                                }
                                sectionPair.Section = str;
                                sectionPair.Key     = strArrays[0];
                                if ((int)strArrays.Length > 1)
                                {
                                    str1 = strArrays[1];
                                }
                                try
                                {
                                    this.keyPairs.Add(sectionPair, str1);
                                    this.tmpList.Add(sectionPair);
                                }
                                catch
                                {
                                }
                            }
                            else
                            {
                                str = i.Substring(1, i.Length - 2);
                            }
                        }
                    }
                    streamReader.Close();
                }
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
 internal string GetSetting(string sectionName, string settingName)
 {
     IniParser.SectionPair sectionPair = new IniParser.SectionPair();
     sectionPair.Section = sectionName;
     sectionPair.Key     = settingName;
     return((string)this.keyPairs[sectionPair]);
 }
Exemplo n.º 3
0
 internal bool ContainsSetting(string sectionName, string settingName)
 {
     IniParser.SectionPair sectionPair = new IniParser.SectionPair();
     sectionPair.Section = sectionName;
     sectionPair.Key     = settingName;
     return(this.keyPairs.Contains(sectionPair));
 }
Exemplo n.º 4
0
 internal void DeleteSetting(string sectionName, string settingName)
 {
     IniParser.SectionPair sectionPair = new IniParser.SectionPair();
     sectionPair.Section = sectionName;
     sectionPair.Key     = settingName;
     if (this.keyPairs.ContainsKey(sectionPair))
     {
         this.keyPairs.Remove(sectionPair);
         this.tmpList.Remove(sectionPair);
     }
 }
Exemplo n.º 5
0
 internal void SetSetting(string sectionName, string settingName, string value)
 {
     IniParser.SectionPair sectionPair = new IniParser.SectionPair();
     sectionPair.Section = sectionName;
     sectionPair.Key     = settingName;
     if (string.IsNullOrEmpty(value))
     {
         value = string.Empty;
     }
     if (this.keyPairs.ContainsKey(sectionPair))
     {
         this.keyPairs[sectionPair] = value;
     }
 }
Exemplo n.º 6
0
 internal void AddSetting(string sectionName, string settingName, string settingValue)
 {
     IniParser.SectionPair sectionPair = new IniParser.SectionPair();
     sectionPair.Section = sectionName;
     sectionPair.Key     = settingName;
     if (settingValue == null)
     {
         settingValue = string.Empty;
     }
     if (this.keyPairs.ContainsKey(sectionPair))
     {
         this.keyPairs.Remove(sectionPair);
     }
     if (this.tmpList.Contains(sectionPair))
     {
         this.tmpList.Remove(sectionPair);
     }
     this.keyPairs.Add(sectionPair, settingValue);
     this.tmpList.Add(sectionPair);
 }