From c80806d5cb1864b8bdfd3e45d49b91b9d60e26fe Mon Sep 17 00:00:00 2001 From: rmbgame Date: Sat, 15 May 2021 02:57:10 +0800 Subject: [PATCH] save --- .../App.axaml.cs | 2 +- .../CommandLineTools.cs | 12 +++++++-- .../Services/Mvvm/AuthService.cs | 26 +++++++++---------- .../Services/Mvvm/ProxyService.cs | 10 +++---- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/ST.Client.Desktop.Avalonia.App/App.axaml.cs b/src/ST.Client.Desktop.Avalonia.App/App.axaml.cs index 7a1a9b98b..82323fd4d 100644 --- a/src/ST.Client.Desktop.Avalonia.App/App.axaml.cs +++ b/src/ST.Client.Desktop.Avalonia.App/App.axaml.cs @@ -171,7 +171,7 @@ namespace System.Application.UI #if !UI_DEMO compositeDisposable.Add(SettingsHost.Save); compositeDisposable.Add(ProxyService.Current.Dispose); - compositeDisposable.Add(AuthService.Current.SaveEditNameAuthenticators); + //compositeDisposable.Add(AuthService.Current.SaveEditNameAuthenticators); compositeDisposable.Add(SteamConnectService.Current.Dispose); if (GeneralSettings.IsStartupAppMinimized.Value) { diff --git a/src/ST.Client.Desktop.Avalonia.App/CommandLineTools.cs b/src/ST.Client.Desktop.Avalonia.App/CommandLineTools.cs index dc5f5b2ff..1bfc459af 100644 --- a/src/ST.Client.Desktop.Avalonia.App/CommandLineTools.cs +++ b/src/ST.Client.Desktop.Avalonia.App/CommandLineTools.cs @@ -1,4 +1,5 @@ using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Threading; using System.Application.Services; using System.CommandLine; using System.CommandLine.Invocation; @@ -126,8 +127,15 @@ namespace System.Application.UI if (id <= 0) return; initStartup(DILevel.GUI | DILevel.Steam | DILevel.HttpClientFactory); IWindowService.Instance.InitUnlockAchievement(id); - IsMinimize = silence; - initUIApp(); + if (!silence) + { + initUIApp(); + } + else + { + SteamConnectService.Current.Initialize(id); + Dispatcher.UIThread.MainLoop(new Threading.CancellationToken()); + } }); rootCommand.AddCommand(unlock_achievement); diff --git a/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs b/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs index 1884d65e8..6618d9951 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/AuthService.cs @@ -26,6 +26,8 @@ namespace System.Application.Services public static AuthService Current { get; } = new(); #endregion + private readonly IGameAccountPlatformAuthenticatorRepository repository = DI.Get(); + public SourceCache Authenticators { get; } public AuthService() @@ -35,7 +37,6 @@ namespace System.Application.Services public async void Initialize(bool isSync = false) { - var repository = DI.Get(); var list = await repository.GetAllAsync(); if (list.Any_Nullable()) { @@ -53,11 +54,6 @@ namespace System.Application.Services //else // ToastService.Current.Notify(AppResources.LocalAuth_RefreshAuthSuccess); } - - //Authenticators.CollectionChanged += (s, e) => - //{ - // this.RaisePropertyChanged(nameof(IsAuthenticatorsEmpty)); - //}; } @@ -465,7 +461,7 @@ namespace System.Application.Services public static async void AddOrUpdateSaveAuthenticators(MyAuthenticator auth) { var repository = DI.Get(); - await repository.InsertOrUpdateAsync(auth.AuthenticatorData, false); + await repository.InsertOrUpdateAsync(auth.AuthenticatorData, true); if (Current.Authenticators.Items.Any(s => s.Id == auth.Id)) { return; @@ -484,23 +480,25 @@ namespace System.Application.Services Current.Authenticators.Remove(auth); } - - public void SaveEditNameAuthenticators() + public void SaveEditNameAuthenticators(bool isLocal = false, string? password = null) { var auths = Authenticators.Items.Where(x => x.Name != x.OriginName); foreach (var auth in auths) - AddOrUpdateSaveAuthenticators(auth); + repository.RenameAsync(auth.Id, auth.Name, true, password); } - public void ExportAuthenticators() + public async void ExportAuthenticators(string filePath, bool isLocal = false, string? password = null) { - + var auths = await repository.GetAllAsync(password); + var b = Serializable.SMP(auths); + using var stream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write); + await stream.WriteAsync(b); + stream.Close(); } - public async void EncryptionAuthenticators(bool isLocal, string password) + public async void SwitchEncryptionAuthenticators(bool isLocal, string password) { - var repository = DI.Get(); await repository.SwitchEncryptionModeAsync(isLocal, password, Authenticators.Items.Select(s => s.AuthenticatorData)); } } diff --git a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs index d88b367d1..14089a56d 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs @@ -132,17 +132,17 @@ namespace System.Application.Services { if (value) { - if (EnableProxyDomains.Any_Nullable()) - { + //if (EnableProxyDomains.Any_Nullable()) + //{ //Toast.Show(AppResources.CommunityFix_NoSelectAcceleration); //return; - httpProxyService.ProxyDomains = EnableProxyDomains; - this.RaisePropertyChanged(nameof(EnableProxyDomains)); - } + //httpProxyService.ProxyDomains = EnableProxyDomains; + //} httpProxyService.ProxyDomains = EnableProxyDomains; httpProxyService.Scripts = EnableProxyScripts; httpProxyService.IsEnableScript = ProxySettings.IsEnableScript.Value; httpProxyService.IsOnlyWorkSteamBrowser = ProxySettings.IsOnlyWorkSteamBrowser.Value; + this.RaisePropertyChanged(nameof(EnableProxyDomains)); this.RaisePropertyChanged(nameof(EnableProxyScripts)); if (!ProxySettings.EnableWindowsProxy.Value)