From 40b41fb353e881b3d6e8e7fb9cffc475292353ac Mon Sep 17 00:00:00 2001 From: laolarou Date: Sat, 1 Apr 2023 17:31:24 -0700 Subject: [PATCH] add support for NativeAOT now you can use ProjBobcat with NativeAOT! remove icrosoft.Extensions.DependencyInjection.Abstractions change the way of using HttpClientHelper remove ServiceHelper update readme --- .../Class/Helper/AuthPropertyHelper.cs | 10 ++- .../Class/Helper/CurseForgeAPIHelper.cs | 73 +++++++++++++++---- .../ProjBobcat/Class/Helper/DownloadHelper.cs | 7 +- .../Helper/GameResourcesResolveHelper.cs | 12 +-- .../Class/Helper/HttpClientHelper.cs | 40 +++++++--- .../ProjBobcat/Class/Helper/HttpHelper.cs | 2 +- .../ProjBobcat/Class/Helper/JsonHelper.cs | 13 ++-- .../ProjBobcat/Class/Helper/JwtTokenHelper.cs | 6 +- .../Class/Helper/ModrinthAPIHelper.cs | 12 +-- .../ProjBobcat/Class/Helper/ServiceHelper.cs | 25 ------- .../Class/Model/AssetObjectModel.cs | 7 +- .../CurseForge/API/FeaturedQueryOptions.cs | 5 ++ .../CurseForge/CurseForgeManifestModel.cs | 5 ++ .../Class/Model/Fabric/FabricModInfoModel.cs | 5 ++ .../Class/Model/Forge/ForgeInstallProfile.cs | 5 ++ .../Model/Forge/LegacyForgeInstallProfile.cs | 12 +++ .../Model/GameResource/GameModInfoModel.cs | 13 +++- .../GameResource/GameResourcePackModel.cs | 5 ++ .../ProjBobcat/Class/Model/GameRulesModel.cs | 6 ++ .../Model/JsonContexts/DictionaryContext.cs | 9 +++ .../Model/JsonContexts/JsonElementContext.cs | 10 +++ .../Class/Model/JsonContexts/StringContext.cs | 9 +++ .../ProjBobcat/Class/Model/JvmRulesModel.cs | 6 ++ .../LauncherAccount/LauncherAccountModel.cs | 5 ++ .../LauncherProfile/LauncherProfileModel.cs | 7 +- .../Microsoft/Graph/DeviceIdResponseModel.cs | 5 ++ .../Microsoft/Graph/GraphAuthResultModel.cs | 5 ++ .../Graph/GraphResponseErrorModel.cs | 5 ++ .../MicrosoftAuth/AuthMojangResponseModel.cs | 5 ++ .../MicrosoftAuth/AuthXBLRequestModel.cs | 9 ++- .../Model/MicrosoftAuth/AuthXSTSErrorModel.cs | 9 ++- .../MicrosoftAuth/AuthXSTSRequestModel.cs | 9 ++- .../MicrosoftAuth/AuthXSTSResponseModel.cs | 6 ++ .../MicrosoftAuth/MojangErrorResponseModel.cs | 5 ++ .../MojangOwnershipResponseModel.cs | 5 ++ .../MojangProfileResponseModel.cs | 5 ++ .../Model/Modrinth/ModrinthCategoryInfo.cs | 6 ++ .../Modrinth/ModrinthProjectDependencyInfo.cs | 5 ++ .../Model/Modrinth/ModrinthProjectInfo.cs | 5 ++ .../Model/Modrinth/ModrinthSearchResult.cs | 5 ++ .../Model/Modrinth/ModrinthVersionInfo.cs | 8 +- .../Class/Model/Mojang/VersionManifest.cs | 5 ++ .../ProjBobcat/Class/Model/RawVersionModel.cs | 7 +- .../Class/Model/ServerPing/PingPayload.cs | 7 +- .../YggdrasilAuth/AuthRefreshRequestModel.cs | 5 ++ .../Model/YggdrasilAuth/AuthRequestModel.cs | 5 ++ .../Model/YggdrasilAuth/AuthResponseModel.cs | 5 ++ .../YggdrasilAuth/AuthTokenRequestModel.cs | 5 ++ .../Class/Model/YggdrasilAuth/ErrorModel.cs | 5 ++ .../YggdrasilAuth/SignOutRequestModel.cs | 5 ++ .../Authenticator/MicrosoftAuthenticator.cs | 57 +++++++++------ .../Authenticator/YggdrasilAuthenticator.cs | 20 +++-- .../Installer/CurseForgeInstaller.cs | 2 +- .../Installer/FabricInstaller.cs | 7 +- .../HighVersionForgeInstaller.cs | 7 +- .../ForgeInstaller/LegacyForgeInstaller.cs | 7 +- .../Installer/LiteLoaderInstaller.cs | 7 +- .../Installer/OptifineInstaller.cs | 7 +- .../Installer/QuiltInstaller.cs | 6 +- .../Launch/DefaultLaunchArgumentParser.cs | 4 +- .../Launch/DefaultLauncherAccountParser.cs | 6 +- .../Launch/DefaultLauncherProfileParser.cs | 6 +- .../Launch/DefaultVersionLocator.cs | 14 ++-- .../ResourceInfoResolver/AssetInfoResolver.cs | 6 +- .../VersionInfoResolver.cs | 2 +- .../Service/ServerPingService.cs | 2 +- ProjBobcat/ProjBobcat/ProjBobcat.csproj | 7 +- README.md | 8 +- README_zh_cn.md | 8 +- 69 files changed, 478 insertions(+), 160 deletions(-) delete mode 100644 ProjBobcat/ProjBobcat/Class/Helper/ServiceHelper.cs create mode 100644 ProjBobcat/ProjBobcat/Class/Model/JsonContexts/DictionaryContext.cs create mode 100644 ProjBobcat/ProjBobcat/Class/Model/JsonContexts/JsonElementContext.cs create mode 100644 ProjBobcat/ProjBobcat/Class/Model/JsonContexts/StringContext.cs diff --git a/ProjBobcat/ProjBobcat/Class/Helper/AuthPropertyHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/AuthPropertyHelper.cs index 55b6cd52..f0a379ca 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/AuthPropertyHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/AuthPropertyHelper.cs @@ -1,12 +1,18 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json; +using System.Text.Json.Serialization; using ProjBobcat.Class.Model; using ProjBobcat.Class.Model.LauncherProfile; using ProjBobcat.Class.Model.YggdrasilAuth; namespace ProjBobcat.Class.Helper; +[JsonSerializable(typeof(Dictionary))] +partial class UserPropertiesContext : JsonSerializerContext +{ +} + /// /// AuthProperty工具类 /// @@ -17,7 +23,7 @@ public static class AuthPropertyHelper /// /// Property 集合 /// 解析好的User Property - public static string ResolveUserProperties(this IEnumerable properties) + public static string ResolveUserProperties(this IEnumerable? properties) { if (properties == null) return "{}"; @@ -26,7 +32,7 @@ public static string ResolveUserProperties(this IEnumerable prope item => item.Name, item => new[] { item.Value }); - return JsonSerializer.Serialize(keyValues); + return JsonSerializer.Serialize(keyValues, UserPropertiesContext.Default.DictionaryStringStringArray); } diff --git a/ProjBobcat/ProjBobcat/Class/Helper/CurseForgeAPIHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/CurseForgeAPIHelper.cs index e9be2491..451e0300 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/CurseForgeAPIHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/CurseForgeAPIHelper.cs @@ -3,18 +3,66 @@ using System.Net.Http.Json; using System.Text; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; using ProjBobcat.Class.Model.CurseForge; using ProjBobcat.Class.Model.CurseForge.API; namespace ProjBobcat.Class.Helper; +#region Temp Models + +record AddonInfoReqModel(IEnumerable modIds); + + +[JsonSerializable(typeof(AddonInfoReqModel))] +partial class AddonInfoReqModelContext : JsonSerializerContext +{ +} + +[JsonSerializable(typeof(DataModelWithPagination))] +partial class SearchAddonsResultModelContext : JsonSerializerContext +{ +} + +[JsonSerializable(typeof(DataModel))] +partial class GetAddonResultModelContext : JsonSerializerContext +{ +} + +[JsonSerializable(typeof(DataModel))] +partial class GetAddonsResultModelContext : JsonSerializerContext +{ +} + +[JsonSerializable(typeof(DataModel))] +partial class GetAddonFilesResultModelContext : JsonSerializerContext +{ +} + +[JsonSerializable(typeof(DataModel))] +partial class GetCategoriesResultContext : JsonSerializerContext +{ +} + +[JsonSerializable(typeof(DataModel))] +partial class GetFeaturedAddonsResultContext : JsonSerializerContext +{ +} + +[JsonSerializable(typeof(DataModel))] +partial class DataModelStringResultContext : JsonSerializerContext +{ +} + +#endregion + public static class CurseForgeAPIHelper { const string BaseUrl = "https://api.curseforge.com/v1"; static string ApiKey { get; set; } - static HttpClient Client => HttpClientHelper.GetNewClient(HttpClientHelper.DefaultClientName); + static HttpClient Client => HttpClientHelper.DefaultClient; static HttpRequestMessage Req(HttpMethod method, string url) { @@ -37,7 +85,7 @@ public static void SetApiKey(string apiKey) using var req = Req(HttpMethod.Get, reqUrl); using var res = await Client.SendAsync(req); - return await res.Content.ReadFromJsonAsync>(); + return await res.Content.ReadFromJsonAsync(SearchAddonsResultModelContext.Default.DataModelWithPaginationCurseForgeAddonInfoArray); } public static async Task GetAddon(int addonId) @@ -47,16 +95,13 @@ public static void SetApiKey(string apiKey) using var req = Req(HttpMethod.Get, reqUrl); using var res = await Client.SendAsync(req); - return (await res.Content.ReadFromJsonAsync>())?.Data; + return (await res.Content.ReadFromJsonAsync(GetAddonResultModelContext.Default.DataModelCurseForgeAddonInfo))?.Data; } public static async Task GetAddons(IEnumerable addonIds) { const string reqUrl = $"{BaseUrl}/mods"; - var data = JsonSerializer.Serialize(new - { - modIds = addonIds - }); + var data = JsonSerializer.Serialize(new AddonInfoReqModel(addonIds), AddonInfoReqModelContext.Default.AddonInfoReqModel); using var req = Req(HttpMethod.Post, reqUrl); req.Content = new StringContent(data, Encoding.UTF8, "application/json"); @@ -65,7 +110,7 @@ public static void SetApiKey(string apiKey) res.EnsureSuccessStatusCode(); - return (await res.Content.ReadFromJsonAsync>())?.Data; + return (await res.Content.ReadFromJsonAsync(GetAddonsResultModelContext.Default.DataModelCurseForgeAddonInfoArray))?.Data; } public static async Task GetAddonFiles(int addonId) @@ -75,7 +120,7 @@ public static void SetApiKey(string apiKey) using var req = Req(HttpMethod.Get, reqUrl); using var res = await Client.SendAsync(req); - return (await res.Content.ReadFromJsonAsync>())?.Data; + return (await res.Content.ReadFromJsonAsync(GetAddonFilesResultModelContext.Default.DataModelCurseForgeLatestFileModelArray))?.Data; } public static async Task GetCategories(int gameId = 432) @@ -85,13 +130,13 @@ public static void SetApiKey(string apiKey) using var req = Req(HttpMethod.Get, reqUrl); using var res = await Client.SendAsync(req); - return (await res.Content.ReadFromJsonAsync>())?.Data; + return (await res.Content.ReadFromJsonAsync(GetCategoriesResultContext.Default.DataModelCurseForgeSearchCategoryModelArray))?.Data; } public static async Task GetFeaturedAddons(FeaturedQueryOptions options) { const string reqUrl = $"{BaseUrl}/mods/featured"; - var reqJson = JsonSerializer.Serialize(options); + var reqJson = JsonSerializer.Serialize(options, FeaturedQueryOptionsContext.Default.FeaturedQueryOptions); using var req = Req(HttpMethod.Post, reqUrl); req.Content = new StringContent(reqJson, Encoding.UTF8, "application/json"); @@ -99,7 +144,7 @@ public static void SetApiKey(string apiKey) using var res = await Client.SendAsync(req); res.EnsureSuccessStatusCode(); - return (await res.Content.ReadFromJsonAsync>())?.Data; + return (await res.Content.ReadFromJsonAsync(GetFeaturedAddonsResultContext.Default.DataModelCurseForgeFeaturedAddonModel))?.Data; } public static async Task GetAddonDownloadUrl(long addonId, long fileId) @@ -110,7 +155,7 @@ public static void SetApiKey(string apiKey) using var res = await Client.SendAsync(req); res.EnsureSuccessStatusCode(); - return (await res.Content.ReadFromJsonAsync>())?.Data; + return (await res.Content.ReadFromJsonAsync(DataModelStringResultContext.Default.DataModelString))?.Data; } public static async Task GetAddonDescriptionHtml(long addonId) @@ -121,6 +166,6 @@ public static void SetApiKey(string apiKey) using var res = await Client.SendAsync(req); res.EnsureSuccessStatusCode(); - return (await res.Content.ReadFromJsonAsync>())?.Data; + return (await res.Content.ReadFromJsonAsync(DataModelStringResultContext.Default.DataModelString))?.Data; } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Helper/DownloadHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/DownloadHelper.cs index b041ea28..6cc33008 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/DownloadHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/DownloadHelper.cs @@ -26,7 +26,7 @@ public static class DownloadHelper /// public static int DownloadThread { get; set; } = 8; - static HttpClient DataClient => HttpClientHelper.GetNewClient(HttpClientHelper.DataClientName); + static HttpClient DataClient => HttpClientHelper.DataClient; #region 下载数据 @@ -218,10 +218,9 @@ public static async Task AdvancedDownloadListFile(IEnumerable file #region 分片下载 - static HttpClient HeadClient => HttpClientHelper.GetNewClient(HttpClientHelper.HeadClientName); + static HttpClient HeadClient => HttpClientHelper.HeadClient; - static HttpClient MultiPartClient => - HttpClientHelper.GetNewClient(HttpClientHelper.MultiPartClientName); + static HttpClient MultiPartClient => HttpClientHelper.MultiPartClient; static readonly MemoryPool Pool = MemoryPool.Shared; diff --git a/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs index 3df5154b..9541c10f 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs @@ -78,19 +78,19 @@ public static async IAsyncEnumerable ResolveModListAsync(IE async Task GetNewModInfo(IArchiveEntry entry) { await using var stream = entry.OpenEntryStream(); - var doc = await JsonDocument.ParseAsync(stream); + var doc = await JsonDocument.ParseAsync(stream, cancellationToken: ct); List? model = null; switch (doc.RootElement.ValueKind) { case JsonValueKind.Object: - var val = doc.RootElement.Deserialize(); + var val = doc.RootElement.Deserialize(GameModInfoModelContext.Default.GameModInfoModel); if (val != null) model = new List { val }; break; case JsonValueKind.Array: - model = doc.RootElement.Deserialize>(); + model = doc.RootElement.Deserialize(GameModInfoModelContext.Default.ListGameModInfoModel) ?? new List(); break; } @@ -127,7 +127,7 @@ public static async IAsyncEnumerable ResolveModListAsync(IE async Task GetFabricModInfo(IArchiveEntry entry) { await using var stream = entry.OpenEntryStream(); - var tempModel = await JsonSerializer.DeserializeAsync(stream); + var tempModel = await JsonSerializer.DeserializeAsync(stream, FabricModInfoModelContext.Default.FabricModInfoModel, ct); var author = tempModel?.Authors?.Any() ?? false ? string.Join(',', tempModel.Authors) @@ -204,7 +204,7 @@ public static async IAsyncEnumerable ResolveResour if (packInfoEntry != null) { await using var stream = packInfoEntry.OpenEntryStream(); - var model = await JsonSerializer.DeserializeAsync(stream); + var model = await JsonSerializer.DeserializeAsync(stream, GameResourcePackModelContext.Default.GameResourcePackModel, ct); description = model?.Pack?.Description; version = model?.Pack?.PackFormat ?? -1; @@ -228,7 +228,7 @@ public static async IAsyncEnumerable ResolveResour if (File.Exists(infoPath)) { await using var contentStream = File.OpenRead(infoPath); - var model = await JsonSerializer.DeserializeAsync(contentStream); + var model = await JsonSerializer.DeserializeAsync(contentStream, GameResourcePackModelContext.Default.GameResourcePackModel, ct); description = model?.Pack?.Description; version = model?.Pack?.PackFormat ?? -1; diff --git a/ProjBobcat/ProjBobcat/Class/Helper/HttpClientHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/HttpClientHelper.cs index ced59443..c596c6e7 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/HttpClientHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/HttpClientHelper.cs @@ -1,5 +1,5 @@ -using System.Net.Http; -using Microsoft.Extensions.DependencyInjection; +using System; +using System.Net.Http; using ProjBobcat.Handler; namespace ProjBobcat.Class.Helper; @@ -9,18 +9,39 @@ namespace ProjBobcat.Class.Helper; /// public static class HttpClientHelper { - public const string DefaultClientName = "DefaultClient"; - public const string DataClientName = "DataClient"; - public const string HeadClientName = "HeadClient"; - public const string MultiPartClientName = "MultiPartClient"; + static readonly Lazy DefaultClientFactory = new (HttpClientFactory); + static readonly Lazy DataClientFactory = new(HttpClientFactory); + static readonly Lazy HeadClientFactory = new(HttpClientFactory); + static readonly Lazy MultiPartClientFactory = new(() => + { + var client = HttpClientFactory(); + + client.DefaultRequestHeaders.ConnectionClose = false; + + return client; + }); + + public static HttpClient DefaultClient => DefaultClientFactory.Value; + public static HttpClient DataClient => DataClientFactory.Value; + public static HttpClient HeadClient => HeadClientFactory.Value; + public static HttpClient MultiPartClient => MultiPartClientFactory.Value; + + static HttpClient HttpClientFactory() + { + var handlers = new RedirectHandler(new RetryHandler(new HttpClientHandler { AllowAutoRedirect = false })); + var httpClient = new HttpClient(handlers); + + httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(Ua); + + return httpClient; + } /// /// 获取或设置用户代理信息。 /// public static string Ua { get; set; } = "ProjBobcat"; - - public static IHttpClientFactory HttpClientFactory { get; private set; } - + + /* public static void Init() { var arr = new[] { DefaultClientName, DataClientName, HeadClientName, MultiPartClientName }; @@ -53,4 +74,5 @@ public static HttpClient GetNewClient(string name) { return HttpClientFactory.CreateClient(name); } + */ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Helper/HttpHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/HttpHelper.cs index 27c4eaf3..ebaaf393 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/HttpHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/HttpHelper.cs @@ -21,7 +21,7 @@ public static class HttpHelper static readonly Regex UriRegex = new(UriRegexStr, RegexOptions.Compiled); #pragma warning restore SYSLIB1045 // 转换为“GeneratedRegexAttribute”。 - static HttpClient Client => HttpClientHelper.GetNewClient(HttpClientHelper.DefaultClientName); + static HttpClient Client => HttpClientHelper.DefaultClient; /// /// 正则匹配Uri diff --git a/ProjBobcat/ProjBobcat/Class/Helper/JsonHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/JsonHelper.cs index 285591f7..655ba7c1 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/JsonHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/JsonHelper.cs @@ -4,10 +4,13 @@ namespace ProjBobcat.Class.Helper; public static class JsonHelper { - public static readonly JsonSerializerOptions CamelCasePropertyNamesSettings = new() + public static JsonSerializerOptions CamelCasePropertyNamesSettings() { - WriteIndented = true, - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - MaxDepth = 100 - }; + return new() + { + WriteIndented = true, + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + MaxDepth = 100 + }; + } } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Helper/JwtTokenHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/JwtTokenHelper.cs index c950001d..d1ea515a 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/JwtTokenHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/JwtTokenHelper.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Security.Claims; using System.Text.Json; +using ProjBobcat.Class.Model.JsonContexts; namespace ProjBobcat.Class.Helper; @@ -12,8 +13,9 @@ static IEnumerable ParseClaimsFromJwt(string jwt) { var payload = jwt.Split('.')[1]; var jsonBytes = Convert.FromBase64String(ReformatBase64String(payload)); - var keyValuePairs = JsonSerializer.Deserialize>(jsonBytes); - return keyValuePairs.Select(kvp => new Claim(kvp.Key, kvp.Value.ToString())); + var keyValuePairs = JsonSerializer.Deserialize(jsonBytes, JsonElementContext.Default.JsonElement); + + return keyValuePairs.EnumerateObject().Select(p => new Claim(p.Name, p.Value.ToString())); } static string ReformatBase64String(string str) diff --git a/ProjBobcat/ProjBobcat/Class/Helper/ModrinthAPIHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/ModrinthAPIHelper.cs index d21007f6..d8e10e60 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/ModrinthAPIHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/ModrinthAPIHelper.cs @@ -22,7 +22,7 @@ static async Task Get(string reqUrl) const string reqUrl = $"{BaseUrl}/tag/category"; using var res = await Get(reqUrl); - var resModel = await res.Content.ReadFromJsonAsync(); + var resModel = await res.Content.ReadFromJsonAsync(ModrinthCategoryInfoContext.Default.ModrinthCategoryInfoArray); return resModel; } @@ -32,7 +32,7 @@ static async Task Get(string reqUrl) var reqUrl = $"{BaseUrl}/project/{projectId}/dependencies"; using var res = await Get(reqUrl); - var resModel = await res.Content.ReadFromJsonAsync(); + var resModel = await res.Content.ReadFromJsonAsync(ModrinthProjectDependencyInfoContext.Default.ModrinthProjectDependencyInfo); return resModel; } @@ -42,7 +42,7 @@ static async Task Get(string reqUrl) var reqUrl = $"{BaseUrl}/project/{projectId}"; using var res = await Get(reqUrl); - var resModel = await res.Content.ReadFromJsonAsync(); + var resModel = await res.Content.ReadFromJsonAsync(ModrinthProjectInfoContext.Default.ModrinthProjectInfo); return resModel; } @@ -52,7 +52,7 @@ static async Task Get(string reqUrl) const string reqUrl = $"{BaseUrl}/search"; using var res = await Get(reqUrl); - var resModel = await res.Content.ReadFromJsonAsync(); + var resModel = await res.Content.ReadFromJsonAsync(ModrinthSearchResultContext.Default.ModrinthSearchResult); return resModel; } @@ -62,7 +62,7 @@ static async Task Get(string reqUrl) var reqUrl = $"{BaseUrl}/search{searchOptions}"; using var res = await Get(reqUrl); - var resModel = await res.Content.ReadFromJsonAsync(); + var resModel = await res.Content.ReadFromJsonAsync(ModrinthSearchResultContext.Default.ModrinthSearchResult); return resModel; } @@ -72,7 +72,7 @@ static async Task Get(string reqUrl) var reqUrl = $"{BaseUrl}/project/{projectId}/version"; using var res = await Get(reqUrl); - var resModel = await res.Content.ReadFromJsonAsync(); + var resModel = await res.Content.ReadFromJsonAsync(ModrinthVersionInfoContext.Default.ModrinthVersionInfoArray); return resModel; } diff --git a/ProjBobcat/ProjBobcat/Class/Helper/ServiceHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/ServiceHelper.cs deleted file mode 100644 index 1f81f004..00000000 --- a/ProjBobcat/ProjBobcat/Class/Helper/ServiceHelper.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using ProjBobcat.Handler; - -namespace ProjBobcat.Class.Helper; - -public static class ServiceHelper -{ - public static IServiceCollection ServiceCollection { get; private set; } - public static ServiceProvider ServiceProvider { get; private set; } - - public static void Init() - { - ServiceCollection = new ServiceCollection(); - - ServiceCollection.AddTransient(); - ServiceCollection.AddTransient(); - - ServiceProvider = ServiceCollection.BuildServiceProvider(); - } - - public static void UpdateServiceProvider() - { - ServiceProvider = ServiceCollection.BuildServiceProvider(); - } -} \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/AssetObjectModel.cs b/ProjBobcat/ProjBobcat/Class/Model/AssetObjectModel.cs index c13c7c08..349ecefa 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/AssetObjectModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/AssetObjectModel.cs @@ -31,4 +31,9 @@ public class AssetObjectModel /// [JsonPropertyName("objects")] public Dictionary Objects { get; set; } -} \ No newline at end of file +} + +[JsonSerializable(typeof(AssetObjectModel))] +partial class AssetObjectModelContext : JsonSerializerContext +{ +} diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/API/FeaturedQueryOptions.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/API/FeaturedQueryOptions.cs index 9a17f0d1..4fc09846 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/API/FeaturedQueryOptions.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/API/FeaturedQueryOptions.cs @@ -23,4 +23,9 @@ public class FeaturedQueryOptions PopularCount = 150, UpdatedCount = 150 }; +} + +[JsonSerializable(typeof(FeaturedQueryOptions))] +partial class FeaturedQueryOptionsContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeManifestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeManifestModel.cs index c87a1d0d..0b1a1fa2 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeManifestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/CurseForge/CurseForgeManifestModel.cs @@ -19,4 +19,9 @@ public class CurseForgeManifestModel [JsonPropertyName("files")] public CurseForgeFileModel[] Files { get; set; } [JsonPropertyName("overrides")] public string Overrides { get; set; } +} + +[JsonSerializable(typeof(CurseForgeManifestModel))] +partial class CurseForgeManifestModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricModInfoModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricModInfoModel.cs index 6f778fa6..36293659 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricModInfoModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Fabric/FabricModInfoModel.cs @@ -49,4 +49,9 @@ public class FabricModInfoModel [JsonPropertyName("contacts")] public Dictionary Contacts { get; set; } [JsonPropertyName("jars")] public FabricFileInfo[] Jars { get; set; } +} + +[JsonSerializable(typeof(FabricModInfoModel))] +partial class FabricModInfoModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProfile.cs b/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProfile.cs index bc323309..ec04c00a 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProfile.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Forge/ForgeInstallProfile.cs @@ -50,4 +50,9 @@ public class ForgeInstallProfile [JsonPropertyName("processors")] public ForgeInstallProfileProcessor[] Processors { get; set; } [JsonPropertyName("libraries")] public Library[] Libraries { get; set; } +} + +[JsonSerializable(typeof(ForgeInstallProfile))] +internal partial class ForgeInstallProfileContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Forge/LegacyForgeInstallProfile.cs b/ProjBobcat/ProjBobcat/Class/Model/Forge/LegacyForgeInstallProfile.cs index 2dcde420..b7190b39 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Forge/LegacyForgeInstallProfile.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Forge/LegacyForgeInstallProfile.cs @@ -67,6 +67,8 @@ public class VersionInfo [JsonPropertyName("libraries")] public ForgeLibraries[] Libraries { get; set; } } + + public class Optional { [JsonPropertyName("name")] public string Name { get; set; } @@ -96,4 +98,14 @@ public class LegacyForgeInstallProfile [JsonPropertyName("versionInfo")] public VersionInfo VersionInfo { get; set; } [JsonPropertyName("optionals")] public Optional[] OptionalList { get; set; } +} + +[JsonSerializable(typeof(VersionInfo))] +partial class LegacyForgeInstallVersionInfoContext : JsonSerializerContext +{ +} + +[JsonSerializable(typeof(LegacyForgeInstallProfile))] +partial class LegacyForgeInstallProfileContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameModInfoModel.cs b/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameModInfoModel.cs index 2b8dca8a..35424169 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameModInfoModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameModInfoModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text.Json.Serialization; namespace ProjBobcat.Class.Model.GameResource; @@ -20,11 +21,17 @@ public class GameModInfoModel public string? UpdateUrl { get; set; } - public List? AuthorList { get; set; } + public string[]? AuthorList { get; set; } public string? Parent { get; set; } - public List? Screenshots { get; set; } + public string[]? Screenshots { get; set; } - public List? Dependencies { get; set; } + public string[]? Dependencies { get; set; } +} + +[JsonSerializable(typeof(GameModInfoModel))] +[JsonSerializable(typeof(List))] +partial class GameModInfoModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameResourcePackModel.cs b/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameResourcePackModel.cs index ab2a8a89..6865681f 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameResourcePackModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/GameResource/GameResourcePackModel.cs @@ -12,4 +12,9 @@ public class Pack public class GameResourcePackModel { [JsonPropertyName("pack")] public Pack? Pack { get; set; } +} + +[JsonSerializable(typeof(GameResourcePackModel))] +partial class GameResourcePackModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/GameRulesModel.cs b/ProjBobcat/ProjBobcat/Class/Model/GameRulesModel.cs index de0e6998..984513c2 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/GameRulesModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/GameRulesModel.cs @@ -8,4 +8,10 @@ public class GameRules [JsonPropertyName("action")] public string Action { get; set; } [JsonPropertyName("features")] public Dictionary Features { get; set; } +} + +[JsonSerializable(typeof(GameRules))] +[JsonSerializable(typeof(GameRules[]))] +partial class GameRulesContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/JsonContexts/DictionaryContext.cs b/ProjBobcat/ProjBobcat/Class/Model/JsonContexts/DictionaryContext.cs new file mode 100644 index 00000000..e5e106d6 --- /dev/null +++ b/ProjBobcat/ProjBobcat/Class/Model/JsonContexts/DictionaryContext.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace ProjBobcat.Class.Model.JsonContexts; + +[JsonSerializable(typeof(Dictionary))] +partial class DictionaryContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/JsonContexts/JsonElementContext.cs b/ProjBobcat/ProjBobcat/Class/Model/JsonContexts/JsonElementContext.cs new file mode 100644 index 00000000..c34406ed --- /dev/null +++ b/ProjBobcat/ProjBobcat/Class/Model/JsonContexts/JsonElementContext.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; +using System.Text.Json; + +namespace ProjBobcat.Class.Model.JsonContexts; + +[JsonSerializable(typeof(JsonElement))] +[JsonSerializable(typeof(JsonElement[]))] +partial class JsonElementContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/JsonContexts/StringContext.cs b/ProjBobcat/ProjBobcat/Class/Model/JsonContexts/StringContext.cs new file mode 100644 index 00000000..e8d37e2c --- /dev/null +++ b/ProjBobcat/ProjBobcat/Class/Model/JsonContexts/StringContext.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace ProjBobcat.Class.Model.JsonContexts; + +[JsonSerializable(typeof(string))] +[JsonSerializable(typeof(string[]))] +partial class StringContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/JvmRulesModel.cs b/ProjBobcat/ProjBobcat/Class/Model/JvmRulesModel.cs index 8d76cca7..dcc871a8 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/JvmRulesModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/JvmRulesModel.cs @@ -41,4 +41,10 @@ public class JvmRules /// [JsonPropertyName("os")] public OperatingSystemRules? OperatingSystem { get; set; } +} + +[JsonSerializable(typeof(JvmRules))] +[JsonSerializable(typeof(JvmRules[]))] +partial class JvmRulesContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/LauncherAccountModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/LauncherAccountModel.cs index b1587d00..52d4a19e 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/LauncherAccountModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherAccount/LauncherAccountModel.cs @@ -12,4 +12,9 @@ public class LauncherAccountModel [JsonPropertyName("mojangClientToken")] public string MojangClientToken { get; set; } +} + +[JsonSerializable(typeof(LauncherAccountModel))] +partial class LauncherAccountModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherProfileModel.cs b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherProfileModel.cs index d2fb0c91..53e67ec8 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherProfileModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/LauncherProfile/LauncherProfileModel.cs @@ -12,4 +12,9 @@ public class LauncherProfileModel [JsonPropertyName("selectedUser")] public SelectedUserModel SelectedUser { get; set; } [JsonPropertyName("launcherVersion")] public LauncherVersionModel LauncherVersion { get; set; } -} \ No newline at end of file +} + +[JsonSerializable(typeof(LauncherProfileModel))] +partial class LauncherProfileModelContext : JsonSerializerContext +{ +} diff --git a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/DeviceIdResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/DeviceIdResponseModel.cs index 03f0f058..c43e7790 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/DeviceIdResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/DeviceIdResponseModel.cs @@ -15,4 +15,9 @@ public class DeviceIdResponseModel [JsonPropertyName("interval")] public int Interval { get; set; } [JsonPropertyName("message")] public string Message { get; set; } +} + +[JsonSerializable(typeof(DeviceIdResponseModel))] +partial class DeviceIdResponseModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphAuthResultModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphAuthResultModel.cs index c15fa2be..4c4c6376 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphAuthResultModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphAuthResultModel.cs @@ -15,4 +15,9 @@ public class GraphAuthResultModel [JsonPropertyName("refresh_token")] public string RefreshToken { get; set; } [JsonPropertyName("id_token")] public string IdToken { get; set; } +} + +[JsonSerializable(typeof(GraphAuthResultModel))] +public partial class GraphAuthResultModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphResponseErrorModel.cs b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphResponseErrorModel.cs index 3f01ee89..a05ca03e 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphResponseErrorModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Microsoft/Graph/GraphResponseErrorModel.cs @@ -19,4 +19,9 @@ public class GraphResponseErrorModel [JsonPropertyName("correlation_id")] public Guid CorrelationId { get; set; } [JsonPropertyName("error_uri")] public string ErrorUri { get; set; } +} + +[JsonSerializable(typeof(GraphResponseErrorModel))] +partial class GraphResponseErrorModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthMojangResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthMojangResponseModel.cs index e54d89f1..873dcb84 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthMojangResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthMojangResponseModel.cs @@ -14,4 +14,9 @@ public class AuthMojangResponseModel [JsonPropertyName("token_type")] public string TokenType { get; set; } [JsonPropertyName("expires_in")] public long ExpiresIn { get; set; } +} + +[JsonSerializable(typeof(AuthMojangResponseModel))] +partial class AuthMojangResponseModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXBLRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXBLRequestModel.cs index 7103c66d..d43c4e9b 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXBLRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXBLRequestModel.cs @@ -1,4 +1,6 @@ -namespace ProjBobcat.Class.Model.MicrosoftAuth; +using System.Text.Json.Serialization; + +namespace ProjBobcat.Class.Model.MicrosoftAuth; public class XBLProperties { @@ -27,4 +29,9 @@ public static AuthXBLRequestModel Get(string accessToken) TokenType = "JWT" }; } +} + +[JsonSerializable(typeof(AuthXBLRequestModel))] +partial class AuthXBLRequestModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSErrorModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSErrorModel.cs index 99a7b058..772e600c 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSErrorModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSErrorModel.cs @@ -1,4 +1,6 @@ -namespace ProjBobcat.Class.Model.MicrosoftAuth; +using System.Text.Json.Serialization; + +namespace ProjBobcat.Class.Model.MicrosoftAuth; public class AuthXSTSErrorModel { @@ -6,4 +8,9 @@ public class AuthXSTSErrorModel public uint XErr { get; set; } public string Message { get; set; } public string Redirect { get; set; } +} + +[JsonSerializable(typeof(AuthXSTSErrorModel))] +partial class AuthXSTSErrorModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSRequestModel.cs index 4a1b394a..178ea66a 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSRequestModel.cs @@ -1,4 +1,6 @@ -namespace ProjBobcat.Class.Model.MicrosoftAuth; +using System.Text.Json.Serialization; + +namespace ProjBobcat.Class.Model.MicrosoftAuth; public class XSTSProperties { @@ -28,4 +30,9 @@ public static AuthXSTSRequestModel Get(string token, string relyingParty = "rp:/ TokenType = "JWT" }; } +} + +[JsonSerializable(typeof(AuthXSTSRequestModel))] +partial class AuthXSTSRequestModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSResponseModel.cs index 6331d84b..4263be7f 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/AuthXSTSResponseModel.cs @@ -1,5 +1,6 @@ using System; using System.Text.Json; +using System.Text.Json.Serialization; namespace ProjBobcat.Class.Model.MicrosoftAuth; @@ -9,4 +10,9 @@ public class AuthXSTSResponseModel public DateTime NotAfter { get; set; } public string Token { get; set; } public JsonElement DisplayClaims { get; set; } +} + +[JsonSerializable(typeof(AuthXSTSResponseModel))] +partial class AuthXSTSResponseModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangErrorResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangErrorResponseModel.cs index b2a7dc98..aa729e73 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangErrorResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangErrorResponseModel.cs @@ -13,4 +13,9 @@ public class MojangErrorResponseModel [JsonPropertyName("errorMessage")] public string ErrorMessage { get; set; } [JsonPropertyName("developerMessage")] public string DeveloperMessage { get; set; } +} + +[JsonSerializable(typeof(MojangErrorResponseModel))] +partial class MojangErrorResponseModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangOwnershipResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangOwnershipResponseModel.cs index 84d284b7..510bf7d8 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangOwnershipResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangOwnershipResponseModel.cs @@ -16,4 +16,9 @@ public class MojangOwnershipResponseModel [JsonPropertyName("signature")] public string Signature { get; set; } [JsonPropertyName("keyId")] public string KeyId { get; set; } +} + +[JsonSerializable(typeof(MojangOwnershipResponseModel))] +partial class MojangOwnershipResponseModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangProfileResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangProfileResponseModel.cs index fab0501d..88cf8d1a 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangProfileResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/MicrosoftAuth/MojangProfileResponseModel.cs @@ -32,4 +32,9 @@ public class MojangProfileResponseModel { return Skins?.FirstOrDefault(x => x.State.Equals("ACTIVE", StringComparison.OrdinalIgnoreCase)); } +} + +[JsonSerializable(typeof(MojangProfileResponseModel))] +partial class MojangProfileResponseModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthCategoryInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthCategoryInfo.cs index 7e5e1a2d..ebb359fe 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthCategoryInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthCategoryInfo.cs @@ -9,4 +9,10 @@ public class ModrinthCategoryInfo [JsonPropertyName("name")] public string Name { get; set; } [JsonPropertyName("project_type")] public string ProjectType { get; set; } +} + +[JsonSerializable(typeof(ModrinthCategoryInfo))] +[JsonSerializable(typeof(ModrinthCategoryInfo[]))] +partial class ModrinthCategoryInfoContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectDependencyInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectDependencyInfo.cs index a5fe4269..3299aae6 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectDependencyInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectDependencyInfo.cs @@ -7,4 +7,9 @@ public class ModrinthProjectDependencyInfo [JsonPropertyName("projects")] public ModrinthProjectInfo[] Projects { get; set; } [JsonPropertyName("versions")] public ModrinthVersionInfo[] Versions { get; set; } +} + +[JsonSerializable(typeof(ModrinthProjectDependencyInfo))] +partial class ModrinthProjectDependencyInfoContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfo.cs index d43f42c6..c638302c 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthProjectInfo.cs @@ -45,4 +45,9 @@ public class ModrinthProjectInfo : ModrinthProjectInfoBase [JsonPropertyName("discord_url")] public string DiscordUrl { get; set; } [JsonPropertyName("donation_urls")] public JsonElement[] DonationUrls { get; set; } +} + +[JsonSerializable(typeof(ModrinthProjectInfo))] +partial class ModrinthProjectInfoContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchResult.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchResult.cs index f77b74d3..f7d5c42c 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchResult.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthSearchResult.cs @@ -11,4 +11,9 @@ public class ModrinthSearchResult [JsonPropertyName("limit")] public int Limit { get; set; } [JsonPropertyName("total_hits")] public int TotalHits { get; set; } +} + +[JsonSerializable(typeof(ModrinthSearchResult))] +partial class ModrinthSearchResultContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthVersionInfo.cs b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthVersionInfo.cs index 0e9ab96b..671b0325 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthVersionInfo.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Modrinth/ModrinthVersionInfo.cs @@ -55,4 +55,10 @@ public class ModrinthVersionInfo [JsonPropertyName("dependencies")] public ModrinthDependency[] Dependencies { get; set; } [JsonPropertyName("game_versions")] public string[] GameVersion { get; set; } -} \ No newline at end of file +} + +[JsonSerializable(typeof(ModrinthVersionInfo))] +[JsonSerializable(typeof(ModrinthVersionInfo[]))] +partial class ModrinthVersionInfoContext : JsonSerializerContext +{ +} diff --git a/ProjBobcat/ProjBobcat/Class/Model/Mojang/VersionManifest.cs b/ProjBobcat/ProjBobcat/Class/Model/Mojang/VersionManifest.cs index 93609688..33e9c9dc 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/Mojang/VersionManifest.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/Mojang/VersionManifest.cs @@ -23,4 +23,9 @@ public class VersionManifest [JsonPropertyName("latest")] public Latest Latest { get; set; } [JsonPropertyName("versions")] public VersionManifestVersionsModel[] Versions { get; set; } +} + +[JsonSerializable(typeof(VersionManifest))] +partial class VersionManifestContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/RawVersionModel.cs b/ProjBobcat/ProjBobcat/Class/Model/RawVersionModel.cs index bf74fc48..946eed35 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/RawVersionModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/RawVersionModel.cs @@ -218,4 +218,9 @@ public class RawVersionModel /// [JsonPropertyName("jar")] public string? JarFile { get; set; } -} \ No newline at end of file +} + +[JsonSerializable(typeof(RawVersionModel))] +partial class RawVersionModelContext : JsonSerializerContext +{ +} diff --git a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/PingPayload.cs b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/PingPayload.cs index 6cdff011..400bdab9 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/ServerPing/PingPayload.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/ServerPing/PingPayload.cs @@ -14,4 +14,9 @@ public class PingPayload [JsonPropertyName("modinfo")] public ServerPingModInfo ModInfo { get; set; } [JsonPropertyName("favicon")] public string Icon { get; set; } -} \ No newline at end of file +} + +[JsonSerializable(typeof(PingPayload))] +partial class PingPayloadContext : JsonSerializerContext +{ +} diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRefreshRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRefreshRequestModel.cs index 4b1ba914..76744880 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRefreshRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRefreshRequestModel.cs @@ -11,4 +11,9 @@ public class AuthRefreshRequestModel [JsonPropertyName("requestUser")] public bool RequestUser { get; set; } [JsonPropertyName("selectedProfile")] public ProfileInfoModel SelectedProfile { get; set; } +} + +[JsonSerializable(typeof(AuthRefreshRequestModel))] +partial class AuthRefreshRequestModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRequestModel.cs index 8fbfcba4..b449879d 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthRequestModel.cs @@ -25,4 +25,9 @@ public class AuthRequestModel Name = "Minecraft", Version = 1 }; +} + +[JsonSerializable(typeof(AuthRequestModel))] +partial class AuthRequestModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs index bd24d2a9..139482fc 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs @@ -14,4 +14,9 @@ public class AuthResponseModel [JsonPropertyName("selectedProfile")] public ProfileInfoModel? SelectedProfile { get; set; } [JsonPropertyName("user")] public UserInfoModel User { get; set; } +} + +[JsonSerializable(typeof(AuthResponseModel))] +partial class AuthResponseModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthTokenRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthTokenRequestModel.cs index 784eb4f3..6acfd168 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthTokenRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthTokenRequestModel.cs @@ -7,4 +7,9 @@ public class AuthTokenRequestModel [JsonPropertyName("accessToken")] public string AccessToken { get; set; } [JsonPropertyName("clientToken")] public string ClientToken { get; set; } +} + +[JsonSerializable(typeof(AuthTokenRequestModel))] +partial class AuthTokenRequestModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ErrorModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ErrorModel.cs index ff718991..979ca160 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ErrorModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/ErrorModel.cs @@ -12,4 +12,9 @@ public class ErrorModel [JsonPropertyName("cause")] public string Cause { get; set; } [JsonIgnore] public Exception Exception { get; set; } +} + +[JsonSerializable(typeof(ErrorModel))] +partial class ErrorModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/SignOutRequestModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/SignOutRequestModel.cs index 68f8ef4f..a5272a93 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/SignOutRequestModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/SignOutRequestModel.cs @@ -7,4 +7,9 @@ public class SignOutRequestModel [JsonPropertyName("username")] public string Username { get; set; } [JsonPropertyName("password")] public string Password { get; set; } +} + +[JsonSerializable(typeof(SignOutRequestModel))] +partial class SignOutRequestModelContext : JsonSerializerContext +{ } \ No newline at end of file diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs index 5044d225..5049f58c 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/MicrosoftAuthenticator.cs @@ -4,6 +4,8 @@ using System.Net.Http; using System.Net.Http.Json; using System.Text.Json; +using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; using ProjBobcat.Class.Helper; using ProjBobcat.Class.Model; @@ -18,6 +20,15 @@ namespace ProjBobcat.DefaultComponent.Authenticator; +#region Temp Models + +record McReqModel(string identityToken); + +[JsonSerializable(typeof(McReqModel))] +partial class McReqModelContext : JsonSerializerContext { } + +#endregion + public class MicrosoftAuthenticator : IAuthenticator { public const string MSAuthScope = "XboxLive.signin offline_access"; @@ -46,7 +57,7 @@ public MicrosoftAuthenticator() public static string MSRefreshTokenRequestUrl => $"https://login.microsoftonline.com/{ApiSettings.TenentId}/oauth2/v2.0/token"; - static HttpClient DefaultClient => HttpClientHelper.GetNewClient(HttpClientHelper.DefaultClientName); + static HttpClient DefaultClient => HttpClientHelper.DefaultClient; public string Email { get; set; } public Func> CacheTokenProvider { get; init; } @@ -93,7 +104,9 @@ public async Task AuthTaskAsync(bool userField = false) #region STAGE 1 var xBoxLiveToken = - await SendRequest(MSAuthXBLUrl, AuthXBLRequestModel.Get(accessToken)); + await SendRequest(MSAuthXBLUrl, AuthXBLRequestModel.Get(accessToken), + AuthXSTSResponseModelContext.Default.AuthXSTSResponseModel, + AuthXBLRequestModelContext.Default.AuthXBLRequestModel); if (xBoxLiveToken == null) return new MicrosoftAuthResult @@ -111,12 +124,12 @@ public async Task AuthTaskAsync(bool userField = false) #region STAGE 2 - var xStsReqStr = JsonSerializer.Serialize(AuthXSTSRequestModel.Get(xBoxLiveToken.Token)); + var xStsReqStr = JsonSerializer.Serialize(AuthXSTSRequestModel.Get(xBoxLiveToken.Token), AuthXSTSRequestModelContext.Default.AuthXSTSRequestModel); using var xStsMessage = await HttpHelper.Post(MSAuthXSTSUrl, xStsReqStr); if (!xStsMessage.IsSuccessStatusCode) { - var errModel = await xStsMessage.Content.ReadFromJsonAsync(); + var errModel = await xStsMessage.Content.ReadFromJsonAsync(AuthXSTSErrorModelContext.Default.AuthXSTSErrorModel); var reason = (errModel?.XErr ?? 0) switch { 2148916233 => "未创建 XBox 账户", @@ -140,19 +153,19 @@ public async Task AuthTaskAsync(bool userField = false) }; } - var xStsRes = await xStsMessage.Content.ReadFromJsonAsync(); + var xStsRes = await xStsMessage.Content.ReadFromJsonAsync(AuthXSTSResponseModelContext.Default.AuthXSTSResponseModel); #endregion #region STAGE 2.5 (FETCH XBOX UID) - var xUidReqStr = JsonSerializer.Serialize(AuthXSTSRequestModel.Get(xBoxLiveToken.Token, "http://xboxlive.com")); + var xUidReqStr = JsonSerializer.Serialize(AuthXSTSRequestModel.Get(xBoxLiveToken.Token, "http://xboxlive.com"), AuthXSTSRequestModelContext.Default.AuthXSTSRequestModel); using var xUidMessage = await HttpHelper.Post(MSAuthXSTSUrl, xUidReqStr); var xuid = Guid.Empty.ToString("N"); if (xUidMessage.IsSuccessStatusCode) { - var xUidRes = await xUidMessage.Content.ReadFromJsonAsync(); + var xUidRes = await xUidMessage.Content.ReadFromJsonAsync(AuthXSTSResponseModelContext.Default.AuthXSTSResponseModel); if (xUidRes != null) { @@ -184,11 +197,9 @@ public async Task AuthTaskAsync(bool userField = false) }; var uhsValue = uhs.GetString()!; - var mcReqModel = new - { - identityToken = $"XBL3.0 x={uhsValue};{xStsRes.Token}" - }; - var mcRes = await SendRequest(MojangAuthUrl, mcReqModel); + var mcReqModel = new McReqModel($"XBL3.0 x={uhsValue};{xStsRes.Token}"); + var mcRes = await SendRequest(MojangAuthUrl, mcReqModel, + AuthMojangResponseModelContext.Default.AuthMojangResponseModel, McReqModelContext.Default.McReqModel); #endregion @@ -196,7 +207,7 @@ public async Task AuthTaskAsync(bool userField = false) using var ownResRes = await HttpHelper.Get(MojangOwnershipUrl, new Tuple("Bearer", mcRes.AccessToken)); - var ownRes = await ownResRes.Content.ReadFromJsonAsync(); + var ownRes = await ownResRes.Content.ReadFromJsonAsync(MojangOwnershipResponseModelContext.Default.MojangOwnershipResponseModel); if (!(ownRes?.Items?.Any() ?? false)) return new MicrosoftAuthResult @@ -216,11 +227,11 @@ public async Task AuthTaskAsync(bool userField = false) using var profileResRes = await HttpHelper.Get(MojangProfileUrl, new Tuple("Bearer", mcRes.AccessToken)); - var profileRes = await profileResRes.Content.ReadFromJsonAsync(); + var profileRes = await profileResRes.Content.ReadFromJsonAsync(MojangProfileResponseModelContext.Default.MojangProfileResponseModel); if (profileRes == null) { - var errModel = await profileResRes.Content.ReadFromJsonAsync(); + var errModel = await profileResRes.Content.ReadFromJsonAsync(MojangErrorResponseModelContext.Default.MojangErrorResponseModel); return new MicrosoftAuthResult { @@ -352,7 +363,7 @@ public static void Configure(MicrosoftAuthenticatorAPISettings apiSettings) ApiSettings = apiSettings; } - public static object? ResolveMSGraphResult(string content) + public static object? ResolveMSGraphResult(string content, JsonTypeInfo typeInfo) { var jsonObj = JsonDocument.Parse(content).RootElement; var options = new JsonSerializerOptions @@ -364,9 +375,9 @@ public static void Configure(MicrosoftAuthenticatorAPISettings apiSettings) }; if (jsonObj.TryGetProperty("error", out _) && jsonObj.TryGetProperty("error_description", out _)) - return JsonSerializer.Deserialize(content, options); + return JsonSerializer.Deserialize(content, typeof(GraphResponseErrorModel), new GraphResponseErrorModelContext(options)) as GraphResponseErrorModel; - return JsonSerializer.Deserialize(content); + return JsonSerializer.Deserialize(content, typeInfo); } public async Task GetMSAuthResult(Action deviceTokenNotifier) @@ -386,7 +397,7 @@ public static void Configure(MicrosoftAuthenticatorAPISettings apiSettings) using var deviceTokenRes = await DefaultClient.SendAsync(deviceTokenReq); var deviceTokenContent = await deviceTokenRes.Content.ReadAsStringAsync(); - var deviceTokenModel = ResolveMSGraphResult(deviceTokenContent); + var deviceTokenModel = ResolveMSGraphResult(deviceTokenContent, DeviceIdResponseModelContext.Default.DeviceIdResponseModel); if (deviceTokenModel is not DeviceIdResponseModel deviceTokenResModel) return null; @@ -415,7 +426,7 @@ public static void Configure(MicrosoftAuthenticatorAPISettings apiSettings) using var userAuthResultRes = await DefaultClient.SendAsync(userAuthResultReq); var userAuthResultContent = await userAuthResultRes.Content.ReadAsStringAsync(); - var userAuthResultModel = ResolveMSGraphResult(userAuthResultContent); + var userAuthResultModel = ResolveMSGraphResult(userAuthResultContent, GraphAuthResultModelContext.Default.GraphAuthResultModel); if (userAuthResultModel is not GraphAuthResultModel) if (userAuthResultModel is GraphResponseErrorModel error) @@ -447,15 +458,15 @@ public static string GetLoginUri(string clientId, string redirectUri) + $"&redirect_uri={redirectUri}"); } - static async Task SendRequest(string url, object model) + static async Task SendRequest(string url, TReq model, JsonTypeInfo typeInfo, JsonTypeInfo reqTypeInfo) { - var reqStr = JsonSerializer.Serialize(model); + var reqStr = JsonSerializer.Serialize(model, reqTypeInfo); using var res = await HttpHelper.Post(url, reqStr); if (!res.IsSuccessStatusCode) return default; - var result = await res.Content.ReadFromJsonAsync(); + var result = await res.Content.ReadFromJsonAsync(typeInfo); return result; } diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs index 49f5ab1e..9d838425 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs @@ -7,6 +7,7 @@ using ProjBobcat.Class.Helper; using ProjBobcat.Class.Model; using ProjBobcat.Class.Model.Auth; +using ProjBobcat.Class.Model.JsonContexts; using ProjBobcat.Class.Model.LauncherAccount; using ProjBobcat.Class.Model.LauncherProfile; using ProjBobcat.Class.Model.YggdrasilAuth; @@ -96,7 +97,7 @@ public async Task AuthTaskAsync(bool userField = false) Username = Email, Password = Password }; - var requestJson = JsonSerializer.Serialize(requestModel, JsonHelper.CamelCasePropertyNamesSettings); + var requestJson = JsonSerializer.Serialize(requestModel, typeof(AuthRequestModel), new AuthRequestModelContext(JsonHelper.CamelCasePropertyNamesSettings())); using var resultJson = await HttpHelper.Post(LoginAddress, requestJson); @@ -111,11 +112,11 @@ public async Task AuthTaskAsync(bool userField = false) } }; - var result = await resultJson.Content.ReadFromJsonAsync(); + var result = await resultJson.Content.ReadFromJsonAsync(AuthResponseModelContext.Default.AuthResponseModel); if (result == default || string.IsNullOrEmpty(result.AccessToken)) { - var error = await resultJson.Content.ReadFromJsonAsync(); + var error = await resultJson.Content.ReadFromJsonAsync(ErrorModelContext.Default.ErrorModel); if (error is null) return new YggdrasilAuthResult @@ -307,10 +308,13 @@ public async Task AuthRefreshTaskAsync(AuthResponseModel respons RequestUser = userField, SelectedProfile = response.SelectedProfile }; - var requestJson = JsonSerializer.Serialize(requestModel, JsonHelper.CamelCasePropertyNamesSettings); + var requestJson = JsonSerializer.Serialize(requestModel, typeof(AuthRefreshRequestModel), new AuthRefreshRequestModelContext(JsonHelper.CamelCasePropertyNamesSettings())); using var resultJson = await HttpHelper.Post(RefreshAddress, requestJson); - var result = await resultJson.Content.ReadFromJsonAsync(); + var resultJsonElement = await resultJson.Content.ReadFromJsonAsync(JsonElementContext.Default.JsonElement); + object? result = resultJsonElement.TryGetProperty("cause", out _) + ? resultJsonElement.Deserialize(ErrorModelContext.Default.ErrorModel) + : resultJsonElement.Deserialize(AuthResponseModelContext.Default.AuthResponseModel); switch (result) { @@ -408,7 +412,7 @@ public async Task ValidateTokenTaskAsync(string accessToken) AccessToken = accessToken, ClientToken = LauncherAccountParser.LauncherAccount.MojangClientToken }; - var requestJson = JsonSerializer.Serialize(requestModel, JsonHelper.CamelCasePropertyNamesSettings); + var requestJson = JsonSerializer.Serialize(requestModel, typeof(AuthTokenRequestModel), new AuthTokenRequestModelContext(JsonHelper.CamelCasePropertyNamesSettings())); using var result = await HttpHelper.Post(ValidateAddress, requestJson); return result.StatusCode.Equals(HttpStatusCode.NoContent); @@ -421,7 +425,7 @@ public async Task TokenRevokeTaskAsync(string accessToken) AccessToken = accessToken, ClientToken = LauncherAccountParser.LauncherAccount.MojangClientToken }; - var requestJson = JsonSerializer.Serialize(requestModel, JsonHelper.CamelCasePropertyNamesSettings); + var requestJson = JsonSerializer.Serialize(requestModel, typeof(AuthTokenRequestModel), new AuthTokenRequestModelContext(JsonHelper.CamelCasePropertyNamesSettings())); using var x = await HttpHelper.Post(RevokeAddress, requestJson); } @@ -438,7 +442,7 @@ public async Task SignOutTaskAsync() Username = Email, Password = Password }; - var requestJson = JsonSerializer.Serialize(requestModel, JsonHelper.CamelCasePropertyNamesSettings); + var requestJson = JsonSerializer.Serialize(requestModel, typeof(SignOutRequestModel), new SignOutRequestModelContext(JsonHelper.CamelCasePropertyNamesSettings())); using var result = await HttpHelper.Post(SignOutAddress, requestJson); return result.StatusCode.Equals(HttpStatusCode.NoContent); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/CurseForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/CurseForgeInstaller.cs index d13bdada..f08bdc39 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/CurseForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/CurseForgeInstaller.cs @@ -146,7 +146,7 @@ public async Task InstallTaskAsync() await using var stream = manifestEntry.OpenEntryStream(); - var manifestModel = await JsonSerializer.DeserializeAsync(stream); + var manifestModel = await JsonSerializer.DeserializeAsync(stream, CurseForgeManifestModelContext.Default.CurseForgeManifestModel); return manifestModel; } diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs index 19199b31..18f682cc 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/FabricInstaller.cs @@ -6,6 +6,7 @@ using ProjBobcat.Class.Helper; using ProjBobcat.Class.Model; using ProjBobcat.Class.Model.Fabric; +using ProjBobcat.Class.Model.JsonContexts; using ProjBobcat.Interface; namespace ProjBobcat.DefaultComponent.Installer; @@ -50,8 +51,8 @@ public async Task InstallTaskAsync() var mainClassJObject = LoaderArtifact.LauncherMeta.MainClass; var mainClass = mainClassJObject.ValueKind switch { - JsonValueKind.String => mainClassJObject.Deserialize(), - JsonValueKind.Object => mainClassJObject.Deserialize>() + JsonValueKind.String => mainClassJObject.Deserialize(StringContext.Default.String), + JsonValueKind.Object => mainClassJObject.Deserialize(DictionaryContext.Default.DictionaryStringString) ?.TryGetValue("client", out var outMainClass) ?? false ? outMainClass : string.Empty, @@ -85,7 +86,7 @@ public async Task InstallTaskAsync() }; var jsonPath = GamePathHelper.GetGameJsonPath(RootPath, id); - var jsonContent = JsonSerializer.Serialize(resultModel, JsonHelper.CamelCasePropertyNamesSettings); + var jsonContent = JsonSerializer.Serialize(resultModel, typeof(RawVersionModel), new RawVersionModelContext(JsonHelper.CamelCasePropertyNamesSettings())); InvokeStatusChangedEvent("将版本 Json 写入文件", 90); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs index 15a56cdd..274e31e5 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/HighVersionForgeInstaller.cs @@ -97,7 +97,7 @@ public async Task InstallForgeTaskAsync() }; await using var stream = versionJsonEntry.OpenEntryStream(); - var versionJsonModel = await JsonSerializer.DeserializeAsync(stream); + var versionJsonModel = await JsonSerializer.DeserializeAsync(stream, RawVersionModelContext.Default.RawVersionModel); var forgeVersion = versionJsonModel.Id.Replace("-forge-", "-"); var id = string.IsNullOrEmpty(CustomId) ? versionJsonModel.Id : CustomId; @@ -107,8 +107,7 @@ public async Task InstallForgeTaskAsync() versionJsonModel.InheritsFrom = InheritsFrom; var jsonPath = GamePathHelper.GetGameJsonPath(RootPath, id); - var jsonContent = JsonSerializer.Serialize(versionJsonModel, - JsonHelper.CamelCasePropertyNamesSettings); + var jsonContent = JsonSerializer.Serialize(versionJsonModel, typeof(RawVersionModel), new RawVersionModelContext(JsonHelper.CamelCasePropertyNamesSettings())); await File.WriteAllTextAsync(jsonPath, jsonContent); @@ -123,7 +122,7 @@ public async Task InstallForgeTaskAsync() e.Key.Equals("install_profile.json", StringComparison.OrdinalIgnoreCase)); await using var ipStream = installProfileEntry.OpenEntryStream(); - var ipModel = await JsonSerializer.DeserializeAsync(ipStream); + var ipModel = await JsonSerializer.DeserializeAsync(ipStream, ForgeInstallProfileContext.Default.ForgeInstallProfile); #endregion diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs index e762e83c..60c967dc 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/ForgeInstaller/LegacyForgeInstaller.cs @@ -10,6 +10,7 @@ using ProjBobcat.Class.Model.YggdrasilAuth; using ProjBobcat.Interface; using SharpCompress.Archives; +using VersionInfo = ProjBobcat.Class.Model.Forge.VersionInfo; namespace ProjBobcat.DefaultComponent.Installer.ForgeInstaller; @@ -83,7 +84,7 @@ public async Task InstallForgeTaskAsync() InvokeStatusChangedEvent("解析安装文档", 0.35); - var profileModel = await JsonSerializer.DeserializeAsync(stream); + var profileModel = await JsonSerializer.DeserializeAsync(stream, LegacyForgeInstallProfileContext.Default.LegacyForgeInstallProfile); if (profileModel == null) throw new ArgumentNullException(nameof(profileModel)); @@ -117,8 +118,8 @@ public async Task InstallForgeTaskAsync() await using var fs = File.OpenWrite(forgeLibPath); legacyJarEntry.WriteTo(fs); - var versionJsonString = JsonSerializer.Serialize(profileModel.VersionInfo, - JsonHelper.CamelCasePropertyNamesSettings); + var versionJsonString = JsonSerializer.Serialize(profileModel.VersionInfo, typeof(VersionInfo), + new LegacyForgeInstallVersionInfoContext(JsonHelper.CamelCasePropertyNamesSettings())); await File.WriteAllTextAsync(jsonPath, versionJsonString); InvokeStatusChangedEvent("文件写入完成", 1); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs index b9fbfa4a..c700dbcc 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/LiteLoaderInstaller.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using ProjBobcat.Class.Helper; using ProjBobcat.Class.Model; +using ProjBobcat.Class.Model.JsonContexts; using ProjBobcat.Class.Model.LiteLoader; using ProjBobcat.DefaultComponent.Launch; using ProjBobcat.Exceptions; @@ -95,8 +96,8 @@ public async Task InstallTaskAsync() { Game = new[] { - JsonSerializer.SerializeToElement("--tweakClass"), - JsonSerializer.SerializeToElement(VersionModel.Build.TweakClass) + JsonSerializer.SerializeToElement("--tweakClass", StringContext.Default.String), + JsonSerializer.SerializeToElement(VersionModel.Build.TweakClass, StringContext.Default.String) } }; else @@ -112,7 +113,7 @@ public async Task InstallTaskAsync() DirectoryHelper.CleanDirectory(di.FullName); var jsonPath = GamePathHelper.GetGameJsonPath(RootPath, id); - var jsonContent = JsonSerializer.Serialize(resultModel, JsonHelper.CamelCasePropertyNamesSettings); + var jsonContent = JsonSerializer.Serialize(resultModel, typeof(RawVersionModel), new RawVersionModelContext(JsonHelper.CamelCasePropertyNamesSettings())); await File.WriteAllTextAsync(jsonPath, jsonContent); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs index 453a1bba..1a02e8cb 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/OptifineInstaller.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using ProjBobcat.Class.Helper; using ProjBobcat.Class.Model; +using ProjBobcat.Class.Model.JsonContexts; using ProjBobcat.Class.Model.Optifine; using ProjBobcat.Interface; using SharpCompress.Archives; @@ -77,8 +78,8 @@ public async Task InstallTaskAsync() { Game = new[] { - JsonSerializer.SerializeToElement("--tweakClass"), - JsonSerializer.SerializeToElement("optifine.OptiFineTweaker") + JsonSerializer.SerializeToElement("--tweakClass", StringContext.Default.String), + JsonSerializer.SerializeToElement("optifine.OptiFineTweaker", StringContext.Default.String) }, Jvm = Array.Empty() }, @@ -103,7 +104,7 @@ public async Task InstallTaskAsync() }; var versionJsonPath = GamePathHelper.GetGameJsonPath(RootPath, id); - var jsonStr = JsonSerializer.Serialize(versionModel, JsonHelper.CamelCasePropertyNamesSettings); + var jsonStr = JsonSerializer.Serialize(versionModel, typeof(RawVersionModel), new RawVersionModelContext(JsonHelper.CamelCasePropertyNamesSettings())); await File.WriteAllTextAsync(versionJsonPath, jsonStr); var librariesPath = Path.Combine(RootPath, GamePathHelper.GetLibraryRootPath(), "optifine", diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs index a5d9e70e..114ea380 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Installer/QuiltInstaller.cs @@ -16,7 +16,7 @@ public class QuiltInstaller : InstallerBase, IQuiltInstaller { const string DefaultMetaUrl = "https://meta.quiltmc.org"; - static HttpClient Client => HttpClientHelper.GetNewClient(HttpClientHelper.DefaultClientName); + static HttpClient Client => HttpClientHelper.DefaultClient; public QuiltLoaderModel LoaderArtifact { get; set; } @@ -41,7 +41,7 @@ public async Task InstallTaskAsync() res.EnsureSuccessStatusCode(); - var versionModel = await res.Content.ReadFromJsonAsync(); + var versionModel = await res.Content.ReadFromJsonAsync(RawVersionModelContext.Default.RawVersionModel); InvokeStatusChangedEvent("生成版本总成", 70); @@ -75,7 +75,7 @@ public async Task InstallTaskAsync() DirectoryHelper.CleanDirectory(di.FullName); var jsonPath = GamePathHelper.GetGameJsonPath(RootPath, id); - var jsonContent = JsonSerializer.Serialize(versionModel, JsonHelper.CamelCasePropertyNamesSettings); + var jsonContent = JsonSerializer.Serialize(versionModel, typeof(RawVersionModel), new RawVersionModelContext(JsonHelper.CamelCasePropertyNamesSettings())); InvokeStatusChangedEvent("将版本 Json 写入文件", 90); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs index 1eaa4f24..846c02b3 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLaunchArgumentParser.cs @@ -8,6 +8,7 @@ using ProjBobcat.Class.Helper; using ProjBobcat.Class.Model; using ProjBobcat.Class.Model.Auth; +using ProjBobcat.Class.Model.JsonContexts; using ProjBobcat.Interface; namespace ProjBobcat.DefaultComponent.Launch; @@ -199,7 +200,8 @@ public IEnumerable ParseJvmArguments() "${classpath}" ] """; - var preJvmArguments = VersionLocator.ParseJvmArguments(JsonSerializer.Deserialize(preset)!); + + var preJvmArguments = VersionLocator.ParseJvmArguments(JsonSerializer.Deserialize(preset, JsonElementContext.Default.JsonElementArray)!); foreach (var preJvmArg in preJvmArguments) yield return StringHelper.ReplaceByDic(preJvmArg, jvmArgumentsDic); diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherAccountParser.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherAccountParser.cs index 58e7c253..6ec4c6df 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherAccountParser.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherAccountParser.cs @@ -36,7 +36,7 @@ public DefaultLauncherAccountParser(string rootPath, Guid clientToken) LauncherAccount = launcherAccount; var launcherProfileJson = - JsonSerializer.Serialize(launcherAccount, JsonHelper.CamelCasePropertyNamesSettings); + JsonSerializer.Serialize(launcherAccount, typeof(LauncherAccountModel), new LauncherAccountModelContext(JsonHelper.CamelCasePropertyNamesSettings())); if (!Directory.Exists(RootPath)) Directory.CreateDirectory(RootPath); @@ -47,7 +47,7 @@ public DefaultLauncherAccountParser(string rootPath, Guid clientToken) { var launcherProfileJson = File.ReadAllText(FullLauncherAccountPath, Encoding.UTF8); - LauncherAccount = JsonSerializer.Deserialize(launcherProfileJson); + LauncherAccount = JsonSerializer.Deserialize(launcherProfileJson, LauncherAccountModelContext.Default.LauncherAccountModel); } } @@ -139,7 +139,7 @@ public void Save() File.Delete(FullLauncherAccountPath); var launcherProfileJson = - JsonSerializer.Serialize(LauncherAccount, JsonHelper.CamelCasePropertyNamesSettings); + JsonSerializer.Serialize(LauncherAccount, typeof(LauncherAccountModel), new LauncherAccountModelContext(JsonHelper.CamelCasePropertyNamesSettings())); File.WriteAllText(FullLauncherAccountPath, launcherProfileJson); } diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs index d5d8c604..3112f410 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultLauncherProfileParser.cs @@ -46,7 +46,7 @@ public DefaultLauncherProfileParser(string rootPath, Guid clientToken) LauncherProfile = launcherProfile; var launcherProfileJson = - JsonSerializer.Serialize(launcherProfile, JsonHelper.CamelCasePropertyNamesSettings); + JsonSerializer.Serialize(launcherProfile, typeof(LauncherProfileModel), new LauncherProfileModelContext(JsonHelper.CamelCasePropertyNamesSettings())); if (!Directory.Exists(RootPath)) Directory.CreateDirectory(RootPath); @@ -57,7 +57,7 @@ public DefaultLauncherProfileParser(string rootPath, Guid clientToken) { var launcherProfileJson = File.ReadAllText(_fullLauncherProfilePath, Encoding.UTF8); - LauncherProfile = JsonSerializer.Deserialize(launcherProfileJson); + LauncherProfile = JsonSerializer.Deserialize(launcherProfileJson, LauncherProfileModelContext.Default.LauncherProfileModel); } } @@ -104,7 +104,7 @@ public void SaveProfile() File.Delete(_fullLauncherProfilePath); var launcherProfileJson = - JsonSerializer.Serialize(LauncherProfile, JsonHelper.CamelCasePropertyNamesSettings); + JsonSerializer.Serialize(LauncherProfile, typeof(LauncherProfileModel), new LauncherProfileModelContext(JsonHelper.CamelCasePropertyNamesSettings())); File.WriteAllText(_fullLauncherProfilePath, launcherProfileJson); } diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs index 4db6b78e..3285f631 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Launch/DefaultVersionLocator.cs @@ -3,10 +3,12 @@ using System.IO; using System.Linq; using System.Text.Json; +using System.Text.Json.Serialization; using ProjBobcat.Class; using ProjBobcat.Class.Helper; using ProjBobcat.Class.Helper.SystemInfo; using ProjBobcat.Class.Model; +using ProjBobcat.Class.Model.JsonContexts; using ProjBobcat.Class.Model.LauncherProfile; using ProjBobcat.Class.Model.Version; using FileInfo = ProjBobcat.Class.Model.FileInfo; @@ -72,14 +74,14 @@ public override IEnumerable ParseJvmArguments(IEnumerable? } if (jvmRule.TryGetProperty("rules", out var rules)) - if (!(rules.Deserialize()?.CheckAllow() ?? false)) + if (!(rules.Deserialize(JvmRulesContext.Default.JvmRulesArray)?.CheckAllow() ?? false)) continue; if (!jvmRule.TryGetProperty("value", out var value)) continue; switch (value.ValueKind) { case JsonValueKind.Array: - var values = value.Deserialize(); + var values = value.Deserialize(StringContext.Default.StringArray); if (!(values?.Any() ?? false)) continue; @@ -136,7 +138,7 @@ private protected override (IEnumerable, Dictionary) Par var ruleKey = string.Empty; var ruleValue = string.Empty; - var rulesArr = rules.Deserialize(); + var rulesArr = rules.Deserialize(GameRulesContext.Default.GameRulesArray); if (!(rulesArr?.Any() ?? false)) continue; @@ -153,7 +155,7 @@ private protected override (IEnumerable, Dictionary) Par ruleValue = value.ValueKind switch { JsonValueKind.String => value.GetString(), - JsonValueKind.Array => string.Join(' ', value.Deserialize() ?? Array.Empty()) + JsonValueKind.Array => string.Join(' ', value.Deserialize(StringContext.Default.StringArray) ?? Array.Empty()) }; } @@ -280,7 +282,7 @@ public override (List, List) GetNatives(IEnumerable
  • public override RawVersionModel? ParseRawVersion(string id) { - // 预防I/O的错误。 + // 预防 I/O 的错误。 // Prevents errors related to I/O. if (!Directory.Exists(Path.Combine(RootPath, GamePathHelper.GetGamePath(id)))) return null; @@ -288,7 +290,7 @@ public override (List, List) GetNatives(IEnumerable
  • (fs); + var versionJson = JsonSerializer.Deserialize(fs, RawVersionModelContext.Default.RawVersionModel); if (versionJson == null) return null; diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/AssetInfoResolver.cs b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/AssetInfoResolver.cs index ffc60f5f..d56af920 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/AssetInfoResolver.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/AssetInfoResolver.cs @@ -43,7 +43,7 @@ public override async IAsyncEnumerable ResolveResourceAsync() OnResolve("没有提供 Version Manifest, 开始下载"); using var vmJsonRes = await HttpHelper.Get(DefaultVersionManifestUrl); - var vm = await vmJsonRes.Content.ReadFromJsonAsync(); + var vm = await vmJsonRes.Content.ReadFromJsonAsync(VersionManifestContext.Default.VersionManifest); versions = vm?.Versions?.ToList(); } @@ -79,7 +79,7 @@ public override async IAsyncEnumerable ResolveResourceAsync() if (versionObject == default) yield break; using var jsonRes = await HttpHelper.Get(versionObject.Url); - var versionModel = await jsonRes.Content.ReadFromJsonAsync(); + var versionModel = await jsonRes.Content.ReadFromJsonAsync(RawVersionModelContext.Default.RawVersionModel); if (versionModel == default) yield break; @@ -121,7 +121,7 @@ public override async IAsyncEnumerable ResolveResourceAsync() try { await using var assetFs = File.OpenRead(assetIndexesPath); - assetObject = await JsonSerializer.DeserializeAsync(assetFs); + assetObject = await JsonSerializer.DeserializeAsync(assetFs, AssetObjectModelContext.Default.AssetObjectModel); } catch (Exception ex) { diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/VersionInfoResolver.cs b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/VersionInfoResolver.cs index 0eaeefe6..ada2b0ff 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/VersionInfoResolver.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/ResourceInfoResolver/VersionInfoResolver.cs @@ -22,7 +22,7 @@ public override async IAsyncEnumerable ResolveResourceAsync() if (!File.Exists(versionJson)) yield break; await using var fs = File.OpenRead(versionJson); - var rawVersionModel = await JsonSerializer.DeserializeAsync(fs); + var rawVersionModel = await JsonSerializer.DeserializeAsync(fs, RawVersionModelContext.Default.RawVersionModel); if (rawVersionModel?.Downloads?.Client == null) yield break; diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Service/ServerPingService.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Service/ServerPingService.cs index c82bff67..f585fbbe 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Service/ServerPingService.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Service/ServerPingService.cs @@ -124,7 +124,7 @@ public ServerPingResult Run() InvokeStatusChangedEvent($"收到包 0x{packet:X2} , 长度为 {length}", 80); var json = ReadString(buffer, jsonLength); - var ping = JsonSerializer.Deserialize(json); + var ping = JsonSerializer.Deserialize(json, PingPayloadContext.Default.PingPayload); if (ping == null) return null; diff --git a/ProjBobcat/ProjBobcat/ProjBobcat.csproj b/ProjBobcat/ProjBobcat/ProjBobcat.csproj index 5407c914..89dee0f3 100644 --- a/ProjBobcat/ProjBobcat/ProjBobcat.csproj +++ b/ProjBobcat/ProjBobcat/ProjBobcat.csproj @@ -15,6 +15,11 @@ true + + true + false + + WINDOWS @@ -90,8 +95,6 @@ performance optimization - - all diff --git a/README.md b/README.md index db922c09..41e4ba9e 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,9 @@ The next-generation Minecraft launcher core written in C# providing the freest, Developed and maintained by Corona Studio. -## Stats -![Alt](https://repobeats.axiom.co/api/embed/d8d56d4c2023d90ea067d5b3ca83ed5da4979289.svg "Repobeats analytics image") +## NativeAOT (ahead-of-time compilation) Support + +ProjBobcat provide fully support for [NativeAot](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/). Native AOT apps start up very quickly and use less memory. Users of the application can run it on a machine that doesn't have the .NET runtime installed. If you want to use NativeAot in your project, please switch your target framework to **net7.0 or higher**. ## Multi-Platform Support @@ -247,6 +248,9 @@ var result = await Core.LaunchTaskAsync(launchSettings).ConfigureAwait(true); // ``` +## Stats +![Alt](https://repobeats.axiom.co/api/embed/d8d56d4c2023d90ea067d5b3ca83ed5da4979289.svg "Repobeats analytics image") + ## License MIT. This means that you can modify or use our code for any purpose, however copyright notice and permission notice shall be included in all copies or substantial portions of your software. diff --git a/README_zh_cn.md b/README_zh_cn.md index 8b06e84a..e3be8af4 100644 --- a/README_zh_cn.md +++ b/README_zh_cn.md @@ -20,9 +20,9 @@ 由日冕工作室开发和维护。 -## Stats +## Native AOT (提前编译为本地代码) 支持 -![Alt](https://repobeats.axiom.co/api/embed/d8d56d4c2023d90ea067d5b3ca83ed5da4979289.svg "Repobeats analytics image") +ProjBobcat 为 [NativeAot](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/) 提供全面支持。Native AOT 应用程序启动非常快,并且使用较少的内存。应用程序的用户可以在没有安装 .NET 运行时的机器上运行它。如果你想在你的项目中使用Native AOT,请将你的目标框架切换到 **net7.0 或更高版本**。 ## 跨平台支持 @@ -258,6 +258,10 @@ var result = await Core.LaunchTaskAsync(launchSettings).ConfigureAwait(true); // ``` +## 统计 + +![Alt](https://repobeats.axiom.co/api/embed/d8d56d4c2023d90ea067d5b3ca83ed5da4979289.svg "Repobeats analytics image") + ## 免责声明 ProjBobcat 不隶属于Mojang以及其附属软件的任何一部分。