using System; using System.Application.Serialization; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace System.Application.Models.Settings { public static class AuthSettings { static AuthSettings() { Authenticators.ValueChanged += Authenticators_ValueChanged; } private static void Authenticators_ValueChanged(object sender, ValueChangedEventArgs e) { if (e.NewValue != e.OldValue) { if (AuthSettings.IsCurrentDirectorySaveAuthData.Value) { File.WriteAllText(Path.Combine(AppContext.BaseDirectory, Constants.AUTHDATA_FILE), e.NewValue); } } } /// /// 令牌数据(压缩存储) /// public static SerializableProperty Authenticators { get; } = new SerializableProperty(GetKey(), Providers.Local) { AutoSave = true }; /// /// 是否将令牌数据存储在程序路径下 /// public static SerializableProperty IsCurrentDirectorySaveAuthData { get; } = new SerializableProperty(GetKey(), Providers.Local, false) { AutoSave = true }; private static string GetKey([CallerMemberName] string propertyName = "") { return nameof(AuthSettings) + "." + propertyName; } } }