This commit is contained in:
DismissedLight
2023-11-26 15:55:37 +08:00
parent 7099ca43b6
commit 9960b6f6b1
3 changed files with 30 additions and 3 deletions

View File

@@ -10,7 +10,7 @@ namespace Snap.Hutao.Extension;
/// <see cref="StringBuilder"/> 扩展方法
/// </summary>
[HighQuality]
internal static class StringBuilderExtensions
internal static class StringBuilderExtension
{
/// <summary>
/// 当条件符合时执行 <see cref="StringBuilder.Append(string?)"/>
@@ -37,4 +37,21 @@ internal static class StringBuilderExtensions
{
return condition ? sb.Append(value) : sb;
}
public static string ToStringTrimEndReturn(this StringBuilder builder)
{
Must.Argument(builder.Length >= 1, "StringBuilder 的长度必须大于 0");
int remove = 0;
if (builder[^1] is '\n')
{
remove = 1;
if (builder.Length >= 2 && builder[^2] is '\r')
{
remove = 2;
}
}
return builder.ToString(0, builder.Length - remove);
}
}

View File

@@ -7,4 +7,6 @@ internal sealed class LatestPackage : Package
{
[JsonPropertyName("segments")]
public List<PackageSegment> Segments { get; set; } = default!;
public new string DisplayName { get => Name; }
}

View File

@@ -8,6 +8,7 @@ using Snap.Hutao.Web.Request.Builder.Abstraction;
using Snap.Hutao.Web.Response;
using System.IO;
using System.Net.Http;
using System.Text;
namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher;
@@ -46,8 +47,15 @@ internal sealed partial class ResourceClient
// 补全缺失的信息
if (resp is { Data.Game.Latest: LatestPackage latest })
{
latest.Path = latest.Segments[0].Path[..^4]; // .00X
latest.Name = Path.GetFileName(latest.Path);
StringBuilder pathBuilder = new();
foreach (PackageSegment segment in latest.Segments)
{
pathBuilder.AppendLine(segment.Path);
}
latest.Path = pathBuilder.ToStringTrimEndReturn();
string path = latest.Segments[0].Path[..^4]; // .00X
latest.Name = Path.GetFileName(path);
}
return Response.Response.DefaultIfNull(resp);