mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix #1126
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -7,4 +7,6 @@ internal sealed class LatestPackage : Package
|
||||
{
|
||||
[JsonPropertyName("segments")]
|
||||
public List<PackageSegment> Segments { get; set; } = default!;
|
||||
|
||||
public new string DisplayName { get => Name; }
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user