コード例 #1
0
ファイル: ConfigReader.cs プロジェクト: blockspacer/MMXLegacy
        public void ReadData(Stream p_stream)
        {
            if (p_stream == null)
            {
                throw new ArgumentNullException("p_stream");
            }
            m_groups.Clear();
            Int32       num         = 0;
            ConfigGroup configGroup = null;

            using (StreamReader streamReader = new StreamReader(p_stream))
            {
                Regex  regex     = new Regex("\\[[a-zA-Z\\d\\s]+\\]", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
                Char[] separator = new Char[]
                {
                    '='
                };
                while (!streamReader.EndOfStream)
                {
                    String text = streamReader.ReadLine();
                    num++;
                    if (text.Contains("#"))
                    {
                        if (text.IndexOf("#") == 0)
                        {
                            continue;
                        }
                        text = text.Substring(0, text.IndexOf("#"));
                    }
                    text = text.Trim();
                    Match match = regex.Match(text);
                    if (match.Success)
                    {
                        if (match.Value.Length == 2)
                        {
                            throw new ConfigException(String.Format("Group must have a name (line {0})", num));
                        }
                        if (configGroup != null)
                        {
                            m_groups.Add(configGroup.Name, configGroup);
                        }
                        String text2 = match.Value.Substring(1, match.Length - 2);
                        if (!m_groups.TryGetValue(text2, out configGroup))
                        {
                            configGroup = new ConfigGroup(text2);
                        }
                    }
                    else if (text.IndexOf('=') != -1)
                    {
                        if (configGroup == null)
                        {
                            configGroup = new ConfigGroup("default");
                        }
                        String[] array = text.Split(separator, 2);
                        configGroup.AddSetting(new ConfigSetting(array[0].Trim(), array[1].Trim()));
                    }
                }
                m_groups.Add(configGroup.Name, configGroup);
            }
        }
コード例 #2
0
ファイル: ConfigReader.cs プロジェクト: blockspacer/MMXLegacy
 public ConfigGroup this[String groupName]
 {
     get
     {
         ConfigGroup result;
         if (!m_groups.TryGetValue(groupName, out result))
         {
             result = (m_groups[groupName] = new ConfigGroup(groupName));
         }
         return(result);
     }
 }