fix predownload latest path and name

This commit is contained in:
Lightczx
2024-03-11 11:47:43 +08:00
parent 16e8a17614
commit 1a300e8b9c
2 changed files with 28 additions and 9 deletions

View File

@@ -0,0 +1,21 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Text;
namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource;
internal static class LatestPackageExtension
{
public static void Patch(this LatestPackage latest)
{
StringBuilder pathBuilder = new();
foreach (PackageSegment segment in latest.Segments)
{
pathBuilder.AppendLine(segment.Path);
}
latest.Path = pathBuilder.ToStringTrimEndReturn();
latest.Name = latest.Segments[0].Path[..^4]; // .00X
}
}

View File

@@ -46,18 +46,16 @@ internal sealed partial class ResourceClient
.TryCatchSendAsync<Response<GameResource>>(httpClient, logger, token)
.ConfigureAwait(false);
// 补全缺失的信息
// 最新版完整包
if (resp is { Data.Game.Latest: LatestPackage latest })
{
StringBuilder pathBuilder = new();
foreach (PackageSegment segment in latest.Segments)
{
pathBuilder.AppendLine(segment.Path);
}
latest.Patch();
}
latest.Path = pathBuilder.ToStringTrimEndReturn();
string path = latest.Segments[0].Path[..^4]; // .00X
latest.Name = Path.GetFileName(path);
// 预下载完整包
if (resp is { Data.PreDownloadGame.Latest: LatestPackage preDownloadLatest })
{
preDownloadLatest.Patch();
}
return Response.Response.DefaultIfNull(resp);