/* UserSettings.cs * part of zaaReloaded2 * * Copyright 2015-2017 Daniel Kraus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace zaaReloaded2 { [Serializable] class UserSettings : Bovender.UserSettings.UserSettingsBase { #region Static property public static string UserSettingsFile { get { return Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Properties.Settings.Default.AppDataFolder, Properties.Settings.Default.UserFolder, Properties.Settings.Default.UserSettingsFile); } } #endregion #region Singleton factory new public static UserSettings Default { get { return _lazy.Value; } } private static Lazy _lazy = new Lazy(() => { // Logger.Info("Initializing singleton instance"); UserSettings s = FromFileOrDefault(UserSettingsFile); Bovender.UserSettings.UserSettingsBase.Default = s; return s; }); #endregion #region User settings public DateTime LastUpdateCheck { get { if (_lastUpdateCheck == null) { _lastUpdateCheck = new DateTime(2016, 1, 1); } return _lastUpdateCheck; } set { _lastUpdateCheck = value; } } public string LastVersionSeen { get { if (_lastVersionSeen == null) { _lastVersionSeen = DEFAULT_VERSION; } return _lastVersionSeen; } set { _lastVersionSeen = value; } } public int UpdateCheckInterval { get { if (_updateCheckInterval <= 0) { _updateCheckInterval = 7; } return _updateCheckInterval; } set { _updateCheckInterval = value; } } public bool EnableLogging { get { return LogFile.IsInitializedAndEnabled; } set { if (value) { LogFile.Default.IsFileLoggingEnabled = true; } else if (LogFile.IsInitializedAndEnabled) { LogFile.Default.IsFileLoggingEnabled = true; } } } public string ImportExportPath { get; set; } public bool SuppressItemCommentInteraction { get; set; } public Guid LastSettings { get { if (_lastSettings == null) { _lastSettings = new Guid("00000000-0000-0000-0000-000000000000"); } return _lastSettings; } set { _lastSettings = value; } } public Controller.SettingsRepository SettingsRepository { get; set; } [YamlDotNet.Serialization.YamlIgnore] public bool FirstRun { get { return LastVersionSeen == DEFAULT_VERSION; } } #endregion #region Private fields private DateTime _lastUpdateCheck; private int _updateCheckInterval; private string _lastVersionSeen; private Guid _lastSettings; private const string DEFAULT_VERSION = "0.0.0"; #endregion #region Overrides public override string GetSettingsFilePath() { return UserSettingsFile; } protected override YamlDotNet.Serialization.SerializerBuilder ConstructSerializerBuilder() { return base.ConstructSerializerBuilder().EnsureRoundtrip(); } #endregion #region Constructor /// /// Creates a new instance. This should never be called directly, use /// the singleton factory instead. The constructor must be public to /// enable deserialization. /// public UserSettings() { } #endregion #region Class logger private static NLog.Logger Logger { get { return _logger.Value; } } private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); #endregion } }