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 17d9f390c..5443ac87f 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 @@ -217,7 +217,7 @@ ToolTip.Tip="{ReflectionBinding Path=Res.GameList_ResizeAppLogo,Mode=OneWay,Source={x:Static resx:R.Current}}" Label="{ReflectionBinding Path=Res.GameList_ResizeAppLogo,Mode=OneWay,Source={x:Static resx:R.Current}}"> - diff --git a/src/ST.Client.Desktop.Windows/Services/Implementation/SteamServiceImpl.cs b/src/ST.Client.Desktop.Windows/Services/Implementation/SteamServiceImpl.cs index 18d907338..a858e326c 100644 --- a/src/ST.Client.Desktop.Windows/Services/Implementation/SteamServiceImpl.cs +++ b/src/ST.Client.Desktop.Windows/Services/Implementation/SteamServiceImpl.cs @@ -140,7 +140,9 @@ namespace System.Application.Services.Implementation { if (OperatingSystem2.IsWindows) { +#pragma warning disable CA1416 // 验证平台兼容性 platformService.StartAsInvoker(SteamProgramPath, arguments); +#pragma warning restore CA1416 // 验证平台兼容性 } else { @@ -507,6 +509,32 @@ namespace System.Application.Services.Implementation } } + /// + /// 保存修改后的游戏数据到steam本地客户端缓存文件 + /// + public bool SaveAppInfosToSteam() + { + if (string.IsNullOrEmpty(AppInfoPath) && !File.Exists(AppInfoPath)) + return false; + + using (BinaryWriter binaryWriter = new (new MemoryStream())) + { + binaryWriter.Write(MagicNumber); + binaryWriter.Write(univeseNumber); + foreach (SteamApp app in SteamConnectService.Current.SteamApps.Items) + { + app.Write(binaryWriter); + } + binaryWriter.Write(0); + using (FileStream fileStream = File.Open(AppInfoPath, FileMode.Create, FileAccess.Write)) + { + binaryWriter.BaseStream.Position = 0L; + binaryWriter.BaseStream.CopyTo(fileStream); + } + } + return false; + } + public uint[] GetInstalledAppIds() { return GetDownloadingAppList().Where(x => x.IsInstalled).Select(x => x.AppId).ToArray(); diff --git a/src/ST.Client/Models/Steam/SteamApp.cs b/src/ST.Client/Models/Steam/SteamApp.cs index 886930606..2d634a982 100644 --- a/src/ST.Client/Models/Steam/SteamApp.cs +++ b/src/ST.Client/Models/Steam/SteamApp.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Security.Cryptography; +using System.Text; using System.Threading.Tasks; using static System.Application.SteamApiUrls; @@ -543,6 +545,64 @@ namespace System.Application.Models return app; } + public void Write(BinaryWriter writer) + { + this.ClearCachedProps(); + SteamAppPropertyTable propertyTable = new SteamAppPropertyTable(this._properties); + SteamAppPropertyTable? propertyValue = propertyTable.GetPropertyValue(null, NodeAppInfo, NodeCommon); + if (propertyValue != null) + { + string? text = Name; + if (text != null) + { + SteamAppPropertyTable? propertyValue2 = propertyValue.GetPropertyValue(null, "name_localized"); + if (propertyValue2 != null) + { + propertyTable.SetPropertyValue(SteamAppPropertyType.Table, propertyValue2, NodeAppInfo, "steam_edit", "base_name_localized"); + propertyValue.RemoveProperty("name_localized"); + } + propertyTable.SetPropertyValue(SteamAppPropertyType.String, text, NodeAppInfo, "steam_edit", "base_name"); + //if (SteamData.UseCompleted && this.IsCompleted) + //{ + // text += SteamData.CompletedSuffix; + //} + propertyValue.SetPropertyValue("name", SteamAppPropertyType.String, text); + } + else + { + Log.Info("SteamApp Write Error", $"AppInfo {AppId:X8} has null name!"); + } + string? text2 = propertyValue.GetPropertyValue("type", "game"); + if (text2 != null) + { + propertyTable.SetPropertyValue(SteamAppPropertyType.String, text2, NodeAppInfo, "steam_edit", "base_type"); + //if (SteamData.UseHidden && this.IsHidden) + //{ + // text2 = "hidden_" + text2; + //} + propertyValue.SetPropertyValue("type", SteamAppPropertyType.String, text2); + } + else + { + Log.Info("SteamApp Write Error", $"AppInfo {AppId:X8} has null type!"); + } + } + string s = propertyTable.ToString(); + byte[] bytes = Encoding.UTF8.GetBytes(s); + byte[] buffer = SHA1.Create().ComputeHash(bytes); + writer.Write(this.AppId); + using (BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream())) + { + binaryWriter.Write(this._stuffBeforeHash); + binaryWriter.Write(buffer); + binaryWriter.Write(this._changeNumber); + SteamAppPropertyHelper.Write(binaryWriter, propertyTable); + MemoryStream memoryStream = (MemoryStream)binaryWriter.BaseStream; + writer.Write((int)memoryStream.Length); + writer.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length); + } + } + private static bool IsBitSet(int b, int pos) { return (b & (1 << pos)) != 0; diff --git a/src/ST.Client/Services/IPlatformService.Windows.cs b/src/ST.Client/Services/IPlatformService.Windows.cs index 366831f58..300c82107 100644 --- a/src/ST.Client/Services/IPlatformService.Windows.cs +++ b/src/ST.Client/Services/IPlatformService.Windows.cs @@ -21,7 +21,7 @@ namespace System.Application.Services } /// - /// 已正常权限启动进程 + /// 以正常权限启动进程 /// /// ///