Пример #1
0
        /// <summary>
        /// Apply and save new settings
        /// </summary>
        /// <param name="settings">Settings to apply</param>
        public static void ApplySettings(Settings settings)
        {
            // Write to settings file
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Settings));

            using (TextWriter textWriter = new StreamWriter(SettingsFilePath))
            {
                xmlSerializer.Serialize(textWriter, settings);
            }

            // Set autostart setting to registry
            AutoStartManager.SetAutoStart(settings.AutoStart);
        }
Пример #2
0
        /// <summary>
        /// Return current settings as object
        /// </summary>
        /// <returns>Current settings</returns>
        public static Settings GetSettings()
        {
            // If settings file doesn't exist, generate it
            if (!File.Exists(SettingsFilePath))
            {
                GenerateDefaultSettingsFile();
            }

            // Read settings from settings file
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Settings));
            Settings      settings      = new Settings();

            using (TextReader textReader = new StreamReader(SettingsFilePath))
            {
                settings = (Settings)xmlSerializer.Deserialize(textReader);
            }

            // Read autostart setting from registry
            settings.AutoStart = AutoStartManager.AutoStartIsActive();

            return(settings);
        }