Exemplo n.º 1
0
        /// <summary>
        /// Loads the application's settings.
        /// </summary>
        private void LoadSettings()
        {
            lock (stateSyncObject)
            {
                if (!PreserveApplicationSettings)
                {
                    return;
                }

                var directory = GetLocalApplicationSettingsDirectory();
                var path      = Path.Combine(directory, "UltravioletSettings.xml");

                try
                {
                    var settings = UltravioletActivitySettings.Load(path);
                    if (settings == null)
                    {
                        return;
                    }

                    this.settings = settings;
                }
                catch (FileNotFoundException) { }
                catch (DirectoryNotFoundException) { }
                catch (XmlException) { }
            }
        }
        /// <summary>
        /// Saves the specified application settings to the specified file.
        /// </summary>
        /// <param name="path">The path to the file in which to save the application settings.</param>
        /// <param name="settings">The <see cref="UltravioletApplicationSettings"/> to serialize to the specified file.</param>
        public static void Save(String path, UltravioletActivitySettings settings)
        {
            var xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                                    new XElement("Settings",
                                                 UltravioletActivityAudioSettings.Save(settings.Audio)
                                                 ));

            xml.Save(path);
        }
        /// <summary>
        /// Creates a set of application settings from the current application state.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <returns>The <see cref="UltravioletApplicationSettings"/> which was retrieved.</returns>
        public static UltravioletActivitySettings FromCurrentSettings(UltravioletContext uv)
        {
            Contract.Require(uv, nameof(uv));

            var settings = new UltravioletActivitySettings();

            settings.Audio = UltravioletActivityAudioSettings.FromCurrentSettings(uv);

            return(settings);
        }
        /// <summary>
        /// Loads a set of application settings from the specified file.
        /// </summary>
        /// <param name="path">The path to the file from which to load the application settings.</param>
        /// <returns>The <see cref="UltravioletApplicationSettings"/> which were deserialized from the specified file.</returns>
        public static UltravioletActivitySettings Load(String path)
        {
            var xml = XDocument.Load(path);

            var settings = new UltravioletActivitySettings();

            settings.Audio = UltravioletActivityAudioSettings.Load(xml.Root.Element("Audio"));

            if (settings.Audio == null)
            {
                return(null);
            }

            return(settings);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Saves the application's settings.
        /// </summary>
        private void SaveSettings()
        {
            lock (stateSyncObject)
            {
                if (!PreserveApplicationSettings)
                {
                    return;
                }

                var path = Path.Combine(GetLocalApplicationSettingsDirectory(), "UltravioletSettings.xml");

                this.settings = UltravioletActivitySettings.FromCurrentSettings(Ultraviolet);
                UltravioletActivitySettings.Save(path, settings);
            }
        }