Ejemplo n.º 1
0
        /// <summary>
        /// set a group setting
        /// </summary>
        public void SetSettingGroup(SettingGroup group)
        {
            string id = group.Id;

            if (GroupsDictionary.ContainsKey(id))
            {
                GroupsDictionary[id] = group;
            }
            else
            {
                GroupsDictionary.Add(id, group);
            }
            bool oldAutoSave = AutoSave;

            AutoSave = false;
            foreach (var item in group.Settings)
            {
                SetSetting(id + "." + item.Key, item.Value);
            }
            AutoSave = oldAutoSave;
            if (AutoSave)
            {
                SaveSettings();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save the current settings to local file
        /// </summary>
        public bool SaveSettings()
        {
            try
            {
                if (string.IsNullOrEmpty(SettingsFile))
                {
                    return(false);
                }

                using (TextWriter writer = File.CreateText(SettingsFile))
                {
                    foreach (SettingGroup group in GroupsDictionary.Values)
                    {
                        writer.WriteLine("Group={0}", group.Id);
                        foreach (var item in group.Settings)
                        {
                            writer.WriteLine("    {0}={1}", item.Key, item.Value);
                        }
                        writer.WriteLine("EndGroup={0}", group.Id);
                    }
                    foreach (var item in SettingsDictionary)
                    {
                        // skip those "group.key=value" for setting group
                        string   key   = item.Key;
                        string[] parts = key.Split(GroupNameDelimiter);
                        if (parts.Length == 1 || !GroupsDictionary.ContainsKey(parts[0]))
                        {
                            writer.WriteLine("{0}={1}", key, item.Value);
                        }
                    }
                    writer.Close();
                }
                return(true);
            }
            catch (Exception err)
            {
                // todo
            }
            return(false);
        }