From e5132615076fc80c0c9d005c42cbfe98490afd2e Mon Sep 17 00:00:00 2001 From: rmbgame Date: Sat, 8 May 2021 01:52:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BA=93=E5=AD=98=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E5=88=97=E8=A1=A8=E5=8A=A0=E8=BD=BD=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E6=BD=9C=E5=9C=A8=E7=9A=84=E9=97=AA?= =?UTF-8?q?=E9=80=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApplicationInstance.cs | 2 +- .../UI/Views/Pages/GameListPage.axaml | 20 +- .../UI/Views/Pages/LocalAuthPage.axaml | 175 ++++++++++-------- .../UI/Views/Pages/SteamAccountPage.axaml | 1 + .../LocalAuthPage/PasswordWindow.axaml | 24 +++ .../LocalAuthPage/PasswordWindow.axaml.cs | 22 +++ .../ST.Client.Desktop.Avalonia.csproj | 3 + .../Implementation/SteamServiceImpl.cs | 56 +++--- .../Services/Mvvm/ProxyService.cs | 4 + .../Services/Mvvm/SteamConnectService.cs | 26 ++- .../UI/Resx/AppResources.Designer.cs | 27 +++ .../UI/Resx/AppResources.resx | 9 + .../Pages/CommunityProxyPageViewModel.cs | 6 +- .../ViewModels/Pages/GameListPageViewModel.cs | 11 +- .../LocalAuthPage/PasswordWindowViewModel.cs | 24 +++ 15 files changed, 294 insertions(+), 116 deletions(-) create mode 100644 src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/PasswordWindow.axaml create mode 100644 src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/PasswordWindow.axaml.cs create mode 100644 src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/PasswordWindowViewModel.cs diff --git a/src/ST.Client.Desktop.Avalonia.App/ApplicationInstance.cs b/src/ST.Client.Desktop.Avalonia.App/ApplicationInstance.cs index fbde707c9..2dc6cfb73 100644 --- a/src/ST.Client.Desktop.Avalonia.App/ApplicationInstance.cs +++ b/src/ST.Client.Desktop.Avalonia.App/ApplicationInstance.cs @@ -38,7 +38,7 @@ namespace System.Application.UI static bool GetIsFirst() { var current = Process.GetCurrentProcess(); - var query = from p in Process.GetProcesses() + var query = from p in Process.GetProcessesByName(current.ProcessName) where p.Id != current.Id && p.ProcessName == current.ProcessName && (current.MainModule == null || diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/GameListPage.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/GameListPage.axaml index 71a241619..b65f283f9 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/GameListPage.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/GameListPage.axaml @@ -83,11 +83,11 @@ - + + - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml index 6fe01a265..9c0f5ceb6 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Pages/SteamAccountPage.axaml @@ -43,6 +43,7 @@ Header="{ReflectionBinding Path=Res.UserChange_OfflineBtn,Mode=OneWay,Source={x:Static resx:R.Current}}" Command="{ReflectionBinding #u.DataContext.OfflineModeButton_Click}" CommandParameter="{Binding}" /> + + + + + + diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/PasswordWindow.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/PasswordWindow.axaml.cs new file mode 100644 index 000000000..1bd8a12d8 --- /dev/null +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/LocalAuthPage/PasswordWindow.axaml.cs @@ -0,0 +1,22 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace System.Application.UI.Views.Windows +{ + public class PasswordWindow : FluentWindow + { + public PasswordWindow() : base() + { + InitializeComponent(); +#if DEBUG + this.AttachDevTools(); +#endif + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } +} diff --git a/src/ST.Client.Desktop.Avalonia/ST.Client.Desktop.Avalonia.csproj b/src/ST.Client.Desktop.Avalonia/ST.Client.Desktop.Avalonia.csproj index 5dd8e1f79..713339f02 100644 --- a/src/ST.Client.Desktop.Avalonia/ST.Client.Desktop.Avalonia.csproj +++ b/src/ST.Client.Desktop.Avalonia/ST.Client.Desktop.Avalonia.csproj @@ -70,6 +70,9 @@ EncryptionAuthWindow.axaml + + PasswordWindow.axaml + ExportAuthWindow.axaml diff --git a/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs b/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs index faa896853..85a1904eb 100644 --- a/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs +++ b/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs @@ -280,39 +280,47 @@ namespace System.Application.Services.Implementation List GetAppInfos_() { var apps = new List(); - if (string.IsNullOrEmpty(AppInfoPath) && !File.Exists(AppInfoPath)) - return apps; - using (BinaryReader binaryReader = new(File.OpenRead(AppInfoPath))) + try { - uint num = binaryReader.ReadUInt32(); - if (num != MagicNumber) - { - Log.Error(nameof(GetAppInfos), string.Format("\"{0}\" magic code is not supported: 0x{1:X8}", Path.GetFileName(AppInfoPath), num)); + if (string.IsNullOrEmpty(AppInfoPath) && !File.Exists(AppInfoPath)) return apps; - } - SteamApp? app = new(); - unknownValueAtStart = binaryReader.ReadUInt32(); - while ((app = SteamApp.FromReader(binaryReader)) != null) + using (BinaryReader binaryReader = new(File.OpenRead(AppInfoPath))) { - if (app.AppId > 0) + uint num = binaryReader.ReadUInt32(); + if (num != MagicNumber) { - if (GameLibrarySettings.DefaultIgnoreList.Contains(app.AppId)) - continue; - if (app.ParentId > 0) + Log.Error(nameof(GetAppInfos), string.Format("\"{0}\" magic code is not supported: 0x{1:X8}", Path.GetFileName(AppInfoPath), num)); + return apps; + } + SteamApp? app = new(); + unknownValueAtStart = binaryReader.ReadUInt32(); + while ((app = SteamApp.FromReader(binaryReader)) != null) + { + if (app.AppId > 0) { - var parentApp = apps.FirstOrDefault(f => f.AppId == app.ParentId); - if (parentApp != null) - parentApp.ChildApp.Add(app.AppId); - //continue; + if (GameLibrarySettings.DefaultIgnoreList.Contains(app.AppId)) + continue; + if (app.ParentId > 0) + { + var parentApp = apps.FirstOrDefault(f => f.AppId == app.ParentId); + if (parentApp != null) + parentApp.ChildApp.Add(app.AppId); + //continue; + } + apps.Add(app); + //app.Modified += (s, e) => + //{ + //}; } - apps.Add(app); - //app.Modified += (s, e) => - //{ - //}; } } + return apps; + } + catch (Exception ex) + { + Log.Error(nameof(SteamServiceImpl), ex, nameof(GetAppInfos)); + return apps; } - return apps; } } diff --git a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs index 30e76396d..17b3e45d5 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/ProxyService.cs @@ -387,6 +387,7 @@ namespace System.Application.Services Toast.Show(msg); } } + public async Task AddNewScript(FileInfo fileInfo, ScriptDTO? info, ScriptDTO? oldInfo = null) { IsLoading = true; @@ -410,6 +411,7 @@ namespace System.Application.Services IsLoading = false; Toast.Show(item.msg); } + public async void RefreshScript() { var scriptList = await DI.Get().GetAllScript(); @@ -428,6 +430,7 @@ namespace System.Application.Services CheckUpdate(); } + public async void DownloadScript(ScriptDTO model) { model.IsLoading = true; @@ -466,6 +469,7 @@ namespace System.Application.Services Toast.Show(AppResources.Download_ScriptError); model.IsLoading = false; } + public async void CheckUpdate() { var items = Current.ProxyScripts.Items.Where(x => x.Id.HasValue).Select(x => x.Id!.Value).ToList(); diff --git a/src/ST.Client.Desktop/Services/Mvvm/SteamConnectService.cs b/src/ST.Client.Desktop/Services/Mvvm/SteamConnectService.cs index 6c36f84e0..4d6651eff 100644 --- a/src/ST.Client.Desktop/Services/Mvvm/SteamConnectService.cs +++ b/src/ST.Client.Desktop/Services/Mvvm/SteamConnectService.cs @@ -110,6 +110,19 @@ namespace System.Application.Services } #endregion + private bool _IsLoadingGameList = true; + public bool IsLoadingGameList + { + get => _IsLoadingGameList; + set + { + if (_IsLoadingGameList != value) + { + _IsLoadingGameList = value; + this.RaisePropertyChanged(); + } + } + } public void Initialize() { @@ -117,7 +130,6 @@ namespace System.Application.Services SteamTool.StartSteam(SteamSettings.SteamStratParameter.Value); Task.Run(InitializeGameList).ForgetAndDispose(); - var t = new Task(async () => { Thread.CurrentThread.IsBackground = true; @@ -144,7 +156,14 @@ namespace System.Application.Services IsSteamChinaLauncher = ApiService.IsSteamChinaLauncher(); #region 初始化需要steam启动才能使用的功能 - InitializeGameList(); + if (SteamApps.Items.Any()) + { + LoadGames(SteamApps.Items); + } + else + { + LoadGames(await ISteamService.Instance.GetAppInfos()); + } //尝试十次无法获取到就不再尝试 for (var i = 0; i < 10; i++) @@ -201,8 +220,10 @@ namespace System.Application.Services public async void InitializeGameList() { + IsLoadingGameList = true; LoadGames(await ISteamService.Instance.GetAppInfos()); //UpdateGamesImage(); + IsLoadingGameList = false; } public void UpdateGamesImage() @@ -246,6 +267,7 @@ namespace System.Application.Services { if (ApiService.Initialize()) { + SteamApps.Clear(); while (true) { InitializeGameList(); diff --git a/src/ST.Client.Desktop/UI/Resx/AppResources.Designer.cs b/src/ST.Client.Desktop/UI/Resx/AppResources.Designer.cs index c577f13e5..0a1b6de7b 100644 --- a/src/ST.Client.Desktop/UI/Resx/AppResources.Designer.cs +++ b/src/ST.Client.Desktop/UI/Resx/AppResources.Designer.cs @@ -854,6 +854,15 @@ namespace System.Application.UI.Resx { } } + /// + /// 查找类似 管理隐藏游戏列表 的本地化字符串。 + /// + public static string GameList_HideGameManger { + get { + return ResourceManager.GetString("GameList_HideGameManger", resourceCulture); + } + } + /// /// 查找类似 隐藏此游戏 的本地化字符串。 /// @@ -863,6 +872,15 @@ namespace System.Application.UI.Resx { } } + /// + /// 查找类似 管理游戏时长挂机列表 的本地化字符串。 + /// + public static string GameList_IdleGamesManger { + get { + return ResourceManager.GetString("GameList_IdleGamesManger", resourceCulture); + } + } + /// /// 查找类似 安装 的本地化字符串。 /// @@ -881,6 +899,15 @@ namespace System.Application.UI.Resx { } } + /// + /// 查找类似 正在加载游戏列表... 的本地化字符串。 + /// + public static string GameList_IsLoading { + get { + return ResourceManager.GetString("GameList_IsLoading", resourceCulture); + } + } + /// /// 查找类似 仅显示已安装的游戏 的本地化字符串。 /// diff --git a/src/ST.Client.Desktop/UI/Resx/AppResources.resx b/src/ST.Client.Desktop/UI/Resx/AppResources.resx index 74719a243..d09c788a8 100644 --- a/src/ST.Client.Desktop/UI/Resx/AppResources.resx +++ b/src/ST.Client.Desktop/UI/Resx/AppResources.resx @@ -384,15 +384,24 @@ 编辑游戏信息 + + 管理隐藏游戏列表 + 隐藏此游戏 + + 管理游戏时长挂机列表 + 安装 没有获取到任何游戏数据 + + 正在加载游戏列表... + 仅显示已安装的游戏 diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs index bed630185..aeddcb688 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/CommunityProxyPageViewModel.cs @@ -14,8 +14,6 @@ namespace System.Application.UI.ViewModels { public class CommunityProxyPageViewModel : TabItemViewModel { - readonly IHttpProxyService httpProxyService = DI.Get(); - public override string Name { get => AppResources.CommunityFix; @@ -105,12 +103,12 @@ namespace System.Application.UI.ViewModels public void SetupCertificate_OnClick() { - httpProxyService.SetupCertificate(); + DI.Get().SetupCertificate(); } public void DeleteCertificate_OnClick() { - httpProxyService.DeleteCertificate(); + DI.Get().DeleteCertificate(); } public void EditHostsFile_OnClick() diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs index f91ec5b9b..910363d6d 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/GameListPageViewModel.cs @@ -111,6 +111,13 @@ namespace System.Application.UI.ViewModels this.RaisePropertyChanged(nameof(IsSteamAppsEmpty)); this.CalcTypeCount(); }); + + + MenuItems = new ObservableCollection() + { + new MenuItemViewModel(nameof(AppResources.GameList_HideGameManger)), + new MenuItemViewModel (nameof(AppResources.GameList_IdleGamesManger)), + }; } internal override void Activation() @@ -158,8 +165,7 @@ namespace System.Application.UI.ViewModels set => this.RaiseAndSetIfChanged(ref _SearchText, value); } - public bool IsSteamAppsLoading => IsSteamAppsEmpty; - public bool IsSteamAppsEmpty => !SteamApps.Any_Nullable(); + public bool IsSteamAppsEmpty => !SteamApps.Any_Nullable() && !SteamConnectService.Current.IsLoadingGameList; private ObservableCollection> _AppTypeFiltres = new(); public ObservableCollection> AppTypeFiltres @@ -168,7 +174,6 @@ namespace System.Application.UI.ViewModels set => this.RaiseAndSetIfChanged(ref _AppTypeFiltres, value); } - private IReadOnlyCollection> _EnableAppTypeFiltres = new List>(); public IReadOnlyCollection> EnableAppTypeFiltres { diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/PasswordWindowViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/PasswordWindowViewModel.cs new file mode 100644 index 000000000..d11a46e58 --- /dev/null +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/LocalAuthPage/PasswordWindowViewModel.cs @@ -0,0 +1,24 @@ +using Newtonsoft.Json.Linq; +using ReactiveUI; +using System.Application.Models; +using System.Application.UI.Resx; +using System.Properties; + +namespace System.Application.UI.ViewModels +{ + public class PasswordWindowViewModel : WindowViewModel + { + public PasswordWindowViewModel() : base() + { + Title = ThisAssembly.AssemblyTrademark + " | " + AppResources.LocalAuth_AuthData; + } + + private string? _Password; + public string? Password + { + get => _Password; + set => this.RaiseAndSetIfChanged(ref _Password, value); + } + + } +} \ No newline at end of file