diff --git a/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs b/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs index 24c545f1..c5cf216b 100644 --- a/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs +++ b/ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs @@ -63,7 +63,7 @@ public static async IAsyncEnumerable ResolveModListAsync(IE var infoTable = arr.Children.First(); var title = infoTable.HasKey("modId") - ? infoTable["modId"]?.AsString + ? (infoTable["modId"]?.AsString ?? "-") : Path.GetFileName(file); var author = infoTable.HasKey("authors") ? infoTable["authors"]?.AsString @@ -128,18 +128,30 @@ public static async IAsyncEnumerable ResolveModListAsync(IE async Task GetFabricModInfo(IArchiveEntry entry) { - await using var stream = entry.OpenEntryStream(); - var tempModel = await JsonSerializer.DeserializeAsync(stream, - FabricModInfoModelContext.Default.FabricModInfoModel, ct); - - var author = tempModel?.Authors?.Any() ?? false - ? string.Join(',', tempModel.Authors) - : null; - var modList = tempModel?.Depends?.Select(d => d.Key)?.ToImmutableList(); - var titleResult = string.IsNullOrEmpty(tempModel?.Id) ? Path.GetFileName(file) : tempModel.Id; - var versionResult = string.IsNullOrEmpty(tempModel?.Version) ? null : tempModel.Version; - - return new GameModResolvedInfo(author, file, modList, titleResult, versionResult, "Fabric", isEnabled); + try + { + await using var stream = entry.OpenEntryStream(); + var tempModel = await JsonSerializer.DeserializeAsync(stream, + FabricModInfoModelContext.Default.FabricModInfoModel, ct); + + var author = tempModel?.Authors?.Any() ?? false + ? string.Join(',', tempModel.Authors) + : null; + var modList = tempModel?.Depends?.Select(d => d.Key)?.ToImmutableList(); + var titleResult = string.IsNullOrEmpty(tempModel?.Id) ? Path.GetFileName(file) : tempModel.Id; + var versionResult = string.IsNullOrEmpty(tempModel?.Version) ? null : tempModel.Version; + + return new GameModResolvedInfo(author, file, modList, titleResult, versionResult, "Fabric", isEnabled); + } + catch (JsonException e) + { + var errorList = new[] + { + "[!] 数据包 JSON 异常", + e.Message + }; + return new GameModResolvedInfo(null, file, errorList.ToImmutableList(), Path.GetFileName(file), null, "Fabric", isEnabled); + } } GameModResolvedInfo? result = null; diff --git a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs index 139482fc..a9195b8f 100644 --- a/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs +++ b/ProjBobcat/ProjBobcat/Class/Model/YggdrasilAuth/AuthResponseModel.cs @@ -13,7 +13,7 @@ public class AuthResponseModel [JsonPropertyName("selectedProfile")] public ProfileInfoModel? SelectedProfile { get; set; } - [JsonPropertyName("user")] public UserInfoModel User { get; set; } + [JsonPropertyName("user")] public UserInfoModel? User { get; set; } } [JsonSerializable(typeof(AuthResponseModel))] diff --git a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs index cdf3a6f3..208d69a7 100644 --- a/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs +++ b/ProjBobcat/ProjBobcat/DefaultComponent/Authenticator/YggdrasilAuthenticator.cs @@ -182,7 +182,7 @@ public async Task AuthTaskAsync(bool userField = false) Legacy = false, LocalId = rUuid, Persistent = true, - RemoteId = result.User.UUID.ToString(), + RemoteId = result.User?.UUID.ToString() ?? new Guid().ToString(), Type = "Mojang", UserProperites = result.User?.Properties?.ToAuthProperties(profiles).ToArray() ?? Array.Empty(), @@ -361,7 +361,7 @@ public async Task AuthRefreshTaskAsync(AuthResponseModel respons Legacy = false, LocalId = rUuid, Persistent = true, - RemoteId = authResponse.User.UUID.ToString(), + RemoteId = authResponse.User?.UUID.ToString() ?? new Guid().ToString(), Type = "Mojang", UserProperites = authResponse.User?.Properties?.ToAuthProperties(profiles).ToArray() ?? Array.Empty(),