Example #1
0
 /// <summary>
 /// 获取一个设置组
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public SettingGroup this[string name] {
     get {
         for (int i = 0; i < this.Groups.Count; i++)
         {
             SettingGroup group = this.Groups[i];
             if (group.Name == name)
             {
                 return(group);
             }
         }
         SettingGroup newGroup = new SettingGroup()
         {
             Name = name
         };
         this.Groups.Add(newGroup);
         return(newGroup);
     }
 }
Example #2
0
        //加载文件内容
        private void LoadFile()
        {
            string sz = dpz2.File.UTF8File.ReadAllText(path, false);

            string[]     lines = sz.Replace("\r", "").Split('\n');
            SettingGroup group = null;

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i].Trim();
                if (line == "")
                {
                    if (group == null)
                    {
                        group = new SettingGroup()
                        {
                            Name = ""
                        };
                        this.Groups.Add(group);
                    }
                    //去掉末尾空行
                    if (i != lines.Length - 1)
                    {
                        group.AddEmptyLine();
                    }
                }
                else if (line.StartsWith("[") && line.EndsWith("]"))
                {
                    group = new SettingGroup()
                    {
                        Name = line.Substring(1, line.Length - 2)
                    };
                    this.Groups.Add(group);
                }
                else
                {
                    if (group == null)
                    {
                        group = new SettingGroup()
                        {
                            Name = ""
                        };
                        this.Groups.Add(group);
                    }
                    if (line.StartsWith("#"))
                    {
                        group.AddNote(line.Substring(1));
                    }
                    else
                    {
                        int idx = line.IndexOf("=");
                        if (idx < 0)
                        {
                            group.Set(line);
                        }
                        else
                        {
                            group.Set(line.Substring(0, idx).Trim(), line.Substring(idx + 1).Trim());
                        }
                    }
                }
            }
        }