From a495cd285665f78431a3f3caeea41d36434bddbb Mon Sep 17 00:00:00 2001 From: Mossimo Date: Tue, 8 Feb 2022 18:32:32 +0800 Subject: [PATCH] Script SaveSqlite SteamAccountChange Fix VdfSaveType Share Disable --- .../SteamAccountPage/ShareManageWindow.axaml | 275 +++++++++++------- .../Implementation/SteamServiceImpl.cs | 69 +++-- src/ST.Client.Desktop.Windows/VdfHelper.cs | 13 +- src/ST.Client/Entities/Script.cs | 11 +- src/ST.Client/Models/AuthorizedDevice.cs | 16 +- src/ST.Client/Models/Steam/SteamUser.cs | 41 ++- .../Repositories/IScriptRepository.cs | 1 + .../Implementation/ScriptRepository.cs | 18 +- src/ST.Client/Services/IScriptManager.cs | 9 +- src/ST.Client/Services/ISteamService.cs | 2 +- .../Services/Implementation/ScriptManager.cs | 4 +- src/ST.Client/Services/Mvvm/ProxyService.cs | 46 +-- .../Settings/SteamAccountSettings.cs | 8 +- .../UI/Resx/AppResources.Designer.cs | 38 ++- src/ST.Client/UI/Resx/AppResources.resx | 14 +- .../Pages/SteamAccountPageViewModel.cs | 18 +- .../SteamAccountPage/ShareManageViewModel.cs | 31 +- 17 files changed, 405 insertions(+), 209 deletions(-) diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/SteamAccountPage/ShareManageWindow.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/SteamAccountPage/ShareManageWindow.axaml index 07568d1f7..6548ac47f 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/SteamAccountPage/ShareManageWindow.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Windows/SteamAccountPage/ShareManageWindow.axaml @@ -62,87 +62,107 @@ Classes="paper" Background="{DynamicResource ThemeBrushKey}" Margin="10 0"> - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - + + + - - - - - + + + + + - + - - - - - - - - - + + + + + + + + + - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + + + + + diff --git a/src/ST.Client.Desktop.Windows/Services/Implementation/SteamServiceImpl.cs b/src/ST.Client.Desktop.Windows/Services/Implementation/SteamServiceImpl.cs index 8cb5f393b..073b09e29 100644 --- a/src/ST.Client.Desktop.Windows/Services/Implementation/SteamServiceImpl.cs +++ b/src/ST.Client.Desktop.Windows/Services/Implementation/SteamServiceImpl.cs @@ -165,7 +165,7 @@ namespace System.Application.Services.Implementation try { var i = item.Value; - var user = new SteamUser(item.ToString()) + var user = new SteamUser() { SteamId64 = Convert.ToInt64(item.Key.ToString()), AccountName = i.AccountName?.ToString(), @@ -216,28 +216,19 @@ namespace System.Application.Services.Implementation var authorizedDevice = v.Value.AuthorizedDevice; if (authorizedDevice != null) { - foreach (var item in authorizedDevice) - { - try - { - var i = item.Value; - authorizeds.Add(new AuthorizedDevice(item.ToString()) - { - SteamId3_Int = Convert.ToInt64(item.Key.ToString()), - Timeused = Convert.ToInt64(i.timeused.ToString()), - Description = i.description.ToString(), - Tokenid = i.tokenid.ToString(), - }); - } - catch (Exception e) - { - Log.Error(TAG, e, "GetAuthorizedDeviceList Fail(0)."); - } + + var lists = new VObject(); + foreach (var item in model.OrderBy(x=>x.Index)) + { + VObject itemTemp=new VObject(); + itemTemp.Add("timeused", new VValue(item.Timeused)); + itemTemp.Add("description", new VValue(item.Description)); + itemTemp.Add("tokenid", new VValue(item.Tokenid)); + + lists.Add(item.SteamId3_Int.ToString(), itemTemp); } - var oldStr = $"\t{{\n{string.Join("\n", authorizeds.Select(x => x.CurrentVdfString))}\n\t}}".TrimEnd("\n"); - //authorizedDevice.Select(x => x.ToString()); - var newStr = $"\t{{\n{string.Join("\n", model.OrderBy(x => x.Index).Select(x => x.CurrentVdfString))}\n\t}}".TrimEnd("\n"); - VdfHelper.UpdateValueByReplaceNoPattern(ConfigVdfPath, oldStr, newStr); + v.Value.AuthorizedDevice = lists; + VdfHelper.Write(ConfigVdfPath, v); return true; } else @@ -388,7 +379,7 @@ namespace System.Application.Services.Implementation } } - public void UpdateLocalUserData(SteamUser user) + public void UpdateLocalUserData(IEnumerable user) { if (string.IsNullOrWhiteSpace(UserVdfPath)) { @@ -396,11 +387,32 @@ namespace System.Application.Services.Implementation } else { - var originVdfStr = user.OriginVdfString; - VdfHelper.UpdateValueByReplace( - UserVdfPath, - originVdfStr.ThrowIsNull(nameof(originVdfStr)), - user.CurrentVdfString); + if (File.Exists(UserVdfPath)) + { + dynamic models = VdfHelper.Read(UserVdfPath); + foreach (var item in models.Value.Children()) + { + try + { + var itemUser = user.FirstOrDefault(x => x.SteamId64.ToString() == item.Key); + if (itemUser == null) + { + item.Value.MostRecent = item.Value.MostRecent == 1 ? 0 : 1; + break; + } + item.Value.MostRecent = Convert.ToByte(itemUser.MostRecent); + item.Value.Timestamp = itemUser.Timestamp; + item.Value.WantsOfflineMode = Convert.ToByte(itemUser.WantsOfflineMode); + item.Value.SkipOfflineModeWarning = Convert.ToByte(itemUser.SkipOfflineModeWarning); + } + catch (Exception e) + { + Log.Error(TAG, e, "GetUserVdfPath for catch"); + } + } + + VdfHelper.Write(UserVdfPath, models); + } } } @@ -863,6 +875,7 @@ namespace System.Application.Services.Implementation } return keys; } + } } diff --git a/src/ST.Client.Desktop.Windows/VdfHelper.cs b/src/ST.Client.Desktop.Windows/VdfHelper.cs index e028d9014..090ab3be6 100644 --- a/src/ST.Client.Desktop.Windows/VdfHelper.cs +++ b/src/ST.Client.Desktop.Windows/VdfHelper.cs @@ -19,7 +19,18 @@ namespace System.Application { var text = File.ReadAllText(filePath, Encoding.UTF8); return VdfConvert.Deserialize(text); - } + } + public static void Write(string filePath, VProperty content) + { + try + { + File.WriteAllText(filePath, VdfConvert.Serialize(content), Encoding.UTF8); + } + catch (Exception e) + { + Log.Error(nameof(VdfHelper), e, "Write Vdf Error"); + } + } public static void UpdateValueByReplaceNoPattern(string filePath, string oldVaule, string newValue) { var text = File.ReadAllText(filePath, Encoding.UTF8); diff --git a/src/ST.Client/Entities/Script.cs b/src/ST.Client/Entities/Script.cs index 5554ae0e5..c6e2e6346 100644 --- a/src/ST.Client/Entities/Script.cs +++ b/src/ST.Client/Entities/Script.cs @@ -1,4 +1,4 @@ -#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 +#pragma warning disable CS8618 // 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。 using SQLite; using System.Application.Columns; using System.Diagnostics; @@ -12,13 +12,16 @@ namespace System.Application.Entities /// /// 脚本 /// - [SQLiteTable("1B2D820C")] + [SQLiteTable(TableName)] [DebuggerDisplay("{DebuggerDisplay(),nq}")] public class Script : IEntity, IOrder { + public const string TableName = "1B2D820C"; + public const string ColumnName_Id = "E386BC36"; + public const string ColumnName_Enable = "6DB11594"; string DebuggerDisplay() => $"{Name}, {Id}"; - [Column("E386BC36")] + [Column(ColumnName_Id)] [PrimaryKey] [AutoIncrement] public int Id { get; set; } @@ -99,7 +102,7 @@ namespace System.Application.Entities /// /// 是否启用 /// - [Column("6DB11594")] + [Column(ColumnName_Enable)] public bool Enable { get; set; } = false; /// diff --git a/src/ST.Client/Models/AuthorizedDevice.cs b/src/ST.Client/Models/AuthorizedDevice.cs index 495120c6d..1c00f115f 100644 --- a/src/ST.Client/Models/AuthorizedDevice.cs +++ b/src/ST.Client/Models/AuthorizedDevice.cs @@ -2,6 +2,8 @@ using ReactiveUI; using System.Threading.Tasks; using static System.Application.SteamApiUrls; +using MPKey = MessagePack.KeyAttribute; +using MPObj = MessagePack.MessagePackObjectAttribute; namespace System.Application.Models { public class AuthorizedDevice : ReactiveObject @@ -16,7 +18,7 @@ namespace System.Application.Models { OriginVdfString = vdfString; } - + public bool Disable { get; set; } public string ProfileUrl => string.Format(STEAM_PROFILES_URL, SteamId64_Int); public bool First { get; set; } @@ -86,4 +88,16 @@ namespace System.Application.Models "\t\t\t\"description\"\t\t\"" + Description + "\"\n" + "\t\t\t\"tokenid\"\t\t\"" + Tokenid + "\"\n\t\t}"; } + [MPObj] + public class DisableAuthorizedDevice + { + [MPKey(0)] + public long SteamId3_Int { get; set; } + [MPKey(1)] + public long Timeused { get; set; } + [MPKey(2)] + public string? Description { get; set; } + [MPKey(3)] + public string? Tokenid { get; set; } + } } \ No newline at end of file diff --git a/src/ST.Client/Models/Steam/SteamUser.cs b/src/ST.Client/Models/Steam/SteamUser.cs index 785a61dc9..67b55e72c 100644 --- a/src/ST.Client/Models/Steam/SteamUser.cs +++ b/src/ST.Client/Models/Steam/SteamUser.cs @@ -15,11 +15,6 @@ namespace System.Application.Models { } - public SteamUser(string vdfstring) : this() - { - OriginVdfString = vdfstring; - } - [XmlIgnore] public string? SteamId3 { get; set; } @@ -194,24 +189,24 @@ namespace System.Application.Models set => this.RaiseAndSetIfChanged(ref _MiniProfile, value); } - /// - /// 来源 Valve Data File 字符串 - /// - [XmlIgnore] - public string? OriginVdfString { get; set; } + ///// + ///// 来源 Valve Data File 字符串 + ///// + //[XmlIgnore] + //public string? OriginVdfString { get; set; } - /// - /// 导出 Valve Data File 配置字符串 - /// - [XmlIgnore] - public string CurrentVdfString => - "\"" + SteamId64 + "\"\n{\n" + - "\t\t\"AccountName\"\t\t\"" + AccountName + "\"\n" + - "\t\t\"PersonaName\"\t\t\"" + PersonaName + "\"\n" + - "\t\t\"RememberPassword\"\t\t\"" + Convert.ToByte(RememberPassword) + "\"\n" + - "\t\t\"MostRecent\"\t\t\"" + Convert.ToByte(MostRecent) + "\"\n" + - "\t\t\"WantsOfflineMode\"\t\t\"" + Convert.ToByte(WantsOfflineMode) + "\"\n" + - "\t\t\"SkipOfflineModeWarning\"\t\t\"" + Convert.ToByte(SkipOfflineModeWarning) + "\"\n" + - "\t\t\"Timestamp\"\t\t\"" + Timestamp + "\"\n}"; + ///// + ///// 导出 Valve Data File 配置字符串 + ///// + //[XmlIgnore] + //public string CurrentVdfString => + // "\"" + SteamId64 + "\"\n{\n" + + // "\t\t\"AccountName\"\t\t\"" + AccountName + "\"\n" + + // "\t\t\"PersonaName\"\t\t\"" + PersonaName + "\"\n" + + // "\t\t\"RememberPassword\"\t\t\"" + Convert.ToByte(RememberPassword) + "\"\n" + + // "\t\t\"MostRecent\"\t\t\"" + Convert.ToByte(MostRecent) + "\"\n" + + // "\t\t\"WantsOfflineMode\"\t\t\"" + Convert.ToByte(WantsOfflineMode) + "\"\n" + + // "\t\t\"SkipOfflineModeWarning\"\t\t\"" + Convert.ToByte(SkipOfflineModeWarning) + "\"\n" + + // "\t\t\"Timestamp\"\t\t\"" + Timestamp + "\"\n}"; } } \ No newline at end of file diff --git a/src/ST.Client/Repositories/IScriptRepository.cs b/src/ST.Client/Repositories/IScriptRepository.cs index 905eb0f01..d72fa8046 100644 --- a/src/ST.Client/Repositories/IScriptRepository.cs +++ b/src/ST.Client/Repositories/IScriptRepository.cs @@ -19,5 +19,6 @@ namespace System.Application.Repositories Task