From a669560415c0d041cfebf39df3cfb44ab90ee5c8 Mon Sep 17 00:00:00 2001 From: mossimo Date: Mon, 21 Jun 2021 17:55:51 +0800 Subject: [PATCH] shareManage --- .../ShareManagePage/ShareManageWindow.axaml | 182 ++++++++++++++++++ .../ShareManageWindow.axaml.cs | 23 +++ .../ST.Client.Desktop.Avalonia.csproj | 6 + src/ST.Client.Desktop/CustomWindow.cs | 1 + .../Models/AuthorizedDevice.cs | 52 ++++- .../Services/ISteamService.cs | 2 + .../Implementation/SteamServiceImpl.cs | 49 ++++- .../Pages/SteamAccountPageViewModel.cs | 8 + .../ShareManagePage/ShareManageViewModel.cs | 119 ++++++++++++ 9 files changed, 433 insertions(+), 9 deletions(-) create mode 100644 src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/ShareManagePage/ShareManageWindow.axaml create mode 100644 src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/ShareManagePage/ShareManageWindow.axaml.cs create mode 100644 src/ST.Client.Desktop/UI/ViewModels/Windows/ShareManagePage/ShareManageViewModel.cs diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/ShareManagePage/ShareManageWindow.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/ShareManagePage/ShareManageWindow.axaml new file mode 100644 index 000000000..24e75531d --- /dev/null +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/ShareManagePage/ShareManageWindow.axaml @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/ShareManagePage/ShareManageWindow.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/ShareManagePage/ShareManageWindow.axaml.cs new file mode 100644 index 000000000..dc2e384a5 --- /dev/null +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/ShareManagePage/ShareManageWindow.axaml.cs @@ -0,0 +1,23 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using System.Application.UI.ViewModels; + +namespace System.Application.UI.Views.Windows +{ + public class ShareManageWindow : FluentWindow + { + public ShareManageWindow() : 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 ec9ef33d6..cfa9e30ef 100644 --- a/src/ST.Client.Desktop.Avalonia/ST.Client.Desktop.Avalonia.csproj +++ b/src/ST.Client.Desktop.Avalonia/ST.Client.Desktop.Avalonia.csproj @@ -57,4 +57,10 @@ + + + ShareManageWindow.axaml + + + \ No newline at end of file diff --git a/src/ST.Client.Desktop/CustomWindow.cs b/src/ST.Client.Desktop/CustomWindow.cs index 5095a9c35..8bc1b1541 100644 --- a/src/ST.Client.Desktop/CustomWindow.cs +++ b/src/ST.Client.Desktop/CustomWindow.cs @@ -17,6 +17,7 @@ namespace System.Application ScriptStore, HideApp, IdleApp, + ShareManage, ChangeBindPhoneNumber, UserProfile, NewVersion, diff --git a/src/ST.Client.Desktop/Models/AuthorizedDevice.cs b/src/ST.Client.Desktop/Models/AuthorizedDevice.cs index ea6d13ff1..86d3bca00 100644 --- a/src/ST.Client.Desktop/Models/AuthorizedDevice.cs +++ b/src/ST.Client.Desktop/Models/AuthorizedDevice.cs @@ -8,12 +8,62 @@ namespace System.Application.Models { public class AuthorizedDevice : ReactiveObject { - public string? SteamId3 { get; set; } + public const long UndefinedId = 76561197960265728; + public AuthorizedDevice(){} + public AuthorizedDevice(string vdfString) :this(){ + + OriginVdfString = vdfString; + } + public string ProfileUrl => string.Format(STEAM_PROFILES_URL, SteamId64_Int); + public long SteamId3_Int { get; set; } + public long SteamId64_Int => UndefinedId + SteamId3_Int; + private string? _OnlineState; + public string? OnlineState + { + get => _OnlineState; + set => this.RaiseAndSetIfChanged(ref _OnlineState, value); + } + private string? _Remark; + /// + /// 备注 + /// + public string? Remark + { + get => _Remark; + set => this.RaiseAndSetIfChanged(ref _Remark, value); + } + public string? SteamID { get; set; } + public string? ShowName { get; set; } + public string? SteamNickName { get; set; } + /// + /// 用户名 + /// + public string? AccountName { get; set; } public long Timeused { get; set; } + public DateTime TimeusedTime => Timeused.ToDateTimeS(); + + public string? Description { get; set; } public string? Tokenid { get; set; } + + public string AvatarIcon { get; set; } + public string AvatarMedium { get; set; } + + private Task? _AvatarStream; + public Task? AvatarStream + { + get => _AvatarStream; + set => this.RaiseAndSetIfChanged(ref _AvatarStream, value); + } + + public string? OriginVdfString { get; set; } + public string CurrentVdfString => + "\"" + SteamId3_Int + "\"\n{\n" + + "\t\t\"timeused\"\t\t\"" + Timeused + "\"\n" + + "\t\t\"description\"\t\t\"" + Description + "\"\n" + + "\t\t\"tokenid\"\t\t\"" + Tokenid + "\"\n"; } } \ No newline at end of file diff --git a/src/ST.Client.Desktop/Services/ISteamService.cs b/src/ST.Client.Desktop/Services/ISteamService.cs index 6d642a1e4..0d5bc12b6 100644 --- a/src/ST.Client.Desktop/Services/ISteamService.cs +++ b/src/ST.Client.Desktop/Services/ISteamService.cs @@ -71,6 +71,8 @@ namespace System.Application.Services /// List GetRememberUserList(); + bool UpdateAuthorizedDeviceList(AuthorizedDevice list); + bool RemoveAuthorizedDeviceList(AuthorizedDevice list); /// /// 获取所有当前PC共享授权信息 /// diff --git a/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs b/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs index 5fece07f9..7e5597b9b 100644 --- a/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs +++ b/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs @@ -42,7 +42,7 @@ namespace System.Application.Services.Implementation readonly IDesktopPlatformService platformService; readonly string? mSteamDirPath; readonly string? mSteamProgramPath; - readonly string[] steamProcess = new[] { "steam","steam_osx", "steamservice", "steamwebhelper" }; + readonly string[] steamProcess = new[] { "steam", "steam_osx", "steamservice", "steamwebhelper" }; readonly Lazy _http = new(() => DI.Get()); IHttpService Http => _http.Value; @@ -189,7 +189,40 @@ namespace System.Application.Services.Implementation } return users; } - + public bool UpdateAuthorizedDeviceList(AuthorizedDevice model) + { + try + { + if (!string.IsNullOrWhiteSpace(ConfigVdfPath) && File.Exists(ConfigVdfPath)) + { + VdfHelper.UpdateValueByReplace(ConfigVdfPath, model.OriginVdfString.ThrowIsNull(nameof(model.OriginVdfString)), model.CurrentVdfString); + return true; + } + } + catch (Exception e) + { + Log.Error(TAG, e, "UpdateAuthorizedDeviceList Fail(0)."); + return false; + } + return false; + } + public bool RemoveAuthorizedDeviceList(AuthorizedDevice model) + { + try + { + if (!string.IsNullOrWhiteSpace(ConfigVdfPath) && File.Exists(ConfigVdfPath)) + { + VdfHelper.DeleteValueByKey(ConfigVdfPath, model.OriginVdfString.ThrowIsNull(nameof(model.OriginVdfString))); + return true; + } + } + catch (Exception e) + { + Log.Error(TAG, e, "RemoveAuthorizedDeviceList Fail(0)."); + return false; + } + return false; + } public List GetAuthorizedDeviceList() { var authorizeds = new List(); @@ -199,7 +232,7 @@ namespace System.Application.Services.Implementation { // 注意:动态类型在移动端受限,且运行时可能抛出异常 dynamic v = VdfHelper.Read(ConfigVdfPath); - var authorizedDevice = v.Value.AuthorizedDevice.Value; + var authorizedDevice = v.Value.AuthorizedDevice; if (authorizedDevice != null) { foreach (var item in authorizedDevice) @@ -207,12 +240,12 @@ namespace System.Application.Services.Implementation try { var i = item.Value; - authorizeds.Add(new AuthorizedDevice() + authorizeds.Add(new AuthorizedDevice(item.ToString()) { - SteamId3 = item.Key, - Timeused = i.timeused, - Description = i.description, - Tokenid = i.tokenid, + SteamId3_Int = Convert.ToInt64(item.Key.ToString()), + Timeused = Convert.ToInt64(i.timeused.ToString()), + Description = i.description.ToString(), + Tokenid = i.tokenid.ToString(), }); } catch (Exception e) diff --git a/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs index b40971a3d..eab24534b 100644 --- a/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs +++ b/src/ST.Client.Desktop/UI/ViewModels/Pages/SteamAccountPageViewModel.cs @@ -38,6 +38,7 @@ namespace System.Application.UI.ViewModels LoginAccountCommand = ReactiveCommand.Create(LoginNewSteamAccount); RefreshCommand = ReactiveCommand.Create(Initialize); + ShareManageCommand = ReactiveCommand.Create(OpenShareManageWindow); MenuItems = new ObservableCollection() { //new MenuItemViewModel(nameof(AppResources.More)) @@ -47,6 +48,8 @@ namespace System.Application.UI.ViewModels new MenuItemViewModel(nameof(AppResources.UserChange_LoginNewAccount)) { IconKey="SteamDrawing", Command=LoginAccountCommand }, new MenuItemViewModel (), + new MenuItemViewModel(nameof(AppResources.GameList_HideGameManger)){ + IconKey ="EyeHideDrawing", Command = ShareManageCommand }, new MenuItemViewModel (nameof(AppResources.Refresh)) { IconKey="RefreshDrawing" , Command = RefreshCommand}, // } @@ -66,6 +69,11 @@ namespace System.Application.UI.ViewModels public ReactiveCommand LoginAccountCommand { get; } public ReactiveCommand RefreshCommand { get; } + public ReactiveCommand ShareManageCommand { get; } + public void OpenShareManageWindow() + { + IShowWindowService.Instance.Show(CustomWindow.ShareManage, new ShareManageViewModel(), string.Empty, ResizeModeCompat.CanResize); + } /// /// steam记住的用户列表 diff --git a/src/ST.Client.Desktop/UI/ViewModels/Windows/ShareManagePage/ShareManageViewModel.cs b/src/ST.Client.Desktop/UI/ViewModels/Windows/ShareManagePage/ShareManageViewModel.cs new file mode 100644 index 000000000..c32b0706d --- /dev/null +++ b/src/ST.Client.Desktop/UI/ViewModels/Windows/ShareManagePage/ShareManageViewModel.cs @@ -0,0 +1,119 @@ +using DynamicData; +using DynamicData.Binding; +using Newtonsoft.Json.Linq; +using ReactiveUI; +using System.Application.Models; +using System.Application.Models.Settings; +using System.Application.Services; +using System.Application.UI.Resx; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Globalization; +using System.Linq; +using System.Properties; +using System.Reactive.Linq; +using System.Threading.Tasks; + +namespace System.Application.UI.ViewModels +{ + public class ShareManageViewModel : WindowViewModel + { + readonly ISteamService steamService = DI.Get(); + readonly IHttpService httpService = DI.Get(); + readonly ISteamworksWebApiService webApiService = DI.Get(); + public ShareManageViewModel() : base() + { + Title = ThisAssembly.AssemblyTrademark + " q| " + AppResources.GameList_HideGameManger; + this.WhenAnyValue(x => x.AuthorizedList) + .Subscribe(s => this.RaisePropertyChanged(nameof(IsAuthorizedListEmpty))); + + _AuthorizedSourceList = new SourceCache(t => t.SteamId3_Int); + _AuthorizedSourceList + .Connect() + .ObserveOn(RxApp.MainThreadScheduler) + .Sort(SortExpressionComparer.Descending(x => x.Timeused)) + .Bind(out _AuthorizedList) + .Subscribe(); + + Refresh_Click(); + } + public bool _IsAuthorizedListEmpty; + public bool IsAuthorizedListEmpty + { + get => _IsAuthorizedListEmpty; + set => this.RaiseAndSetIfChanged(ref _IsAuthorizedListEmpty, value); + } + + private ReadOnlyObservableCollection? _AuthorizedList; + public ReadOnlyObservableCollection? AuthorizedList => _AuthorizedList; + + public SourceCache< AuthorizedDevice, long> _AuthorizedSourceList; + public SourceCache AuthorizedSourceList + { + get => _AuthorizedSourceList; + set => this.RaiseAndSetIfChanged(ref _AuthorizedSourceList, value); + } + //private string? _SearchText; + //public string? SearchText + //{ + // get => _SearchText; + // set => this.RaiseAndSetIfChanged(ref _SearchText, value); + //} + + public void Refresh_Click() + { + var list = new List(); + + var userlist = steamService.GetRememberUserList(); + var id = string.Empty; + foreach (var item in steamService.GetAuthorizedDeviceList()) + { + var user = userlist.FirstOrDefault(x => x.SteamId3_Int == item.SteamId3_Int); + item.SteamNickName = user?.SteamNickName; + item.ShowName = item.SteamNickName + $"({item.SteamId64_Int})"; + item.AccountName = user?.AccountName; + list.Add( item); + } + if (list.Count == 0) + IsAuthorizedListEmpty = true; + else + IsAuthorizedListEmpty = false; + _AuthorizedSourceList.AddOrUpdate(list); + _AuthorizedSourceList.Refresh(); + Refresh_Cash().ConfigureAwait(false); + } + public async Task Refresh_Cash() { + + var accountRemarks = Serializable.Clone?>(SteamAccountSettings.AccountRemarks.Value); + foreach (var user in _AuthorizedSourceList.Items) + { + string? remark = null; + var temp = await webApiService.GetUserInfo(user.SteamId64_Int); + accountRemarks?.TryGetValue(user.SteamId64_Int, out remark); + user.Remark = remark; + user.SteamID = temp.SteamID; + user.OnlineState = temp.OnlineState; + user.SteamNickName = temp.SteamNickName; + user.AvatarIcon = temp.AvatarIcon; + user.AvatarMedium = temp.AvatarMedium; + user.AvatarStream = httpService.GetImageAsync(temp.AvatarFull, ImageChannelType.SteamAvatars); + } + _AuthorizedSourceList.Refresh(); + } + public void SteamId_Click(AuthorizedDevice user) + { + + } + public void DeleteButton_Click(AuthorizedDevice user) + { + + } + + + public void SetActivity_Click(AuthorizedDevice item) + { + steamService.UpdateAuthorizedDeviceList(item); + Refresh_Click(); + } + } +} \ No newline at end of file