fix game resouce latest package no path

This commit is contained in:
DismissedLight
2023-08-21 23:16:23 +08:00
parent 23feb78f05
commit f4f3242546
5 changed files with 30 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ internal sealed class Game
/// 最新客户端
/// </summary>
[JsonPropertyName("latest")]
public Package Latest { get; set; } = default!;
public LatestPackage Latest { get; set; } = default!;
/// <summary>
/// 相对于当前版本的之前版本的差异文件(非预下载)

View File

@@ -0,0 +1,10 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher;
internal sealed class LatestPackage : Package
{
[JsonPropertyName("segments")]
public List<PackageSegment> Segments { get; set; } = default!;
}

View File

@@ -45,8 +45,6 @@ internal class Package : PathMd5
[JsonPropertyName("decompressed_path")]
public string DecompressedPath { get; set; } = default!;
// We don't want to support `segments` downloading
/// <summary>
/// 包大小 bytes
/// </summary>

View File

@@ -0,0 +1,11 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher;
internal sealed class PackageSegment : PathMd5
{
[JsonPropertyName("package_size")]
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
public long PackageSize { get; set; } = default!;
}

View File

@@ -4,6 +4,7 @@
using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient;
using Snap.Hutao.Service.Game;
using Snap.Hutao.Web.Response;
using System.IO;
using System.Net.Http;
namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher;
@@ -36,6 +37,13 @@ internal sealed partial class ResourceClient
.TryCatchGetFromJsonAsync<Response<GameResource>>(url, options, logger, token)
.ConfigureAwait(false);
// 补全缺失的信息
if (response is { Data.Game.Latest: LatestPackage latest })
{
latest.Path = latest.Segments[0].Path[..^4];
latest.Name = Path.GetFileName(latest.Path);
}
return Response.Response.DefaultIfNull(response);
}
}