Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public void SaveCommonSettings()
        {
            var serializer = new XmlSerializer(typeof(SettingsSerializer), AllSerializationTypes.ToArray());

            if (File.Exists(Path.Combine(Folder, "Options.xml")))
            {
                File.Delete(Path.Combine(Folder, "Options.xml"));
            }

            using (var stream = File.Open(Path.Combine(Folder, "Options.xml"), FileMode.Create, FileAccess.Write))
            {
                serializer.Serialize(stream, Settings);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        public void ReloadSettings()
        {
            if (!File.Exists(Path.Combine(Folder, "Options.xml")))
            {
                LoadDefaultSettings();

                return;
            }

            var serializer = new XmlSerializer(typeof(SettingsSerializer), AllSerializationTypes.ToArray());

            try
            {
                using (var stream = File.OpenRead(Path.Combine(Folder, "Options.xml")))
                {
                    Settings = (SettingsSerializer)serializer.Deserialize(stream);
                    if (Settings.GlobalGroups.Count == 0)
                    {
                        Settings.GlobalGroups.Add(new Group()
                        {
                            IsBuildIn = true, Name = "GlobalDefault", IsEnabled = true
                        });
                    }

                    if (Settings.GlobalHotkeys != null && Settings.GlobalHotkeys.Count > 0)
                    {
                        var defaultGroup = Settings.GlobalGroups.FirstOrDefault(g => g.IsBuildIn);
                        foreach (var hk in Settings.GlobalHotkeys)
                        {
                            defaultGroup.Hotkeys.Add(hk);
                        }

                        Settings.GlobalHotkeys.Clear();
                    }
                }
            }
            catch (Exception)
            {
                LoadDefaultSettings();
            }
        }