This commit is contained in:
DismissedLight
2023-11-25 10:10:16 +08:00
parent 43415ebd0d
commit f2ef6ff8ec
15 changed files with 85 additions and 32 deletions

View File

@@ -1,7 +1,6 @@
using System;
using System.Buffers.Binary;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
namespace Snap.Hutao.Test.IncomingFeature;

View File

@@ -10,6 +10,7 @@
<ResourceDictionary Source="ms-appx:///Control/Image/CachedImage.xaml"/>
<ResourceDictionary Source="ms-appx:///Control/Theme/Card.xaml"/>
<ResourceDictionary Source="ms-appx:///Control/Theme/Color.xaml"/>
<ResourceDictionary Source="ms-appx:///Control/Theme/ComboBox.xaml"/>
<ResourceDictionary Source="ms-appx:///Control/Theme/Converter.xaml"/>
<ResourceDictionary Source="ms-appx:///Control/Theme/CornerRadius.xaml"/>
<ResourceDictionary Source="ms-appx:///Control/Theme/FlyoutStyle.xaml"/>

View File

@@ -128,15 +128,8 @@ internal sealed partial class UniformStaggeredLayout : VirtualizingLayout
UniformStaggeredItem item = state.GetItemAt(i);
if (item.Height == 0)
{
// https://github.com/DGP-Studio/Snap.Hutao/issues/1079
// The first element must be force refreshed otherwise
// it will use the old one realized
// https://github.com/DGP-Studio/Snap.Hutao/issues/1099
// Now we need to refresh the first element of each column
ElementRealizationOptions options = i < numberOfColumns ? ElementRealizationOptions.ForceCreate : ElementRealizationOptions.None;
// Item has not been measured yet. Get the element and store the values
UIElement element = context.GetOrCreateElementAt(i, options);
UIElement element = context.GetOrCreateElementAt(i);
element.Measure(new Size(state.ColumnWidth, availableHeight));
item.Height = element.DesiredSize.Height;
item.Element = element;

View File

@@ -74,6 +74,21 @@ internal sealed class UniformStaggeredLayoutState
/// </summary>
internal void Clear()
{
// https://github.com/DGP-Studio/Snap.Hutao/issues/1079
// The first element must be force refreshed otherwise
// it will use the old one realized
// https://github.com/DGP-Studio/Snap.Hutao/issues/1099
// Now we need to refresh the first element of each column
// https://github.com/DGP-Studio/Snap.Hutao/issues/1099
// Finally we need to refresh the whole layout when we reset
if (context.ItemCount > 0)
{
for (int i = 0; i < context.ItemCount; i++)
{
RecycleElementAt(i);
}
}
columnLayout.Clear();
items.Clear();
}

View File

@@ -3,6 +3,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Core;
using Windows.Foundation;
namespace Snap.Hutao.Control;
@@ -20,12 +21,15 @@ internal sealed partial class SizeRestrictedContentControl : ContentControl
{
element.Measure(availableSize);
Size contentDesiredSize = element.DesiredSize;
Size contentActualOrDesiredSize = new(
Math.Max(element.ActualWidth, contentDesiredSize.Width),
Math.Max(element.ActualHeight, contentDesiredSize.Height));
if (IsWidthRestricted)
{
if (contentDesiredSize.Width > minContentWidth)
if (contentActualOrDesiredSize.Width > minContentWidth)
{
minContentWidth = contentDesiredSize.Width;
minContentWidth = contentActualOrDesiredSize.Width;
}
element.MinWidth = minContentWidth;
@@ -33,9 +37,9 @@ internal sealed partial class SizeRestrictedContentControl : ContentControl
if (IsHeightRestricted)
{
if (contentDesiredSize.Height > minContentHeight)
if (contentActualOrDesiredSize.Height > minContentHeight)
{
minContentHeight = contentDesiredSize.Height;
minContentHeight = contentActualOrDesiredSize.Height;
}
element.MinHeight = minContentHeight;

View File

@@ -0,0 +1,11 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style
x:Key="CommandBarComboBoxStyle"
BasedOn="{StaticResource DefaultComboBoxStyle}"
TargetType="ComboBox">
<Setter Property="Padding" Value="12,7,0,7"/>
<Setter Property="Height" Value="36"/>
</Style>
<!-- https://github.com/microsoft/microsoft-ui-xaml/issues/4811 -->
<x:Int32 x:Key="__DiscardPageOverride">0</x:Int32>
</ResourceDictionary>

View File

@@ -63,8 +63,10 @@ internal static partial class IocHttpClientConfiguration
client.DefaultRequestHeaders.Add("x-rpc-app_version", SaltConstants.CNVersion);
client.DefaultRequestHeaders.Add("x-rpc-client_type", "2");
client.DefaultRequestHeaders.Add("x-rpc-device_id", HoyolabOptions.DeviceId);
client.DefaultRequestHeaders.Add("x-rpc-device_name", string.Empty);
client.DefaultRequestHeaders.Add("x-rpc-game_biz", "bbs_cn");
client.DefaultRequestHeaders.Add("x-rpc-sdk_version", "2.16.0");
//client.DefaultRequestHeaders.Add("x-rpc-tool_verison", "v4.2.2-ys");
}
/// <summary>

View File

@@ -78,7 +78,13 @@ internal static class DiscordController
lock (SyncRoot)
{
StopTokenSource.Cancel();
discordManager?.Dispose();
try
{
discordManager?.Dispose();
}
catch (SEHException)
{
}
}
}
@@ -135,13 +141,18 @@ internal static class DiscordController
}
catch (ResultException ex)
{
System.Diagnostics.Debug.WriteLine($"[Discord.GameSDK]:[ERROR]:{ex.Result}");
// If result is Ok
// Maybe the connection is reset.
if (ex.Result is not Result.Ok)
{
System.Diagnostics.Debug.WriteLine($"[Discord.GameSDK ERROR]:{ex.Result:D} {ex.Result}");
}
}
catch (SEHException ex)
{
// Known error codes:
// 0x80004005 E_FAIL
System.Diagnostics.Debug.WriteLine($"[Discord.GameSDK]:[ERROR]:0x{ex.ErrorCode:X}");
System.Diagnostics.Debug.WriteLine($"[Discord.GameSDK ERROR]:0x{ex.ErrorCode:X}");
}
}
}

View File

@@ -83,6 +83,7 @@
<None Remove="Control\Panel\PanelSelector.xaml" />
<None Remove="Control\Theme\Card.xaml" />
<None Remove="Control\Theme\Color.xaml" />
<None Remove="Control\Theme\ComboBox.xaml" />
<None Remove="Control\Theme\Converter.xaml" />
<None Remove="Control\Theme\CornerRadius.xaml" />
<None Remove="Control\Theme\FlyoutStyle.xaml" />
@@ -317,6 +318,11 @@
<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
<ItemGroup>
<Page Update="Control\Theme\ComboBox.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="Control\Theme\ScrollViewer.xaml">

View File

@@ -247,13 +247,12 @@
</CommandBar.Content>
<AppBarElementContainer>
<shc:SizeRestrictedContentControl>
<shc:SizeRestrictedContentControl Margin="2,6,3,6">
<ComboBox
Height="36"
Margin="2,6,3,6"
DisplayMemberPath="Name"
ItemsSource="{Binding Archives, Mode=OneWay}"
SelectedItem="{Binding SelectedArchive, Mode=TwoWay}"/>
SelectedItem="{Binding SelectedArchive, Mode=TwoWay}"
Style="{ThemeResource CommandBarComboBoxStyle}"/>
</shc:SizeRestrictedContentControl>
</AppBarElementContainer>
<AppBarButton

View File

@@ -248,13 +248,12 @@
<Pivot.RightHeader>
<CommandBar DefaultLabelPosition="Right">
<AppBarElementContainer>
<shc:SizeRestrictedContentControl>
<shc:SizeRestrictedContentControl Margin="6,6,6,6">
<ComboBox
Height="36"
Margin="6,6,6,6"
DisplayMemberPath="Name"
ItemsSource="{Binding Projects}"
SelectedItem="{Binding SelectedProject, Mode=TwoWay}"/>
SelectedItem="{Binding SelectedProject, Mode=TwoWay}"
Style="{ThemeResource CommandBarComboBoxStyle}"/>
</shc:SizeRestrictedContentControl>
</AppBarElementContainer>

View File

@@ -231,13 +231,12 @@
IsHitTestVisible="False"/>
<Pivot>
<Pivot.LeftHeader>
<shc:SizeRestrictedContentControl>
<shc:SizeRestrictedContentControl Margin="16,6,0,6">
<ComboBox
Height="36"
Margin="16,6,0,6"
DisplayMemberPath="Uid"
ItemsSource="{Binding Archives}"
SelectedItem="{Binding SelectedArchive, Mode=TwoWay}"/>
SelectedItem="{Binding SelectedArchive, Mode=TwoWay}"
Style="{ThemeResource CommandBarComboBoxStyle}"/>
</shc:SizeRestrictedContentControl>
</Pivot.LeftHeader>
<Pivot.RightHeader>

View File

@@ -218,9 +218,8 @@
<ToggleSwitch Width="120" IsOn="{Binding Options.IsBorderless, Mode=TwoWay}"/>
</cwc:SettingsCard>
<cwc:SettingsCard Description="{shcm:ResourceString Name=ViewPageLaunchGameAppearanceAspectRatioDescription}" Header="{shcm:ResourceString Name=ViewPageLaunchGameAppearanceAspectRatioHeader}">
<shc:SizeRestrictedContentControl>
<shc:SizeRestrictedContentControl Margin="0,0,136,0">
<ComboBox
Margin="0,0,136,0"
ItemsSource="{Binding Options.AspectRatios}"
PlaceholderText="{shcm:ResourceString Name=ViewPageLaunchGameAppearanceAspectRatioPlaceHolder}"
SelectedItem="{Binding Options.SelectedAspectRatio, Mode=TwoWay}"/>
@@ -252,7 +251,6 @@
<StackPanel Orientation="Horizontal" Spacing="16">
<shc:SizeRestrictedContentControl>
<ComboBox
VerticalAlignment="Center"
DisplayMemberPath="Name"
IsEnabled="{Binding Options.IsMonitorEnabled}"
ItemsSource="{Binding Options.Monitors}"

View File

@@ -34,7 +34,7 @@ internal sealed partial class CardClient
public async ValueTask<Response<VerificationRegistration>> CreateVerificationAsync(User user, CancellationToken token)
{
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.CardCreateVerification(false))
.SetRequestUri(ApiEndpoints.CardCreateVerification(true))
.SetUserCookieAndFpHeader(user, CookieType.LToken)
.Get();

View File

@@ -40,6 +40,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.GameRecordDailyNote(userAndUid.Uid))
.SetUserCookieAndFpHeader(userAndUid, CookieType.Cookie)
.SetReferer(ApiEndpoints.WebStaticMihoyoReferer)
.Get();
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
@@ -60,6 +61,7 @@ internal sealed partial class GameRecordClient : IGameRecordClient
HttpRequestMessageBuilder verifiedbuilder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.GameRecordDailyNote(userAndUid.Uid))
.SetUserCookieAndFpHeader(userAndUid, CookieType.Cookie)
.SetReferer(ApiEndpoints.WebStaticMihoyoReferer)
.SetXrpcChallenge(challenge)
.Get();
@@ -86,6 +88,8 @@ internal sealed partial class GameRecordClient : IGameRecordClient
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.GameRecordIndex(userAndUid.Uid))
.SetUserCookieAndFpHeader(userAndUid, CookieType.Cookie)
.SetHeader("x-rpc-page", "v4.2.2-ys_#/ys/daily")
.SetReferer(ApiEndpoints.WebStaticMihoyoReferer)
.Get();
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
@@ -106,6 +110,8 @@ internal sealed partial class GameRecordClient : IGameRecordClient
HttpRequestMessageBuilder verifiedbuilder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.GameRecordIndex(userAndUid.Uid))
.SetUserCookieAndFpHeader(userAndUid, CookieType.Cookie)
.SetHeader("x-rpc-page", "v4.2.2-ys_#/ys/daily")
.SetReferer(ApiEndpoints.WebStaticMihoyoReferer)
.SetXrpcChallenge(challenge)
.Get();
@@ -133,6 +139,8 @@ internal sealed partial class GameRecordClient : IGameRecordClient
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.GameRecordSpiralAbyss(schedule, userAndUid.Uid))
.SetUserCookieAndFpHeader(userAndUid, CookieType.Cookie)
.SetHeader("x-rpc-page", "v4.2.2-ys_#/ys/daily")
.SetReferer(ApiEndpoints.WebStaticMihoyoReferer)
.Get();
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
@@ -153,6 +161,8 @@ internal sealed partial class GameRecordClient : IGameRecordClient
HttpRequestMessageBuilder verifiedbuilder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.GameRecordSpiralAbyss(schedule, userAndUid.Uid))
.SetUserCookieAndFpHeader(userAndUid, CookieType.Cookie)
.SetHeader("x-rpc-page", "v4.2.2-ys_#/ys/daily")
.SetReferer(ApiEndpoints.WebStaticMihoyoReferer)
.SetXrpcChallenge(challenge)
.Get();
@@ -179,6 +189,8 @@ internal sealed partial class GameRecordClient : IGameRecordClient
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.GameRecordRoleBasicInfo(userAndUid.Uid))
.SetUserCookieAndFpHeader(userAndUid, CookieType.Cookie)
.SetHeader("x-rpc-page", "v4.2.2-ys_#/ys/daily")
.SetReferer(ApiEndpoints.WebStaticMihoyoReferer)
.Get();
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
@@ -203,6 +215,8 @@ internal sealed partial class GameRecordClient : IGameRecordClient
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.GameRecordCharacter)
.SetUserCookieAndFpHeader(userAndUid, CookieType.Cookie)
.SetHeader("x-rpc-page", "v4.2.2-ys_#/ys/daily")
.SetReferer(ApiEndpoints.WebStaticMihoyoReferer)
.PostJson(new CharacterData(userAndUid.Uid, playerInfo.Avatars.Select(x => x.Id)));
await builder.SignDataAsync(DataSignAlgorithmVersion.Gen2, SaltType.X4, false).ConfigureAwait(false);
@@ -223,6 +237,8 @@ internal sealed partial class GameRecordClient : IGameRecordClient
HttpRequestMessageBuilder verifiedBuilder = httpRequestMessageBuilderFactory.Create()
.SetRequestUri(ApiEndpoints.GameRecordCharacter)
.SetUserCookieAndFpHeader(userAndUid, CookieType.Cookie)
.SetHeader("x-rpc-page", "v4.2.2-ys_#/ys/daily")
.SetReferer(ApiEndpoints.WebStaticMihoyoReferer)
.SetXrpcChallenge(challenge)
.PostJson(new CharacterData(userAndUid.Uid, playerInfo.Avatars.Select(x => x.Id)));