Skip to content

Commit

Permalink
resourcepack resolve fix
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Jul 3, 2023
1 parent 2482803 commit 8cb77b0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
41 changes: 29 additions & 12 deletions ProjBobcat/ProjBobcat/Class/Helper/GameResourcesResolveHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ public static class GameResourcesResolveHelper

async Task<GameModResolvedInfo?> GetNewModInfo(IArchiveEntry entry)
{
List<GameModInfoModel>? model = null;

await using var stream = entry.OpenEntryStream();
var doc = await JsonDocument.ParseAsync(stream, cancellationToken: ct);

List<GameModInfoModel>? model = null;

switch (doc.RootElement.ValueKind)
{
case JsonValueKind.Object:
Expand Down Expand Up @@ -205,12 +206,20 @@ async Task<GameModResolvedInfo> GetFabricModInfo(IArchiveEntry entry)

if (packInfoEntry != null)
{
await using var stream = packInfoEntry.OpenEntryStream();
var model = await JsonSerializer.DeserializeAsync(stream,
GameResourcePackModelContext.Default.GameResourcePackModel, ct);
try
{
await using var stream = packInfoEntry.OpenEntryStream();
var model = await JsonSerializer.DeserializeAsync(stream,
GameResourcePackModelContext.Default.GameResourcePackModel, ct);

description = model?.Pack?.Description;
version = model?.Pack?.PackFormat ?? -1;
description = model?.Pack?.Description;
version = model?.Pack?.PackFormat ?? -1;
}
catch (JsonException e)
{
description = $"[!] 数据包 JSON 异常: {e.Message}";
version = -1;
}
}

return new GameResourcePackResolvedInfo(fileName, description, version, imageBytes);
Expand All @@ -230,12 +239,20 @@ async Task<GameModResolvedInfo> GetFabricModInfo(IArchiveEntry entry)

if (File.Exists(infoPath))
{
await using var contentStream = File.OpenRead(infoPath);
var model = await JsonSerializer.DeserializeAsync(contentStream,
GameResourcePackModelContext.Default.GameResourcePackModel, ct);
try
{
await using var contentStream = File.OpenRead(infoPath);
var model = await JsonSerializer.DeserializeAsync(contentStream,
GameResourcePackModelContext.Default.GameResourcePackModel, ct);

description = model?.Pack?.Description;
version = model?.Pack?.PackFormat ?? -1;
description = model?.Pack?.Description;
version = model?.Pack?.PackFormat ?? -1;
}
catch (JsonException e)
{
description = $"[!] 数据包 JSON 异常: {e.Message}";
version = -1;
}
}

return new GameResourcePackResolvedInfo(fileName, description, version, imageBytes);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace ProjBobcat.Class.Model.GameResource;

Expand Down

0 comments on commit 8cb77b0

Please sign in to comment.