From d5551e5cdfa828fdc81407b466e403a710de443e Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Thu, 1 Feb 2024 14:30:50 +0800 Subject: [PATCH] fix #1316 --- .../Snap.Hutao/Control/Media/Rgba32.cs | 3 +- .../Control/Text/DescriptionTextBlock.cs | 48 +++++++++++++++---- .../Web/Hutao/HutaoReleaseDescription.cs | 16 +++++++ .../Web/Hutao/HutaoVersionInformation.cs | 6 +++ 4 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hutao/HutaoReleaseDescription.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Media/Rgba32.cs b/src/Snap.Hutao/Snap.Hutao/Control/Media/Rgba32.cs index 836571c3..a0726a13 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Media/Rgba32.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/Media/Rgba32.cs @@ -49,7 +49,8 @@ internal struct Rgba32 /// RGBA 代码 public unsafe Rgba32(uint code) { - // RRGGBBAA -> AABBGGRR + // uint layout: 0xRRGGBBAA -> AABBGGRR + // AABBGGRR -> RRGGBBAA fixed (Rgba32* pSelf = &this) { *(uint*)pSelf = BinaryPrimitives.ReverseEndianness(code); diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Text/DescriptionTextBlock.cs b/src/Snap.Hutao/Snap.Hutao/Control/Text/DescriptionTextBlock.cs index b6f13817..a60ea1de 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Text/DescriptionTextBlock.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/Text/DescriptionTextBlock.cs @@ -8,6 +8,7 @@ using Microsoft.UI.Xaml.Media; using Snap.Hutao.Control.Extension; using Snap.Hutao.Control.Media; using Snap.Hutao.Control.Theme; +using System.Diagnostics; using Windows.Foundation; using Windows.UI; @@ -23,8 +24,11 @@ namespace Snap.Hutao.Control.Text; [DependencyProperty("TextStyle", typeof(Style), default(Style), nameof(OnTextStyleChanged))] internal sealed partial class DescriptionTextBlock : ContentControl { - private static readonly int ColorTagFullLength = "".Length; - private static readonly int ColorTagLeftLength = "".Length; + private static readonly int RgbaColorTagFullLength = "".Length; + private static readonly int RgbaColorTagLeftLength = "".Length; + + private static readonly int RgbColorTagFullLength = "".Length; + private static readonly int RgbColorTagLeftLength = "".Length; private static readonly int ItalicTagFullLength = "".Length; private static readonly int ItalicTagLeftLength = "".Length; @@ -53,7 +57,14 @@ internal sealed partial class DescriptionTextBlock : ContentControl TextBlock textBlock = (TextBlock)((DescriptionTextBlock)d).Content; ReadOnlySpan description = MetadataSpecialNames.Handle((string)e.NewValue); - UpdateDescription(textBlock, description); + try + { + UpdateDescription(textBlock, description); + } + catch (Exception ex) + { + _ = ex; + } } private static void OnTextStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -81,13 +92,32 @@ internal sealed partial class DescriptionTextBlock : ContentControl // color tag else if (description[i..].StartsWith("')) + { + case 16: // RgbaColorTag + { + AppendText(textBlock, description[last..i]); + Rgba32 color = new(description.Slice(i + 8, 8).ToString()); + int length = description[(i + RgbaColorTagLeftLength)..].IndexOf('<'); + AppendColorText(textBlock, description.Slice(i + RgbaColorTagLeftLength, length), color); - i += length + ColorTagFullLength; - last = i; + i += length + RgbaColorTagFullLength; + last = i; + break; + } + + case 14: // RgbColorTag + { + AppendText(textBlock, description[last..i]); + Rgba32 color = new(description.Slice(i + 8, 6).ToString()); + int length = description[(i + RgbColorTagLeftLength)..].IndexOf('<'); + AppendColorText(textBlock, description.Slice(i + RgbColorTagLeftLength, length), color); + + i += length + RgbColorTagFullLength; + last = i; + break; + } + } } // italic diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hutao/HutaoReleaseDescription.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hutao/HutaoReleaseDescription.cs new file mode 100644 index 00000000..6254806b --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hutao/HutaoReleaseDescription.cs @@ -0,0 +1,16 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hutao; + +internal sealed class HutaoReleaseDescription +{ + [JsonPropertyName("cn")] + public string CN { get; set; } = default!; + + [JsonPropertyName("en")] + public string EN { get; set; } = default!; + + [JsonPropertyName("full")] + public string Full { get; set; } = default!; +} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hutao/HutaoVersionInformation.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hutao/HutaoVersionInformation.cs index d05a3416..bf645b68 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hutao/HutaoVersionInformation.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hutao/HutaoVersionInformation.cs @@ -13,4 +13,10 @@ internal sealed class HutaoVersionInformation [JsonPropertyName("sha256")] public string? Sha256 { get; set; } = default!; + + [JsonPropertyName("archive_urls")] + public List ArchiveUrls { get; set; } = default!; + + [JsonPropertyName("release_description")] + public HutaoReleaseDescription ReleaseDescription { get; set; } = default!; } \ No newline at end of file