/// <summary>
        /// Saves current manager settings to AppData file
        /// </summary>
        public void SaveSettings()
        {
            // Get AppData directory
            string wallBriteAppDataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\WallBrite";

            // Create AppData folder if it doesn't exist already
            if (!Directory.Exists(wallBriteAppDataDirectory))
            {
                Directory.CreateDirectory(wallBriteAppDataDirectory);
            }

            // Create settings object to be serialized
            ManagerSettings settings = new ManagerSettings
            {
                UpdateIntervalHours = _updateIntervalHours,
                UpdateIntervalMins  = _updateIntervalMins,
                BrightestTime       = _brightestTime,
                DarkestTime         = _darkestTime,
                StartsOnStartup     = StartsOnStartup,
                WallpaperStyle      = WallpaperStyle
            };

            // Create settings file in directory (or overwrite existing) and serialize settings object to it
            File.WriteAllText(wallBriteAppDataDirectory + "\\Settings.json", JsonConvert.SerializeObject(settings, Formatting.Indented));
        }
        /// <summary>
        /// Creates ManagerViewModel using given library and settings represented by given ManagerSettings
        /// object
        /// </summary>
        /// <param name="library">LibraryViewModel representing library to be used with this manager</param>
        /// <param name="settings">ManagerSettings object representing settings to be used</param>
        public ManagerViewModel(LibraryViewModel library, ManagerSettings settings)
        {
            // Set assigned library
            Library = library;

            // Pull settings from the settings object
            _updateIntervalHours = settings.UpdateIntervalHours;
            _updateIntervalMins  = settings.UpdateIntervalMins;
            _checkInterval       = new TimeSpan(_updateIntervalHours, _updateIntervalMins, 0);
            _brightestTime       = settings.BrightestTime;
            _darkestTime         = settings.DarkestTime;
            StartsOnStartup      = settings.StartsOnStartup;
            WallpaperStyle       = settings.WallpaperStyle;

            // Create WallpaperStyles
            WallpaperStyles = new List <string>()
            {
                "Tiled",
                "Centered",
                "Stretched",
                "Fill",
                "Fit"
            };

            // Create timers and start checking
            CreateTimers();
            CheckAndUpdate();

            CreateCommands();
        }
Exemple #3
0
        /// <summary>
        /// Returns ManagerSettings represented by given Stream
        /// </summary>
        /// <param name="fileStream">Stream representing settings</param>
        /// <returns>ManagerSerttings represented by given Stream</returns>
        private ManagerSettings GetManagerSettingsFromStream(Stream fileStream)
        {
            var serializer = new JsonSerializer();

            // Use json serializer to read settings file and create new ManagerSettings object
            using (var streamReader = new StreamReader(fileStream))
                using (var jsonTextReader = new JsonTextReader(streamReader))
                {
                    ManagerSettings settings = (ManagerSettings)serializer.Deserialize(jsonTextReader, typeof(ManagerSettings));
                    return(settings);
                }
        }