Exemplo n.º 1
0
        public bool SaveSetting(string name, List <string> contents)
        {
            SettingMember Setting = new SettingMember(name);

            if (!Content.ContainsKey(name))
            {
                foreach (var content in contents)
                {
                    Setting.Add(content);
                }
                Content.TryAdd(name, Setting);
                Write();
                return(true);
            }
            else
            {
                Content[name].Clear();
                foreach (var content in contents)
                {
                    Setting.Add(content);
                }
                Content[name] = Setting;
                Write();
                return(true);
            }
        }
Exemplo n.º 2
0
        private void Read()
        {
            FileStream    FS             = new FileStream(FilePath, FileMode.Open);
            StreamReader  SR             = new StreamReader(FS);
            string        message        = string.Empty;
            int           state          = 0;
            SettingMember SettingContent = null;

            while ((message = SR.ReadLine()) != null)
            {
                switch (state)
                {
                case 0:
                    if (message.Equals(string.Format("[{0}]", FileName)))
                    {
                        state = 1;
                    }
                    break;

                case 1:
                    if (message.StartsWith("--"))
                    {
                        if (SettingContent != null && Content.ContainsKey(SettingContent.Name))
                        {
                            string content = message.Substring(2).Trim();
                            SettingContent.Add(content);
                        }
                    }
                    else if (message.StartsWith("-"))
                    {
                        string        name    = message.Substring(1).Trim();
                        SettingMember Setting = new SettingMember(name);
                        if (!Content.ContainsKey(name))
                        {
                            Content.TryAdd(name, Setting);
                        }
                        SettingContent = Setting;
                    }
                    break;

                default:
                    break;
                }
            }
            SR.Close();
            FS.Close();
        }