mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Compare commits
4 Commits
test/dialo
...
feat/1663
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd0ea971dd | ||
|
|
eeab336f99 | ||
|
|
54e1b095c4 | ||
|
|
5208a2cf55 |
66
.github/workflows/alpha.yml
vendored
66
.github/workflows/alpha.yml
vendored
@@ -29,7 +29,15 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: self-hosted
|
||||
runs-on: ${{ matrix.runner }}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
runner:
|
||||
- self-hosted
|
||||
- windows-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
@@ -45,55 +53,13 @@ jobs:
|
||||
run: dotnet tool restore && dotnet cake
|
||||
env:
|
||||
VERSION_API_TOKEN: ${{ secrets.VERSION_API_TOKEN }}
|
||||
CERTIFICATE: ${{ secrets.CERTIFICATE }}
|
||||
PW: ${{ secrets.PW }}
|
||||
|
||||
- name: Upload signed msix
|
||||
if: success() && github.event_name != 'pull_request'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Snap.Hutao.Alpha-${{ steps.cake.outputs.version }}
|
||||
path: ${{ github.workspace }}/src/output/Snap.Hutao.Alpha-${{ steps.cake.outputs.version }}.msix
|
||||
|
||||
- name: Add summary
|
||||
if: success() && github.event_name != 'pull_request'
|
||||
shell: pwsh
|
||||
run: |
|
||||
$summary = "
|
||||
> [!WARNING]
|
||||
> 该版本是由 CI 程序自动打包生成的 `Alpha` 测试版本,**仅供开发者测试使用**
|
||||
|
||||
> [!TIP]
|
||||
> 普通用户请[点击这里](https://github.com/DGP-Studio/Snap.Hutao/releases/latest/)下载最新的稳定版本
|
||||
|
||||
> [!IMPORTANT]
|
||||
> 请注意,从 Snap Hutao Alpha 2023.12.21.3 开始,我们将使用全新的 CI 证书,原有的 Snap.Hutao.CI.cer 将在几天后过期停止使用。
|
||||
>
|
||||
> 请安装 [DGP_Studio_CA.crt](https://github.com/DGP-Automation/Hutao-Auto-Release/releases/download/certificate-ca/DGP_Studio_CA.crt) 到 `受信任的根证书颁发机构` 以安装测试版安装包
|
||||
"
|
||||
|
||||
echo $summary >> $Env:GITHUB_STEP_SUMMARY
|
||||
fallback_build:
|
||||
runs-on: windows-latest
|
||||
needs: build
|
||||
if: failure()
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 8.0
|
||||
|
||||
- name: Cake
|
||||
id: cake
|
||||
shell: pwsh
|
||||
run: dotnet tool restore && dotnet cake
|
||||
env:
|
||||
VERSION_API_TOKEN: ${{ secrets.VERSION_API_TOKEN }}
|
||||
CERTIFICATE: ${{ secrets.CERTIFICATE }}
|
||||
PW: ${{ secrets.PW }}
|
||||
|
||||
- name: Sign Msix
|
||||
if: success() && github.event_name != 'pull_request'
|
||||
shell: pwsh
|
||||
run: |
|
||||
[System.Convert]::FromBase64String("${{ secrets.CERTIFICATE }}") | Set-Content -AsByteStream temp.pfx
|
||||
signtool.exe sign /debug /v /a /fd SHA256 /f temp.pfx /p ${{ secrets.PW }} ${{ github.workspace }}\src\output\Snap.Hutao.Alpha-${{ steps.cake.outputs.version }}.msix
|
||||
|
||||
- name: Upload signed msix
|
||||
if: success() && github.event_name != 'pull_request'
|
||||
|
||||
65
build.cake
65
build.cake
@@ -11,9 +11,6 @@ var version = "version";
|
||||
var repoDir = "repoDir";
|
||||
var outputPath = "outputPath";
|
||||
|
||||
var pfxPath = "pfxPath";
|
||||
var pw = "pw";
|
||||
|
||||
// Extension
|
||||
|
||||
static ProcessArgumentBuilder AppendIf(this ProcessArgumentBuilder builder, string text, bool condition)
|
||||
@@ -65,11 +62,6 @@ if (GitHubActions.IsRunningOnGitHubActions)
|
||||
}
|
||||
);
|
||||
|
||||
var certificateBase64 = HasEnvironmentVariable("CERTIFICATE") ? EnvironmentVariable("CERTIFICATE") : throw new Exception("Cannot find CERTIFICATE");
|
||||
pw = HasEnvironmentVariable("PW") ? EnvironmentVariable("PW") : throw new Exception("Cannot find PW");
|
||||
pfxPath = System.IO.Path.Combine(repoDir, "temp.pfx");
|
||||
System.IO.File.WriteAllBytes(pfxPath, System.Convert.FromBase64String(certificateBase64));
|
||||
|
||||
Information($"Version: {version}");
|
||||
}
|
||||
|
||||
@@ -96,19 +88,10 @@ else // Local
|
||||
Information($"Version: {version}");
|
||||
}
|
||||
|
||||
// Windows SDK
|
||||
var registry = new WindowsRegistry();
|
||||
var winsdkRegistry = registry.LocalMachine.OpenKey(@"SOFTWARE\Microsoft\Windows Kits\Installed Roots");
|
||||
var winsdkVersion = winsdkRegistry.GetSubKeyNames().MaxBy(key => int.Parse(key.Split(".")[2]));
|
||||
var winsdkPath = (string)winsdkRegistry.GetValue("KitsRoot10");
|
||||
var winsdkBinPath = System.IO.Path.Combine(winsdkPath, "bin", winsdkVersion, "x64");
|
||||
Information($"Windows SDK: {winsdkPath}");
|
||||
|
||||
Task("Build")
|
||||
.IsDependentOn("Build binary package")
|
||||
.IsDependentOn("Copy files")
|
||||
.IsDependentOn("Build MSIX")
|
||||
.IsDependentOn("Sign");
|
||||
.IsDependentOn("Build MSIX");
|
||||
|
||||
Task("NuGet Restore")
|
||||
.Does(() =>
|
||||
@@ -224,11 +207,8 @@ Task("Build MSIX")
|
||||
{
|
||||
arguments = "pack /d " + binPath + " /p " + System.IO.Path.Combine(outputPath, $"Snap.Hutao.Local-{version}.msix");
|
||||
}
|
||||
|
||||
var makeappxPath = System.IO.Path.Combine(winsdkBinPath, "makeappx.exe");
|
||||
|
||||
var p = StartProcess(
|
||||
makeappxPath,
|
||||
"makeappx.exe",
|
||||
new ProcessSettings
|
||||
{
|
||||
Arguments = arguments
|
||||
@@ -236,46 +216,7 @@ Task("Build MSIX")
|
||||
);
|
||||
if (p != 0)
|
||||
{
|
||||
throw new InvalidOperationException("Build MSIX failed with exit code " + p);
|
||||
}
|
||||
});
|
||||
|
||||
Task("Sign")
|
||||
.IsDependentOn("Build MSIX")
|
||||
.Does(() =>
|
||||
{
|
||||
if (AppVeyor.IsRunningOnAppVeyor)
|
||||
{
|
||||
Information("Move to SignPath. Skip signing.");
|
||||
return;
|
||||
}
|
||||
else if (GitHubActions.IsRunningOnGitHubActions)
|
||||
{
|
||||
if (GitHubActions.Environment.PullRequest.IsPullRequest)
|
||||
{
|
||||
Information("Is Pull Request. Skip signing.");
|
||||
return;
|
||||
}
|
||||
|
||||
var signPath = System.IO.Path.Combine(winsdkBinPath, "signtool.exe");
|
||||
var arguments = $"sign /debug /v /a /fd SHA256 /f {pfxPath} /p {pw} {System.IO.Path.Combine(outputPath, $"Snap.Hutao.Alpha-{version}.msix")}";
|
||||
|
||||
var p = StartProcess(
|
||||
signPath,
|
||||
new ProcessSettings
|
||||
{
|
||||
Arguments = arguments
|
||||
}
|
||||
);
|
||||
if (p != 0)
|
||||
{
|
||||
throw new InvalidOperationException("Sign failed with exit code " + p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Information("Local configuration. Skip signing.");
|
||||
return;
|
||||
throw new InvalidOperationException("Build failed with exit code " + p);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -6,25 +6,14 @@ namespace Snap.Hutao.Test.IncomingFeature;
|
||||
public class SpiralAbyssScheduleIdTest
|
||||
{
|
||||
private static readonly TimeSpan Utc8 = new(8, 0, 0);
|
||||
private static readonly DateTimeOffset AcrobaticsBattleIntroducedTime = new(2024, 7, 1, 4, 0, 0, Utc8);
|
||||
|
||||
[TestMethod]
|
||||
public void Test()
|
||||
{
|
||||
Console.WriteLine($"当前第 {GetForDateTimeOffset(DateTimeOffset.Now)} 期");
|
||||
|
||||
// 2020-07-01 04:00:00 为第 1 期
|
||||
// 2024-06-16 04:00:00 为第 96 期
|
||||
// 2024-07-01 04:00:00 为第 97 期
|
||||
// 2024-07-16 04:00:00 为第 98 期
|
||||
// 2024-08-01 04:00:00 为第 99 期
|
||||
Console.WriteLine($"2020-07-01 04:00:00 为第 {GetForDateTimeOffset(new(2020, 07, 01, 4, 0, 0, Utc8))} 期");
|
||||
Console.WriteLine($"2024-06-16 04:00:00 为第 {GetForDateTimeOffset(new(2024, 06, 16, 4, 0, 0, Utc8))} 期");
|
||||
Console.WriteLine($"2024-07-01 04:00:00 为第 {GetForDateTimeOffset(new(2024, 07, 01, 4, 0, 0, Utc8))} 期");
|
||||
Console.WriteLine($"2024-07-16 04:00:00 为第 {GetForDateTimeOffset(new(2024, 07, 16, 4, 0, 0, Utc8))} 期");
|
||||
Console.WriteLine($"2024-08-01 04:00:00 为第 {GetForDateTimeOffset(new(2024, 08, 01, 4, 0, 0, Utc8))} 期");
|
||||
Console.WriteLine($"2024-08-16 04:00:00 为第 {GetForDateTimeOffset(new(2024, 08, 16, 4, 0, 0, Utc8))} 期");
|
||||
Console.WriteLine($"2024-09-01 04:00:00 为第 {GetForDateTimeOffset(new(2024, 09, 01, 4, 0, 0, Utc8))} 期");
|
||||
DateTimeOffset dateTimeOffset = new(2020, 7, 1, 4, 0, 0, Utc8);
|
||||
Console.WriteLine($"2020-07-01 04:00:00 为第 {GetForDateTimeOffset(dateTimeOffset)} 期");
|
||||
}
|
||||
|
||||
public static int GetForDateTimeOffset(DateTimeOffset dateTimeOffset)
|
||||
@@ -49,12 +38,6 @@ public class SpiralAbyssScheduleIdTest
|
||||
periodNum--;
|
||||
}
|
||||
|
||||
if (dateTimeOffset >= AcrobaticsBattleIntroducedTime)
|
||||
{
|
||||
// 当超过 96 期时,每一个月一期
|
||||
periodNum = (4 * 12 * 2) + ((periodNum - (4 * 12 * 2)) / 2);
|
||||
}
|
||||
|
||||
return periodNum;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
using System.Drawing;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Snap.Hutao.Test.RuntimeBehavior;
|
||||
|
||||
[TestClass]
|
||||
public sealed class HttpClientBehaviorTest
|
||||
{
|
||||
private const int MessageNotYetSent = 0;
|
||||
|
||||
[TestMethod]
|
||||
public async Task RetrySendHttpRequestMessage()
|
||||
{
|
||||
using (HttpClient httpClient = new())
|
||||
{
|
||||
HttpRequestMessage requestMessage = new(HttpMethod.Post, "https://jsonplaceholder.typicode.com/posts");
|
||||
JsonContent content = JsonContent.Create(new Point(12, 34));
|
||||
requestMessage.Content = content;
|
||||
using (requestMessage)
|
||||
{
|
||||
await httpClient.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Interlocked.Exchange(ref GetPrivateSendStatus(requestMessage), MessageNotYetSent);
|
||||
Volatile.Write(ref GetPrivateDisposed(content), false);
|
||||
await httpClient.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
// private int _sendStatus
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_sendStatus")]
|
||||
private static extern ref int GetPrivateSendStatus(HttpRequestMessage message);
|
||||
|
||||
// private bool _disposed
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_disposed")]
|
||||
private static extern ref bool GetPrivateDisposed(HttpRequestMessage message);
|
||||
|
||||
// private bool _disposed
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_disposed")]
|
||||
private static extern ref bool GetPrivateDisposed(HttpContent content);
|
||||
}
|
||||
@@ -14,8 +14,8 @@
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.4.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.4.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.Behaviors;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Snap.Hutao.Control.Behavior;
|
||||
|
||||
[DependencyProperty("MilliSecondsDelay", typeof(int))]
|
||||
internal sealed partial class InfoBarDelayCloseBehavior : BehaviorBase<InfoBar>
|
||||
{
|
||||
protected override void OnAssociatedObjectLoaded()
|
||||
{
|
||||
DelayCoreAsync().SafeForget();
|
||||
}
|
||||
|
||||
private async ValueTask DelayCoreAsync()
|
||||
{
|
||||
if (MilliSecondsDelay > 0)
|
||||
{
|
||||
await Delay.FromMilliSeconds(MilliSecondsDelay).ConfigureAwait(true);
|
||||
if (AssociatedObject is not null)
|
||||
{
|
||||
AssociatedObject.IsOpen = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,10 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Snap.Hutao.Control.Extension;
|
||||
using Snap.Hutao.Core.Caching;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Core.IO.DataTransfer;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace Snap.Hutao.Control.Image;
|
||||
|
||||
@@ -17,12 +12,8 @@ namespace Snap.Hutao.Control.Image;
|
||||
/// 缓存图像
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[DependencyProperty("SourceName", typeof(string), "Unknown")]
|
||||
[DependencyProperty("CachedName", typeof(string), "Unknown")]
|
||||
internal sealed partial class CachedImage : Implementation.ImageEx
|
||||
internal sealed class CachedImage : Implementation.ImageEx
|
||||
{
|
||||
private string? file;
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的缓存图像
|
||||
/// </summary>
|
||||
@@ -35,15 +26,12 @@ internal sealed partial class CachedImage : Implementation.ImageEx
|
||||
/// <inheritdoc/>
|
||||
protected override async Task<Uri?> ProvideCachedResourceAsync(Uri imageUri, CancellationToken token)
|
||||
{
|
||||
SourceName = Path.GetFileName(imageUri.ToString());
|
||||
IImageCache imageCache = this.ServiceProvider().GetRequiredService<IImageCache>();
|
||||
|
||||
try
|
||||
{
|
||||
HutaoException.ThrowIf(string.IsNullOrEmpty(imageUri.Host), SH.ControlImageCachedImageInvalidResourceUri);
|
||||
string file = await imageCache.GetFileFromCacheAsync(imageUri).ConfigureAwait(true); // BitmapImage need to be created by main thread.
|
||||
CachedName = Path.GetFileName(file);
|
||||
this.file = file;
|
||||
token.ThrowIfCancellationRequested(); // check token state to determine whether the operation should be canceled.
|
||||
return file.ToUri();
|
||||
}
|
||||
@@ -54,27 +42,4 @@ internal sealed partial class CachedImage : Implementation.ImageEx
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
[Command("CopyToClipboardCommand")]
|
||||
private async Task CopyToClipboard()
|
||||
{
|
||||
if (Image is Microsoft.UI.Xaml.Controls.Image { Source: BitmapImage bitmap })
|
||||
{
|
||||
using (FileStream netStream = File.OpenRead(bitmap.UriSource.LocalPath))
|
||||
{
|
||||
using (IRandomAccessStream fxStream = netStream.AsRandomAccessStream())
|
||||
{
|
||||
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fxStream);
|
||||
SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
|
||||
using (InMemoryRandomAccessStream memory = new())
|
||||
{
|
||||
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, memory);
|
||||
encoder.SetSoftwareBitmap(softwareBitmap);
|
||||
await encoder.FlushAsync();
|
||||
Ioc.Default.GetRequiredService<IClipboardProvider>().SetBitmap(memory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<ResourceDictionary
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:shci="using:Snap.Hutao.Control.Image">
|
||||
@@ -14,13 +14,6 @@
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<Grid.ContextFlyout>
|
||||
<MenuFlyout>
|
||||
<MenuFlyoutItem IsEnabled="False" Text="{TemplateBinding SourceName}"/>
|
||||
<MenuFlyoutItem IsEnabled="False" Text="{TemplateBinding CachedName}"/>
|
||||
<MenuFlyoutItem Command="{Binding CopyToClipboardCommand, RelativeSource={RelativeSource TemplatedParent}}" Text="复制图像"/>
|
||||
</MenuFlyout>
|
||||
</Grid.ContextFlyout>
|
||||
<Image
|
||||
Name="PlaceholderImage"
|
||||
Margin="{TemplateBinding PlaceholderMargin}"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
|
||||
namespace Snap.Hutao.Control;
|
||||
|
||||
@@ -37,18 +36,9 @@ internal class Loading : Microsoft.UI.Xaml.Controls.ContentControl
|
||||
private static void IsLoadingPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
Loading control = (Loading)d;
|
||||
control.presenter ??= control.GetTemplateChild("ContentGrid") as FrameworkElement;
|
||||
|
||||
if ((bool)e.NewValue)
|
||||
{
|
||||
control.presenter ??= control.GetTemplateChild("ContentGrid") as FrameworkElement;
|
||||
}
|
||||
else if (control.presenter is not null)
|
||||
{
|
||||
XamlMarkupHelper.UnloadObject(control.presenter);
|
||||
control.presenter = null;
|
||||
}
|
||||
|
||||
control.Update();
|
||||
control?.Update();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
<ContentPresenter
|
||||
x:Name="ContentGrid"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
x:Load="False">
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
|
||||
<ContentPresenter.RenderTransform>
|
||||
<CompositeTransform/>
|
||||
</ContentPresenter.RenderTransform>
|
||||
@@ -85,4 +84,4 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
||||
|
||||
@@ -53,14 +53,9 @@ internal class ScopedPage : Page
|
||||
{
|
||||
try
|
||||
{
|
||||
TViewModel viewModel = pageScope.ServiceProvider.GetRequiredService<TViewModel>();
|
||||
using (viewModel.DisposeLock.Enter())
|
||||
{
|
||||
viewModel.IsViewDisposed = false;
|
||||
viewModel.CancellationToken = viewCancellationTokenSource.Token;
|
||||
viewModel.DeferContentLoader = new DeferContentLoader(this);
|
||||
}
|
||||
|
||||
IViewModel viewModel = pageScope.ServiceProvider.GetRequiredService<TViewModel>();
|
||||
viewModel.CancellationToken = viewCancellationTokenSource.Token;
|
||||
viewModel.DeferContentLoader = new DeferContentLoader(this);
|
||||
DataContext = viewModel;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -109,9 +104,10 @@ internal class ScopedPage : Page
|
||||
viewCancellationTokenSource.Cancel();
|
||||
IViewModel viewModel = (IViewModel)DataContext;
|
||||
|
||||
using (viewModel.DisposeLock.Enter())
|
||||
using (SemaphoreSlim locker = viewModel.DisposeLock)
|
||||
{
|
||||
// Wait to ensure viewmodel operation is completed
|
||||
locker.Wait();
|
||||
viewModel.IsViewDisposed = true;
|
||||
|
||||
// Dispose the scope
|
||||
|
||||
@@ -21,8 +21,8 @@ internal sealed partial class SizeRestrictedContentControl : ContentControl
|
||||
element.Measure(availableSize);
|
||||
Size contentDesiredSize = element.DesiredSize;
|
||||
Size contentActualOrDesiredSize = new(
|
||||
Math.Min(Math.Max(element.ActualWidth, contentDesiredSize.Width), availableSize.Width),
|
||||
Math.Min(Math.Max(element.ActualHeight, contentDesiredSize.Height), availableSize.Height));
|
||||
Math.Max(element.ActualWidth, contentDesiredSize.Width),
|
||||
Math.Max(element.ActualHeight, contentDesiredSize.Height));
|
||||
|
||||
if (IsWidthRestricted)
|
||||
{
|
||||
|
||||
@@ -5,5 +5,5 @@ namespace Snap.Hutao.Core.Abstraction;
|
||||
|
||||
internal interface IPinnable<TData>
|
||||
{
|
||||
ref TData GetPinnableReference();
|
||||
ref readonly TData GetPinnableReference();
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.Abstraction;
|
||||
|
||||
internal interface IResurrectable
|
||||
{
|
||||
void Resurrect();
|
||||
}
|
||||
@@ -11,13 +11,16 @@ using Snap.Hutao.Web.Request.Builder;
|
||||
using Snap.Hutao.Web.Request.Builder.Abstraction;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Frozen;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Snap.Hutao.Core.Caching;
|
||||
|
||||
/// <summary>
|
||||
/// Provides methods and tools to cache files in a folder
|
||||
/// The class's name will become the cache folder's name
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[ConstructorGenerated]
|
||||
[Injection(InjectAs.Singleton, typeof(IImageCache))]
|
||||
@@ -25,9 +28,10 @@ namespace Snap.Hutao.Core.Caching;
|
||||
[PrimaryHttpMessageHandler(MaxConnectionsPerServer = 8)]
|
||||
internal sealed partial class ImageCache : IImageCache, IImageCacheFilePathOperation
|
||||
{
|
||||
private const string CacheFolderName = nameof(ImageCache);
|
||||
private const string CacheFailedDownloadTasksName = $"{nameof(ImageCache)}.FailedDownloadTasks";
|
||||
|
||||
private static readonly FrozenDictionary<int, TimeSpan> DelayFromRetryCount = FrozenDictionary.ToFrozenDictionary(
|
||||
private readonly FrozenDictionary<int, TimeSpan> retryCountToDelay = FrozenDictionary.ToFrozenDictionary(
|
||||
[
|
||||
KeyValuePair.Create(0, TimeSpan.FromSeconds(4)),
|
||||
KeyValuePair.Create(1, TimeSpan.FromSeconds(16)),
|
||||
@@ -42,13 +46,16 @@ internal sealed partial class ImageCache : IImageCache, IImageCacheFilePathOpera
|
||||
private readonly ILogger<ImageCache> logger;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
|
||||
private string? baseFolder;
|
||||
private string? cacheFolder;
|
||||
|
||||
private string CacheFolder
|
||||
{
|
||||
get => LazyInitializer.EnsureInitialized(ref cacheFolder, () =>
|
||||
{
|
||||
return serviceProvider.GetRequiredService<RuntimeOptions>().GetLocalCacheImageCacheFolder();
|
||||
baseFolder ??= serviceProvider.GetRequiredService<RuntimeOptions>().LocalCache;
|
||||
DirectoryInfo info = Directory.CreateDirectory(Path.Combine(baseFolder, CacheFolderName));
|
||||
return info.FullName;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -142,7 +149,8 @@ internal sealed partial class ImageCache : IImageCache, IImageCacheFilePathOpera
|
||||
return treatNullFileAsInvalid;
|
||||
}
|
||||
|
||||
return new FileInfo(file).Length == 0;
|
||||
FileInfo fileInfo = new(file);
|
||||
return fileInfo.Length == 0;
|
||||
}
|
||||
|
||||
private void RemoveCore(IEnumerable<string> filePaths)
|
||||
@@ -164,76 +172,80 @@ internal sealed partial class ImageCache : IImageCache, IImageCacheFilePathOpera
|
||||
[SuppressMessage("", "SH003")]
|
||||
private async Task DownloadFileAsync(Uri uri, string baseFile)
|
||||
{
|
||||
using (HttpClient httpClient = httpClientFactory.CreateClient(nameof(ImageCache)))
|
||||
int retryCount = 0;
|
||||
HttpClient httpClient = httpClientFactory.CreateClient(nameof(ImageCache));
|
||||
while (retryCount < 3)
|
||||
{
|
||||
int retryCount = 0;
|
||||
|
||||
HttpRequestMessageBuilder requestMessageBuilder = httpRequestMessageBuilderFactory
|
||||
.Create()
|
||||
.SetRequestUri(uri)
|
||||
.SetStaticResourceControlHeadersIf(uri.Host.Contains("api.snapgenshin.com", StringComparison.OrdinalIgnoreCase)) // These headers are only available for our own api
|
||||
|
||||
// These headers are only available for our own api
|
||||
.SetStaticResourceControlHeadersIf(uri.Host.Contains("api.snapgenshin.com", StringComparison.OrdinalIgnoreCase))
|
||||
.Get();
|
||||
|
||||
while (retryCount < 3)
|
||||
using (HttpRequestMessage requestMessage = requestMessageBuilder.HttpRequestMessage)
|
||||
{
|
||||
requestMessageBuilder.Resurrect();
|
||||
|
||||
using (HttpRequestMessage requestMessage = requestMessageBuilder.HttpRequestMessage)
|
||||
using (HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
|
||||
{
|
||||
using (HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
|
||||
if (responseMessage.RequestMessage is { RequestUri: { } target } && target != uri)
|
||||
{
|
||||
// Redirect detection
|
||||
if (responseMessage.RequestMessage is { RequestUri: { } target } && target != uri)
|
||||
logger.LogDebug("The Request '{Source}' has been redirected to '{Target}'", uri, target);
|
||||
}
|
||||
|
||||
if (responseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
if (responseMessage.Content.Headers.ContentType?.MediaType is "application/json")
|
||||
{
|
||||
logger.LogDebug("The Request '{Source}' has been redirected to '{Target}'", uri, target);
|
||||
#if DEBUG
|
||||
DebugTrack(uri);
|
||||
#endif
|
||||
string raw = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
logger.LogColorizedCritical("Failed to download '{Uri}' with unexpected body '{Raw}'", (uri, ConsoleColor.Red), (raw, ConsoleColor.DarkYellow));
|
||||
return;
|
||||
}
|
||||
|
||||
if (responseMessage.IsSuccessStatusCode)
|
||||
using (Stream httpStream = await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false))
|
||||
{
|
||||
if (responseMessage.Content.Headers.ContentType?.MediaType is "application/json")
|
||||
using (FileStream fileStream = File.Create(baseFile))
|
||||
{
|
||||
DebugTrackFailedUri(uri);
|
||||
string raw = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
logger.LogColorizedCritical("Failed to download '{Uri}' with unexpected body '{Raw}'", (uri, ConsoleColor.Red), (raw, ConsoleColor.DarkYellow));
|
||||
await httpStream.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (Stream httpStream = await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false))
|
||||
switch (responseMessage.StatusCode)
|
||||
{
|
||||
case HttpStatusCode.TooManyRequests:
|
||||
{
|
||||
using (FileStream fileStream = File.Create(baseFile))
|
||||
{
|
||||
await httpStream.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
retryCount++;
|
||||
TimeSpan delay = responseMessage.Headers.RetryAfter?.Delta ?? retryCountToDelay[retryCount];
|
||||
logger.LogInformation("Retry download '{Uri}' after {Delay}.", uri, delay);
|
||||
await Task.Delay(delay).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (responseMessage.StatusCode)
|
||||
{
|
||||
case HttpStatusCode.TooManyRequests:
|
||||
{
|
||||
retryCount++;
|
||||
TimeSpan delay = responseMessage.Headers.RetryAfter?.Delta ?? DelayFromRetryCount[retryCount];
|
||||
logger.LogInformation("Retry download '{Uri}' after {Delay}.", uri, delay);
|
||||
await Task.Delay(delay).ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
DebugTrackFailedUri(uri);
|
||||
logger.LogColorizedCritical("Failed to download '{Uri}' with status code '{StatusCode}'", (uri, ConsoleColor.Red), (responseMessage.StatusCode, ConsoleColor.DarkYellow));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
#if DEBUG
|
||||
DebugTrack(uri);
|
||||
#endif
|
||||
logger.LogColorizedCritical("Failed to download '{Uri}' with status code '{StatusCode}'", (uri, ConsoleColor.Red), (responseMessage.StatusCode, ConsoleColor.DarkYellow));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugTrackFailedUri(Uri uri)
|
||||
#if DEBUG
|
||||
internal partial class ImageCache
|
||||
{
|
||||
private void DebugTrack(Uri uri)
|
||||
{
|
||||
HashSet<string>? set = memoryCache.GetOrCreate(CacheFailedDownloadTasksName, entry => new HashSet<string>());
|
||||
HashSet<string>? set = memoryCache.GetOrCreate(CacheFailedDownloadTasksName, entry => entry.Value ??= new HashSet<string>()) as HashSet<string>;
|
||||
set?.Add(uri.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -70,7 +70,7 @@ internal sealed class ObservableReorderableDbCollection<TEntity> : ObservableCol
|
||||
|
||||
[SuppressMessage("", "SA1402")]
|
||||
internal sealed class ObservableReorderableDbCollection<TEntityOnly, TEntity> : ObservableCollection<TEntityOnly>
|
||||
where TEntityOnly : class, IEntityAccess<TEntity>
|
||||
where TEntityOnly : class, IEntityOnly<TEntity>
|
||||
where TEntity : class, IReorderable
|
||||
{
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
|
||||
@@ -73,7 +73,7 @@ internal sealed partial class ScopedDbCurrent<TEntity, TMessage>
|
||||
|
||||
[ConstructorGenerated]
|
||||
internal sealed partial class ScopedDbCurrent<TEntityOnly, TEntity, TMessage>
|
||||
where TEntityOnly : class, IEntityAccess<TEntity>
|
||||
where TEntityOnly : class, IEntityOnly<TEntity>
|
||||
where TEntity : class, ISelectable
|
||||
where TMessage : Message.ValueChangedMessage<TEntityOnly>, new()
|
||||
{
|
||||
|
||||
@@ -41,7 +41,7 @@ internal static class DependencyInjection
|
||||
.AddJsonOptions()
|
||||
.AddDatabase()
|
||||
.AddInjections()
|
||||
.AddConfiguredHttpClients()
|
||||
.AddAllHttpClients()
|
||||
|
||||
// Discrete services
|
||||
.AddSingleton<IMessenger, WeakReferenceMessenger>()
|
||||
|
||||
@@ -34,27 +34,27 @@ internal static class IocConfiguration
|
||||
.AddTransient(typeof(Database.ScopedDbCurrent<,>))
|
||||
.AddTransient(typeof(Database.ScopedDbCurrent<,,>))
|
||||
.AddDbContextPool<AppDbContext>(AddDbContextCore);
|
||||
}
|
||||
|
||||
static void AddDbContextCore(IServiceProvider serviceProvider, DbContextOptionsBuilder builder)
|
||||
private static void AddDbContextCore(IServiceProvider serviceProvider, DbContextOptionsBuilder builder)
|
||||
{
|
||||
RuntimeOptions runtimeOptions = serviceProvider.GetRequiredService<RuntimeOptions>();
|
||||
string dbFile = System.IO.Path.Combine(runtimeOptions.DataFolder, "Userdata.db");
|
||||
string sqlConnectionString = $"Data Source={dbFile}";
|
||||
|
||||
// Temporarily create a context
|
||||
using (AppDbContext context = AppDbContext.Create(serviceProvider, sqlConnectionString))
|
||||
{
|
||||
RuntimeOptions runtimeOptions = serviceProvider.GetRequiredService<RuntimeOptions>();
|
||||
string dbFile = System.IO.Path.Combine(runtimeOptions.DataFolder, "Userdata.db");
|
||||
string sqlConnectionString = $"Data Source={dbFile}";
|
||||
|
||||
// Temporarily create a context
|
||||
using (AppDbContext context = AppDbContext.Create(serviceProvider, sqlConnectionString))
|
||||
if (context.Database.GetPendingMigrations().Any())
|
||||
{
|
||||
if (context.Database.GetPendingMigrations().Any())
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("[Database] Performing AppDbContext Migrations");
|
||||
context.Database.Migrate();
|
||||
}
|
||||
System.Diagnostics.Debug.WriteLine("[Database] Performing AppDbContext Migrations");
|
||||
context.Database.Migrate();
|
||||
}
|
||||
|
||||
builder
|
||||
.EnableSensitiveDataLogging()
|
||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
||||
.UseSqlite(sqlConnectionString);
|
||||
}
|
||||
|
||||
builder
|
||||
.EnableSensitiveDataLogging()
|
||||
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
||||
.UseSqlite(sqlConnectionString);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ internal static partial class IocHttpClientConfiguration
|
||||
{
|
||||
private const string ApplicationJson = "application/json";
|
||||
|
||||
public static IServiceCollection AddConfiguredHttpClients(this IServiceCollection services)
|
||||
public static IServiceCollection AddAllHttpClients(this IServiceCollection services)
|
||||
{
|
||||
services
|
||||
.ConfigureHttpClientDefaults(clientBuilder =>
|
||||
@@ -27,7 +27,7 @@ internal static partial class IocHttpClientConfiguration
|
||||
HttpClientHandler clientHandler = (HttpClientHandler)handler;
|
||||
clientHandler.AllowAutoRedirect = true;
|
||||
clientHandler.UseProxy = true;
|
||||
clientHandler.Proxy = provider.GetRequiredService<HttpProxyUsingSystemProxy>();
|
||||
clientHandler.Proxy = provider.GetRequiredService<DynamicHttpProxy>();
|
||||
});
|
||||
})
|
||||
.AddHttpClients();
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Snap.Hutao.Core.ExceptionService;
|
||||
|
||||
/// <summary>
|
||||
/// 帮助更好的抛出异常
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[System.Diagnostics.StackTraceHidden]
|
||||
[Obsolete("Use HutaoException instead")]
|
||||
internal static class ThrowHelper
|
||||
{
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static ArgumentException Argument(string message, string? paramName)
|
||||
{
|
||||
throw new ArgumentException(message, paramName);
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,7 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
using Snap.Hutao.Win32.System.Com;
|
||||
using Snap.Hutao.Win32.UI.Shell;
|
||||
using System.IO;
|
||||
using static Snap.Hutao.Win32.Macros;
|
||||
using static Snap.Hutao.Win32.Ole32;
|
||||
using static Snap.Hutao.Win32.Shell32;
|
||||
|
||||
namespace Snap.Hutao.Core.IO;
|
||||
|
||||
@@ -23,29 +18,4 @@ internal static class DirectoryOperation
|
||||
FileSystem.MoveDirectory(sourceDirName, destDirName, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static unsafe bool UnsafeRename(string path, string name, FILEOPERATION_FLAGS flags = FILEOPERATION_FLAGS.FOF_ALLOWUNDO | FILEOPERATION_FLAGS.FOF_NOCONFIRMMKDIR)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (SUCCEEDED(CoCreateInstance(in Win32.UI.Shell.FileOperation.CLSID, default, CLSCTX.CLSCTX_INPROC_SERVER, in IFileOperation.IID, out IFileOperation* pFileOperation)))
|
||||
{
|
||||
if (SUCCEEDED(SHCreateItemFromParsingName(path, default, in IShellItem.IID, out IShellItem* pShellItem)))
|
||||
{
|
||||
pFileOperation->SetOperationFlags(flags);
|
||||
pFileOperation->RenameItem(pShellItem, name, default);
|
||||
|
||||
if (SUCCEEDED(pFileOperation->PerformOperations()))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pShellItem);
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pFileOperation);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,30 +45,6 @@ internal static class FileOperation
|
||||
return true;
|
||||
}
|
||||
|
||||
public static unsafe bool UnsafeDelete(string path)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (SUCCEEDED(CoCreateInstance(in Win32.UI.Shell.FileOperation.CLSID, default, CLSCTX.CLSCTX_INPROC_SERVER, in IFileOperation.IID, out IFileOperation* pFileOperation)))
|
||||
{
|
||||
if (SUCCEEDED(SHCreateItemFromParsingName(path, default, in IShellItem.IID, out IShellItem* pShellItem)))
|
||||
{
|
||||
pFileOperation->DeleteItem(pShellItem, default);
|
||||
|
||||
if (SUCCEEDED(pFileOperation->PerformOperations()))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pShellItem);
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pFileOperation);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static unsafe bool UnsafeMove(string sourceFileName, string destFileName)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -97,4 +73,28 @@ internal static class FileOperation
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static unsafe bool UnsafeDelete(string path)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (SUCCEEDED(CoCreateInstance(in Win32.UI.Shell.FileOperation.CLSID, default, CLSCTX.CLSCTX_INPROC_SERVER, in IFileOperation.IID, out IFileOperation* pFileOperation)))
|
||||
{
|
||||
if (SUCCEEDED(SHCreateItemFromParsingName(path, default, in IShellItem.IID, out IShellItem* pShellItem)))
|
||||
{
|
||||
pFileOperation->DeleteItem(pShellItem, default);
|
||||
|
||||
if (SUCCEEDED(pFileOperation->PerformOperations()))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pShellItem);
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pFileOperation);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,6 @@ using System.Text;
|
||||
|
||||
namespace Snap.Hutao.Core.IO.Hashing;
|
||||
|
||||
#if NET9_0_OR_GREATER
|
||||
[Obsolete]
|
||||
#endif
|
||||
internal static class Hash
|
||||
{
|
||||
public static unsafe string SHA1HexString(string input)
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Reflection;
|
||||
namespace Snap.Hutao.Core.IO.Http.Proxy;
|
||||
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class HttpProxyUsingSystemProxy : ObservableObject, IWebProxy, IDisposable
|
||||
internal sealed partial class DynamicHttpProxy : ObservableObject, IWebProxy, IDisposable
|
||||
{
|
||||
private const string ProxySettingPath = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections";
|
||||
|
||||
@@ -20,7 +20,7 @@ internal sealed partial class HttpProxyUsingSystemProxy : ObservableObject, IWeb
|
||||
|
||||
private IWebProxy innerProxy = default!;
|
||||
|
||||
public HttpProxyUsingSystemProxy(IServiceProvider serviceProvider)
|
||||
public DynamicHttpProxy(IServiceProvider serviceProvider)
|
||||
{
|
||||
this.serviceProvider = serviceProvider;
|
||||
UpdateInnerProxy();
|
||||
@@ -56,39 +56,30 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
|
||||
/// <inheritdoc/>
|
||||
public void PostInitialization()
|
||||
{
|
||||
RunPostInitializationAsync().SafeForget();
|
||||
serviceProvider.GetRequiredService<PrivateNamedPipeServer>().RunAsync().SafeForget();
|
||||
ToastNotificationManagerCompat.OnActivated += NotificationActivate;
|
||||
|
||||
async ValueTask RunPostInitializationAsync()
|
||||
using (activateSemaphore.Enter())
|
||||
{
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
// TODO: Introduced in 1.10.2, remove in later version
|
||||
serviceProvider.GetRequiredService<IJumpListInterop>().ClearAsync().SafeForget();
|
||||
serviceProvider.GetRequiredService<IScheduleTaskInterop>().UnregisterAllTasks();
|
||||
|
||||
serviceProvider.GetRequiredService<PrivateNamedPipeServer>().RunAsync().SafeForget();
|
||||
ToastNotificationManagerCompat.OnActivated += NotificationActivate;
|
||||
|
||||
using (await activateSemaphore.EnterAsync().ConfigureAwait(false))
|
||||
if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) < GuideState.Completed)
|
||||
{
|
||||
// TODO: Introduced in 1.10.2, remove in later version
|
||||
serviceProvider.GetRequiredService<IJumpListInterop>().ClearAsync().SafeForget();
|
||||
serviceProvider.GetRequiredService<IScheduleTaskInterop>().UnregisterAllTasks();
|
||||
|
||||
if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) < GuideState.Completed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
serviceProvider.GetRequiredService<HotKeyOptions>().RegisterAll();
|
||||
|
||||
if (serviceProvider.GetRequiredService<AppOptions>().IsNotifyIconEnabled)
|
||||
{
|
||||
XamlLifetime.ApplicationLaunchedWithNotifyIcon = true;
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
serviceProvider.GetRequiredService<App>().DispatcherShutdownMode = DispatcherShutdownMode.OnExplicitShutdown;
|
||||
_ = serviceProvider.GetRequiredService<NotifyIconController>();
|
||||
}
|
||||
|
||||
serviceProvider.GetRequiredService<IQuartzService>().StartAsync(default).SafeForget();
|
||||
return;
|
||||
}
|
||||
|
||||
serviceProvider.GetRequiredService<HotKeyOptions>().RegisterAll();
|
||||
|
||||
if (serviceProvider.GetRequiredService<AppOptions>().IsNotifyIconEnabled)
|
||||
{
|
||||
XamlLifetime.ApplicationLaunchedWithNotifyIcon = true;
|
||||
serviceProvider.GetRequiredService<App>().DispatcherShutdownMode = DispatcherShutdownMode.OnExplicitShutdown;
|
||||
_ = serviceProvider.GetRequiredService<NotifyIconController>();
|
||||
}
|
||||
|
||||
serviceProvider.GetRequiredService<IQuartzService>().StartAsync(default).SafeForget();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,31 +96,25 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
|
||||
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
|
||||
switch (currentWindowReference.Window)
|
||||
if (currentWindowReference.Window is null)
|
||||
{
|
||||
case null:
|
||||
LaunchGameWindow launchGameWindow = serviceProvider.GetRequiredService<LaunchGameWindow>();
|
||||
currentWindowReference.Window = launchGameWindow;
|
||||
currentWindowReference.Window = serviceProvider.GetRequiredService<LaunchGameWindow>();
|
||||
return;
|
||||
}
|
||||
|
||||
launchGameWindow.SwitchTo();
|
||||
launchGameWindow.BringToForeground();
|
||||
return;
|
||||
if (currentWindowReference.Window is MainWindow)
|
||||
{
|
||||
await serviceProvider
|
||||
.GetRequiredService<INavigationService>()
|
||||
.NavigateAsync<View.Page.LaunchGamePage>(INavigationAwaiter.Default, true)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
case MainWindow:
|
||||
await serviceProvider
|
||||
.GetRequiredService<INavigationService>()
|
||||
.NavigateAsync<View.Page.LaunchGamePage>(INavigationAwaiter.Default, true)
|
||||
.ConfigureAwait(false);
|
||||
return;
|
||||
|
||||
case LaunchGameWindow currentLaunchGameWindow:
|
||||
currentLaunchGameWindow.SwitchTo();
|
||||
currentLaunchGameWindow.BringToForeground();
|
||||
return;
|
||||
|
||||
default:
|
||||
Process.GetCurrentProcess().Kill();
|
||||
return;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We have a non-Main Window, just exit current process anyway
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,8 +134,6 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
|
||||
|
||||
private async ValueTask HandleActivationAsync(HutaoActivationArguments args)
|
||||
{
|
||||
await taskContext.SwitchToBackgroundAsync();
|
||||
|
||||
if (activateSemaphore.CurrentCount > 0)
|
||||
{
|
||||
using (await activateSemaphore.EnterAsync().ConfigureAwait(false))
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle.InterProcess.Model;
|
||||
|
||||
internal sealed class ElevationStatusResponse
|
||||
{
|
||||
public ElevationStatusResponse(bool isElevated)
|
||||
{
|
||||
IsElevated = isElevated;
|
||||
}
|
||||
|
||||
public bool IsElevated { get; set; }
|
||||
}
|
||||
@@ -6,9 +6,9 @@ namespace Snap.Hutao.Core.LifeCycle.InterProcess;
|
||||
internal enum PipePacketCommand : byte
|
||||
{
|
||||
None = 0,
|
||||
Exit = 1,
|
||||
Connect = 1,
|
||||
|
||||
RedirectActivation = 10,
|
||||
RequestElevationStatus = 11,
|
||||
ResponseElevationStatus = 12,
|
||||
|
||||
Exit = 30,
|
||||
}
|
||||
@@ -2,83 +2,27 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using System.Buffers;
|
||||
using System.IO.Hashing;
|
||||
using System.IO.Pipes;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle.InterProcess;
|
||||
|
||||
internal static class PipeStreamExtension
|
||||
{
|
||||
public static TData? ReadJsonContent<TData>(this PipeStream stream, ref readonly PipePacketHeader header)
|
||||
public static unsafe byte[] GetValidatedContent(this PipeStream stream, PipePacketHeader* header)
|
||||
{
|
||||
using (IMemoryOwner<byte> memoryOwner = MemoryPool<byte>.Shared.Rent(header.ContentLength))
|
||||
{
|
||||
Span<byte> content = memoryOwner.Memory.Span[..header.ContentLength];
|
||||
stream.ReadExactly(content);
|
||||
|
||||
HutaoException.ThrowIf(XxHash64.HashToUInt64(content) != header.Checksum, "PipePacket Content Hash incorrect");
|
||||
return JsonSerializer.Deserialize<TData>(content);
|
||||
}
|
||||
byte[] content = new byte[header->ContentLength];
|
||||
stream.ReadAtLeast(content, header->ContentLength, false);
|
||||
HutaoException.ThrowIf(XxHash64.HashToUInt64(content) != header->Checksum, "PipePacket Content Hash incorrect");
|
||||
return content;
|
||||
}
|
||||
|
||||
public static unsafe void ReadPacket<TData>(this PipeStream stream, out PipePacketHeader header, out TData? data)
|
||||
where TData : class
|
||||
public static unsafe void WritePacket(this PipeStream stream, PipePacketHeader* header, byte[] content)
|
||||
{
|
||||
data = default;
|
||||
header->ContentLength = content.Length;
|
||||
header->Checksum = XxHash64.HashToUInt64(content);
|
||||
|
||||
stream.ReadPacket(out header);
|
||||
if (header.ContentType is PipePacketContentType.Json)
|
||||
{
|
||||
data = stream.ReadJsonContent<TData>(in header);
|
||||
}
|
||||
}
|
||||
|
||||
[SkipLocalsInit]
|
||||
public static unsafe void ReadPacket(this PipeStream stream, out PipePacketHeader header)
|
||||
{
|
||||
fixed (PipePacketHeader* pHeader = &header)
|
||||
{
|
||||
stream.ReadExactly(new(pHeader, sizeof(PipePacketHeader)));
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe void WritePacketWithJsonContent<TData>(this PipeStream stream, byte version, PipePacketType type, PipePacketCommand command, TData data)
|
||||
{
|
||||
PipePacketHeader header = default;
|
||||
header.Version = version;
|
||||
header.Type = type;
|
||||
header.Command = command;
|
||||
header.ContentType = PipePacketContentType.Json;
|
||||
|
||||
stream.WritePacket(ref header, JsonSerializer.SerializeToUtf8Bytes(data));
|
||||
}
|
||||
|
||||
public static unsafe void WritePacket(this PipeStream stream, ref PipePacketHeader header, byte[] content)
|
||||
{
|
||||
header.ContentLength = content.Length;
|
||||
header.Checksum = XxHash64.HashToUInt64(content);
|
||||
|
||||
stream.WritePacket(in header);
|
||||
stream.Write(new(header, sizeof(PipePacketHeader)));
|
||||
stream.Write(content);
|
||||
}
|
||||
|
||||
public static unsafe void WritePacket(this PipeStream stream, byte version, PipePacketType type, PipePacketCommand command)
|
||||
{
|
||||
PipePacketHeader header = default;
|
||||
header.Version = version;
|
||||
header.Type = type;
|
||||
header.Command = command;
|
||||
|
||||
stream.WritePacket(in header);
|
||||
}
|
||||
|
||||
public static unsafe void WritePacket(this PipeStream stream, ref readonly PipePacketHeader header)
|
||||
{
|
||||
fixed (PipePacketHeader* pHeader = &header)
|
||||
{
|
||||
stream.Write(new(pHeader, sizeof(PipePacketHeader)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle.InterProcess;
|
||||
|
||||
internal static class PrivateNamedPipe
|
||||
{
|
||||
public const int Version = 1;
|
||||
public const string Name = "Snap.Hutao.PrivateNamedPipe";
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Windows.AppLifecycle;
|
||||
using Snap.Hutao.Core.LifeCycle.InterProcess.Model;
|
||||
using System.IO.Pipes;
|
||||
|
||||
namespace Snap.Hutao.Core.LifeCycle.InterProcess;
|
||||
@@ -11,30 +10,72 @@ namespace Snap.Hutao.Core.LifeCycle.InterProcess;
|
||||
[ConstructorGenerated]
|
||||
internal sealed partial class PrivateNamedPipeClient : IDisposable
|
||||
{
|
||||
private readonly NamedPipeClientStream clientStream = new(".", PrivateNamedPipe.Name, PipeDirection.InOut, PipeOptions.Asynchronous | PipeOptions.WriteThrough);
|
||||
private readonly NamedPipeClientStream clientStream = new(".", "Snap.Hutao.PrivateNamedPipe", PipeDirection.InOut, PipeOptions.Asynchronous | PipeOptions.WriteThrough);
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
|
||||
public unsafe bool TryRedirectActivationTo(AppActivationArguments args)
|
||||
{
|
||||
if (clientStream.TryConnectOnce())
|
||||
{
|
||||
clientStream.WritePacket(PrivateNamedPipe.Version, PipePacketType.Request, PipePacketCommand.RequestElevationStatus);
|
||||
clientStream.ReadPacket(out PipePacketHeader header, out ElevationStatusResponse? response);
|
||||
ArgumentNullException.ThrowIfNull(response);
|
||||
|
||||
// Prefer elevated instance
|
||||
if (runtimeOptions.IsElevated && !response.IsElevated)
|
||||
bool serverElevated = false;
|
||||
{
|
||||
// Notify previous instance to exit
|
||||
clientStream.WritePacket(PrivateNamedPipe.Version, PipePacketType.SessionTermination, PipePacketCommand.Exit);
|
||||
// Connect
|
||||
PipePacketHeader connectPacket = default;
|
||||
connectPacket.Version = 1;
|
||||
connectPacket.Type = PipePacketType.Request;
|
||||
connectPacket.Command = PipePacketCommand.Connect;
|
||||
|
||||
clientStream.Write(new(&connectPacket, sizeof(PipePacketHeader)));
|
||||
}
|
||||
|
||||
{
|
||||
// Get previous instance elevated status
|
||||
Span<byte> headerSpan = stackalloc byte[sizeof(PipePacketHeader)];
|
||||
clientStream.ReadExactly(headerSpan);
|
||||
fixed (byte* pHeader = headerSpan)
|
||||
{
|
||||
PipePacketHeader* header = (PipePacketHeader*)pHeader;
|
||||
ReadOnlySpan<byte> content = clientStream.GetValidatedContent(header);
|
||||
serverElevated = JsonSerializer.Deserialize<bool>(content);
|
||||
}
|
||||
}
|
||||
|
||||
if (!serverElevated && runtimeOptions.IsElevated)
|
||||
{
|
||||
// Kill previous instance to use current elevated instance
|
||||
PipePacketHeader killPacket = default;
|
||||
killPacket.Version = 1;
|
||||
killPacket.Type = PipePacketType.SessionTermination;
|
||||
killPacket.Command = PipePacketCommand.Exit;
|
||||
|
||||
clientStream.Write(new(&killPacket, sizeof(PipePacketHeader)));
|
||||
clientStream.Flush();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Redirect to previous instance
|
||||
HutaoActivationArguments hutaoArgs = HutaoActivationArguments.FromAppActivationArguments(args, isRedirected: true);
|
||||
clientStream.WritePacketWithJsonContent(PrivateNamedPipe.Version, PipePacketType.Request, PipePacketCommand.RedirectActivation, hutaoArgs);
|
||||
clientStream.WritePacket(PrivateNamedPipe.Version, PipePacketType.SessionTermination, PipePacketCommand.None);
|
||||
{
|
||||
// Redirect to previous instance
|
||||
PipePacketHeader redirectActivationPacket = default;
|
||||
redirectActivationPacket.Version = 1;
|
||||
redirectActivationPacket.Type = PipePacketType.Request;
|
||||
redirectActivationPacket.Command = PipePacketCommand.RedirectActivation;
|
||||
redirectActivationPacket.ContentType = PipePacketContentType.Json;
|
||||
|
||||
HutaoActivationArguments hutaoArgs = HutaoActivationArguments.FromAppActivationArguments(args, isRedirected: true);
|
||||
byte[] jsonBytes = JsonSerializer.SerializeToUtf8Bytes(hutaoArgs);
|
||||
|
||||
clientStream.WritePacket(&redirectActivationPacket, jsonBytes);
|
||||
}
|
||||
|
||||
{
|
||||
// Terminate session
|
||||
PipePacketHeader terminationPacket = default;
|
||||
terminationPacket.Version = 1;
|
||||
terminationPacket.Type = PipePacketType.SessionTermination;
|
||||
|
||||
clientStream.Write(new(&terminationPacket, sizeof(PipePacketHeader)));
|
||||
}
|
||||
|
||||
clientStream.Flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ internal sealed partial class PrivateNamedPipeMessageDispatcher
|
||||
serviceProvider.GetRequiredService<IAppActivation>().Activate(args);
|
||||
}
|
||||
|
||||
public void ExitApplication()
|
||||
public void Exit()
|
||||
{
|
||||
ITaskContext taskContext = serviceProvider.GetRequiredService<ITaskContext>();
|
||||
App app = serviceProvider.GetRequiredService<App>();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.LifeCycle.InterProcess.Model;
|
||||
using System.IO.Pipes;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
@@ -13,6 +12,8 @@ internal sealed partial class PrivateNamedPipeServer : IDisposable
|
||||
{
|
||||
private readonly PrivateNamedPipeMessageDispatcher messageDispatcher;
|
||||
private readonly RuntimeOptions runtimeOptions;
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly App app;
|
||||
|
||||
private readonly CancellationTokenSource serverTokenSource = new();
|
||||
private readonly SemaphoreSlim serverSemaphore = new(1);
|
||||
@@ -23,6 +24,8 @@ internal sealed partial class PrivateNamedPipeServer : IDisposable
|
||||
{
|
||||
messageDispatcher = serviceProvider.GetRequiredService<PrivateNamedPipeMessageDispatcher>();
|
||||
runtimeOptions = serviceProvider.GetRequiredService<RuntimeOptions>();
|
||||
taskContext = serviceProvider.GetRequiredService<ITaskContext>();
|
||||
app = serviceProvider.GetRequiredService<App>();
|
||||
|
||||
PipeSecurity? pipeSecurity = default;
|
||||
|
||||
@@ -35,7 +38,7 @@ internal sealed partial class PrivateNamedPipeServer : IDisposable
|
||||
}
|
||||
|
||||
serverStream = NamedPipeServerStreamAcl.Create(
|
||||
PrivateNamedPipe.Name,
|
||||
"Snap.Hutao.PrivateNamedPipe",
|
||||
PipeDirection.InOut,
|
||||
NamedPipeServerStream.MaxAllowedServerInstances,
|
||||
PipeTransmissionMode.Byte,
|
||||
@@ -75,28 +78,41 @@ internal sealed partial class PrivateNamedPipeServer : IDisposable
|
||||
|
||||
private unsafe void RunPacketSession(NamedPipeServerStream serverStream, CancellationToken token)
|
||||
{
|
||||
while (serverStream.IsConnected && !token.IsCancellationRequested)
|
||||
Span<byte> headerSpan = stackalloc byte[sizeof(PipePacketHeader)];
|
||||
bool sessionTerminated = false;
|
||||
while (serverStream.IsConnected && !sessionTerminated && !token.IsCancellationRequested)
|
||||
{
|
||||
serverStream.ReadPacket(out PipePacketHeader header);
|
||||
switch ((header.Type, header.Command))
|
||||
serverStream.ReadExactly(headerSpan);
|
||||
fixed (byte* pHeader = headerSpan)
|
||||
{
|
||||
case (PipePacketType.Request, PipePacketCommand.RequestElevationStatus):
|
||||
ElevationStatusResponse resp = new(runtimeOptions.IsElevated);
|
||||
serverStream.WritePacketWithJsonContent(PrivateNamedPipe.Version, PipePacketType.Response, PipePacketCommand.ResponseElevationStatus, resp);
|
||||
serverStream.Flush();
|
||||
break;
|
||||
case (PipePacketType.Request, PipePacketCommand.RedirectActivation):
|
||||
HutaoActivationArguments? hutaoArgs = serverStream.ReadJsonContent<HutaoActivationArguments>(in header);
|
||||
messageDispatcher.RedirectActivation(hutaoArgs);
|
||||
break;
|
||||
case (PipePacketType.SessionTermination, _):
|
||||
serverStream.Disconnect();
|
||||
if (header.Command is PipePacketCommand.Exit)
|
||||
{
|
||||
messageDispatcher.ExitApplication();
|
||||
}
|
||||
PipePacketHeader* header = (PipePacketHeader*)pHeader;
|
||||
|
||||
return;
|
||||
switch ((header->Type, header->Command, header->ContentType))
|
||||
{
|
||||
case (PipePacketType.Request, PipePacketCommand.Connect, _):
|
||||
PipePacketHeader elevatedPacket = default;
|
||||
elevatedPacket.Version = 1;
|
||||
elevatedPacket.Type = PipePacketType.Response;
|
||||
elevatedPacket.ContentType = PipePacketContentType.Json;
|
||||
|
||||
byte[] elevatedBytes = JsonSerializer.SerializeToUtf8Bytes(runtimeOptions.IsElevated);
|
||||
serverStream.WritePacket(&elevatedPacket, elevatedBytes);
|
||||
|
||||
break;
|
||||
case (PipePacketType.Request, PipePacketCommand.RedirectActivation, PipePacketContentType.Json):
|
||||
ReadOnlySpan<byte> content = serverStream.GetValidatedContent(header);
|
||||
messageDispatcher.RedirectActivation(JsonSerializer.Deserialize<HutaoActivationArguments>(content));
|
||||
break;
|
||||
case (PipePacketType.SessionTermination, _, _):
|
||||
serverStream.Disconnect();
|
||||
sessionTerminated = true;
|
||||
if (header->Command is PipePacketCommand.Exit)
|
||||
{
|
||||
messageDispatcher.Exit();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,4 @@ internal static class RuntimeOptionsExtension
|
||||
Directory.CreateDirectory(directory);
|
||||
return directory;
|
||||
}
|
||||
|
||||
public static string GetLocalCacheImageCacheFolder(this RuntimeOptions options)
|
||||
{
|
||||
string directory = Path.Combine(options.LocalCache, "ImageCache");
|
||||
Directory.CreateDirectory(directory);
|
||||
return directory;
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop
|
||||
IUnknownMarshal.Release(pPersistFile);
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pShellLink);
|
||||
uint value = IUnknownMarshal.Release(pShellLink);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -7,22 +7,22 @@ namespace Snap.Hutao.Core.Threading;
|
||||
|
||||
internal static class SpinWaitPolyfill
|
||||
{
|
||||
public static unsafe void SpinUntil<T>(ref readonly T state, delegate*<ref readonly T, bool> condition)
|
||||
public static unsafe void SpinUntil<T>(ref T state, delegate*<ref readonly T, bool> condition)
|
||||
{
|
||||
SpinWait spinner = default;
|
||||
while (!condition(in state))
|
||||
while (!condition(ref state))
|
||||
{
|
||||
spinner.SpinOnce();
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static unsafe bool SpinUntil<T>(ref readonly T state, delegate*<ref readonly T, bool> condition, TimeSpan timeout)
|
||||
public static unsafe bool SpinUntil<T>(ref T state, delegate*<ref readonly T, bool> condition, TimeSpan timeout)
|
||||
{
|
||||
long startTime = Stopwatch.GetTimestamp();
|
||||
|
||||
SpinWait spinner = default;
|
||||
while (!condition(in state))
|
||||
while (!condition(ref state))
|
||||
{
|
||||
spinner.SpinOnce();
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ internal static class TypeNameHelper
|
||||
|
||||
if (builder is null)
|
||||
{
|
||||
if (options.NestedTypeDelimiter is not DefaultNestedTypeDelimiter)
|
||||
if (options.NestedTypeDelimiter != DefaultNestedTypeDelimiter)
|
||||
{
|
||||
return name.Replace(DefaultNestedTypeDelimiter, options.NestedTypeDelimiter);
|
||||
}
|
||||
@@ -112,7 +112,7 @@ internal static class TypeNameHelper
|
||||
}
|
||||
|
||||
builder.Append(name);
|
||||
if (options.NestedTypeDelimiter is not DefaultNestedTypeDelimiter)
|
||||
if (options.NestedTypeDelimiter != DefaultNestedTypeDelimiter)
|
||||
{
|
||||
builder.Replace(DefaultNestedTypeDelimiter, options.NestedTypeDelimiter, builder.Length - name.Length, name.Length);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using Windows.Graphics;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing;
|
||||
|
||||
internal readonly struct RectInt16
|
||||
internal readonly struct CompactRect
|
||||
{
|
||||
private readonly short x;
|
||||
private readonly short y;
|
||||
private readonly short width;
|
||||
private readonly short height;
|
||||
|
||||
private RectInt16(int x, int y, int width, int height)
|
||||
private CompactRect(int x, int y, int width, int height)
|
||||
{
|
||||
this.x = (short)x;
|
||||
this.y = (short)y;
|
||||
@@ -20,22 +21,24 @@ internal readonly struct RectInt16
|
||||
this.height = (short)height;
|
||||
}
|
||||
|
||||
public static implicit operator RectInt32(RectInt16 rect)
|
||||
public static implicit operator RectInt32(CompactRect rect)
|
||||
{
|
||||
return new(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
|
||||
public static explicit operator RectInt16(RectInt32 rect)
|
||||
public static explicit operator CompactRect(RectInt32 rect)
|
||||
{
|
||||
return new(rect.X, rect.Y, rect.Width, rect.Height);
|
||||
}
|
||||
|
||||
public static unsafe explicit operator RectInt16(ulong value)
|
||||
public static unsafe explicit operator CompactRect(ulong value)
|
||||
{
|
||||
return *(RectInt16*)&value;
|
||||
Unsafe.SkipInit(out CompactRect rect);
|
||||
*(ulong*)&rect = value;
|
||||
return rect;
|
||||
}
|
||||
|
||||
public static unsafe implicit operator ulong(RectInt16 rect)
|
||||
public static unsafe implicit operator ulong(CompactRect rect)
|
||||
{
|
||||
return *(ulong*)▭
|
||||
}
|
||||
@@ -63,8 +63,7 @@ internal static class WindowExtension
|
||||
{
|
||||
ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_SHOW);
|
||||
}
|
||||
|
||||
if (IsIconic(hwnd))
|
||||
else if (IsIconic(hwnd))
|
||||
{
|
||||
ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_RESTORE);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ using Snap.Hutao.Core.LifeCycle;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Windowing.Abstraction;
|
||||
using Snap.Hutao.Core.Windowing.NotifyIcon;
|
||||
using Snap.Hutao.Factory.ContentDialog;
|
||||
using Snap.Hutao.Service;
|
||||
using Snap.Hutao.Win32;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
@@ -100,13 +99,10 @@ internal sealed class XamlWindowController
|
||||
|
||||
private void OnWindowClosed(object sender, WindowEventArgs args)
|
||||
{
|
||||
IContentDialogFactory contentDialogFactory = serviceProvider.GetRequiredService<IContentDialogFactory>();
|
||||
contentDialogFactory.CloseCurrentDialog();
|
||||
|
||||
if (XamlLifetime.ApplicationLaunchedWithNotifyIcon && !XamlLifetime.ApplicationExiting)
|
||||
{
|
||||
//args.Handled = true;
|
||||
//window.Hide();
|
||||
args.Handled = true;
|
||||
window.Hide();
|
||||
|
||||
if (!IsNotifyIconVisible())
|
||||
{
|
||||
@@ -245,7 +241,7 @@ internal sealed class XamlWindowController
|
||||
|
||||
if (window is IXamlWindowRectPersisted rectPersisted)
|
||||
{
|
||||
RectInt32 nonDpiPersistedRect = (RectInt16)LocalSetting.Get(rectPersisted.PersistRectKey, (RectInt16)rect);
|
||||
RectInt32 nonDpiPersistedRect = (CompactRect)LocalSetting.Get(rectPersisted.PersistRectKey, (CompactRect)rect);
|
||||
RectInt32 persistedRect = nonDpiPersistedRect.Scale(scale);
|
||||
|
||||
// If the persisted size is less than min size, we want to reset to the init size.
|
||||
@@ -270,7 +266,7 @@ internal sealed class XamlWindowController
|
||||
{
|
||||
// We save the non-dpi rect here
|
||||
double scale = 1.0 / window.GetRasterizationScale();
|
||||
LocalSetting.Set(rectPersisted.PersistRectKey, (RectInt16)window.AppWindow.GetRect().Scale(scale));
|
||||
LocalSetting.Set(rectPersisted.PersistRectKey, (CompactRect)window.AppWindow.GetRect().Scale(scale));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -199,13 +199,6 @@ internal static partial class EnumerableExtension
|
||||
return list;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static List<TSource> SortBy<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector, Comparison<TKey> comparison)
|
||||
{
|
||||
list.Sort((left, right) => comparison(keySelector(left), keySelector(right)));
|
||||
return list;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static List<TSource> SortByDescending<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector)
|
||||
where TKey : IComparable
|
||||
@@ -220,11 +213,4 @@ internal static partial class EnumerableExtension
|
||||
list.Sort((left, right) => comparer.Compare(keySelector(right), keySelector(left)));
|
||||
return list;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||
public static List<TSource> SortByDescending<TSource, TKey>(this List<TSource> list, Func<TSource, TKey> keySelector, Comparison<TKey> comparison)
|
||||
{
|
||||
list.Sort((left, right) => comparison(keySelector(right), keySelector(left)));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ internal static partial class EnumerableExtension
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ObservableReorderableDbCollection<TEntityOnly, TEntity> ToObservableReorderableDbCollection<TEntityOnly, TEntity>(this IEnumerable<TEntityOnly> source, IServiceProvider serviceProvider)
|
||||
where TEntityOnly : class, IEntityAccess<TEntity>
|
||||
where TEntityOnly : class, IEntityOnly<TEntity>
|
||||
where TEntity : class, IReorderable
|
||||
{
|
||||
return source is List<TEntityOnly> list
|
||||
|
||||
@@ -18,8 +18,6 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
|
||||
private readonly ITaskContext taskContext;
|
||||
private readonly AppOptions appOptions;
|
||||
|
||||
private Microsoft.UI.Xaml.Controls.ContentDialog? currentDialog;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask<ContentDialogResult> CreateForConfirmAsync(string title, string content)
|
||||
{
|
||||
@@ -34,8 +32,6 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
|
||||
RequestedTheme = appOptions.ElementTheme,
|
||||
};
|
||||
|
||||
dialog.Closed += OnContentDialogClosed;
|
||||
currentDialog = dialog;
|
||||
return await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
@@ -54,8 +50,6 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
|
||||
RequestedTheme = appOptions.ElementTheme,
|
||||
};
|
||||
|
||||
dialog.Closed += OnContentDialogClosed;
|
||||
currentDialog = dialog;
|
||||
return await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
@@ -71,8 +65,6 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
|
||||
RequestedTheme = appOptions.ElementTheme,
|
||||
};
|
||||
|
||||
dialog.Closed += OnContentDialogClosed;
|
||||
currentDialog = dialog;
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@@ -83,9 +75,6 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
|
||||
TContentDialog contentDialog = serviceProvider.CreateInstance<TContentDialog>(parameters);
|
||||
contentDialog.XamlRoot = currentWindowReference.GetXamlRoot();
|
||||
contentDialog.RequestedTheme = appOptions.ElementTheme;
|
||||
|
||||
contentDialog.Closed += OnContentDialogClosed;
|
||||
currentDialog = contentDialog;
|
||||
return contentDialog;
|
||||
}
|
||||
|
||||
@@ -95,25 +84,6 @@ internal sealed partial class ContentDialogFactory : IContentDialogFactory
|
||||
TContentDialog contentDialog = serviceProvider.CreateInstance<TContentDialog>(parameters);
|
||||
contentDialog.XamlRoot = currentWindowReference.GetXamlRoot();
|
||||
contentDialog.RequestedTheme = appOptions.ElementTheme;
|
||||
|
||||
contentDialog.Closed += OnContentDialogClosed;
|
||||
currentDialog = contentDialog;
|
||||
return contentDialog;
|
||||
}
|
||||
|
||||
public void CloseCurrentDialog()
|
||||
{
|
||||
currentDialog?.Hide();
|
||||
}
|
||||
|
||||
public async ValueTask CloseCurrentDialogAsync()
|
||||
{
|
||||
await taskContext.SwitchToMainThreadAsync();
|
||||
currentDialog?.Hide();
|
||||
}
|
||||
|
||||
private void OnContentDialogClosed(Microsoft.UI.Xaml.Controls.ContentDialog sender, ContentDialogClosedEventArgs args)
|
||||
{
|
||||
currentDialog = null;
|
||||
}
|
||||
}
|
||||
@@ -40,8 +40,4 @@ internal interface IContentDialogFactory
|
||||
|
||||
ValueTask<TContentDialog> CreateInstanceAsync<TContentDialog>(params object[] parameters)
|
||||
where TContentDialog : Microsoft.UI.Xaml.Controls.ContentDialog;
|
||||
|
||||
void CloseCurrentDialog();
|
||||
|
||||
ValueTask CloseCurrentDialogAsync();
|
||||
}
|
||||
@@ -13,7 +13,7 @@ using Windows.Graphics;
|
||||
namespace Snap.Hutao;
|
||||
|
||||
[HighQuality]
|
||||
[Injection(InjectAs.Transient)]
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class LaunchGameWindow : Window,
|
||||
IDisposable,
|
||||
IXamlWindowExtendContentIntoTitleBar,
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Snap.Hutao;
|
||||
/// 主窗体
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Injection(InjectAs.Transient)]
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class MainWindow : Window,
|
||||
IXamlWindowExtendContentIntoTitleBar,
|
||||
IXamlWindowRectPersisted,
|
||||
|
||||
@@ -12,8 +12,7 @@ namespace Snap.Hutao.Model.Entity;
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Table("inventory_items")]
|
||||
internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, uint>,
|
||||
IDbMappingForeignKeyFrom<InventoryItem, uint, uint>
|
||||
internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, uint>
|
||||
{
|
||||
/// <summary>
|
||||
/// 内部Id
|
||||
@@ -57,21 +56,4 @@ internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, ui
|
||||
ItemId = itemId,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的个数不为0的物品
|
||||
/// </summary>
|
||||
/// <param name="projectId">项目Id</param>
|
||||
/// <param name="itemId">物品Id</param>
|
||||
/// <param name="count">物品个数</param>
|
||||
/// <returns>新的个数不为0的物品</returns>
|
||||
public static InventoryItem From(in Guid projectId, in uint itemId, in uint count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
ProjectId = projectId,
|
||||
ItemId = itemId,
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Model;
|
||||
|
||||
internal interface IEntityAccessWithMetadata<out TEntity, out TMetadata> : IEntityAccess<TEntity>
|
||||
{
|
||||
TMetadata Inner { get; }
|
||||
}
|
||||
|
||||
internal interface IEntityAccess<out TEntity>
|
||||
{
|
||||
TEntity Entity { get; }
|
||||
}
|
||||
26
src/Snap.Hutao/Snap.Hutao/Model/IEntityWithMetadata.cs
Normal file
26
src/Snap.Hutao/Snap.Hutao/Model/IEntityWithMetadata.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Model;
|
||||
|
||||
/// <summary>
|
||||
/// 实体与元数据
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity">实体</typeparam>
|
||||
/// <typeparam name="TMetadata">元数据</typeparam>
|
||||
[HighQuality]
|
||||
internal interface IEntityWithMetadata<out TEntity, out TMetadata> : IEntityOnly<TEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// 元数据
|
||||
/// </summary>
|
||||
TMetadata Inner { get; }
|
||||
}
|
||||
|
||||
internal interface IEntityOnly<out TEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体
|
||||
/// </summary>
|
||||
TEntity Entity { get; }
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace Snap.Hutao.Model.InterChange.GachaLog;
|
||||
/// UIGF物品
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem, INameQualityAccess>
|
||||
internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem, INameQuality>
|
||||
{
|
||||
/// <summary>
|
||||
/// 额外祈愿映射
|
||||
@@ -22,7 +22,7 @@ internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem,
|
||||
[JsonEnum(JsonSerializeType.NumberString)]
|
||||
public GachaType UIGFGachaType { get; set; } = default!;
|
||||
|
||||
public static UIGFItem From(GachaItem item, INameQualityAccess nameQuality)
|
||||
public static UIGFItem From(GachaItem item, INameQuality nameQuality)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
|
||||
internal interface ICultivationItemsAccess
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
List<MaterialId> CultivationItems { get; }
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
|
||||
internal interface IItemConvertible
|
||||
internal interface IItemSource
|
||||
{
|
||||
Model.Item ToItem();
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
/// 物品与星级
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal interface INameQualityAccess
|
||||
internal interface INameQuality
|
||||
{
|
||||
/// <summary>
|
||||
/// 名称
|
||||
@@ -9,7 +9,7 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
/// 指示该类为统计物品的源
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal interface IStatisticsItemConvertible
|
||||
internal interface IStatisticsItemSource
|
||||
{
|
||||
/// <summary>
|
||||
/// 转换到统计物品
|
||||
@@ -10,9 +10,19 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
|
||||
/// 指示该类为简述统计物品的源
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal interface ISummaryItemConvertible
|
||||
internal interface ISummaryItemSource
|
||||
{
|
||||
/// <summary>
|
||||
/// 星级
|
||||
/// </summary>
|
||||
QualityType Quality { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 转换到简述统计物品
|
||||
/// </summary>
|
||||
/// <param name="lastPull">距上个五星</param>
|
||||
/// <param name="time">时间</param>
|
||||
/// <param name="isUp">是否为Up物品</param>
|
||||
/// <returns>简述统计物品</returns>
|
||||
SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||
using Snap.Hutao.Model.Metadata.Converter;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.ViewModel.Complex;
|
||||
using Snap.Hutao.ViewModel.GachaLog;
|
||||
using Snap.Hutao.ViewModel.Wiki;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Avatar;
|
||||
|
||||
/// <summary>
|
||||
/// 角色的接口实现部分
|
||||
/// </summary>
|
||||
internal partial class Avatar : IStatisticsItemSource, ISummaryItemSource, IItemSource, INameQuality, ICalculableSource<ICalculableAvatar>
|
||||
{
|
||||
/// <summary>
|
||||
/// [非元数据] 搭配数据
|
||||
/// TODO:Add View suffix.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public AvatarCollocationView? Collocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// [非元数据] 烹饪奖励
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public CookBonusView? CookBonusView { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// [非元数据] 养成物品视图
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<Material>? CultivationItemsView { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大等级
|
||||
/// </summary>
|
||||
[SuppressMessage("", "CA1822")]
|
||||
public uint MaxLevel { get => GetMaxLevel(); }
|
||||
|
||||
public static uint GetMaxLevel()
|
||||
{
|
||||
return 90U;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICalculableAvatar ToCalculable()
|
||||
{
|
||||
return CalculableAvatar.From(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为基础物品
|
||||
/// </summary>
|
||||
/// <returns>基础物品</returns>
|
||||
public Model.Item ToItem()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public StatisticsItem ToStatisticsItem(int count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
|
||||
Time = time,
|
||||
LastPull = lastPull,
|
||||
IsUp = isUp,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,118 +1,99 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||
using Snap.Hutao.Model.Metadata.Converter;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.ViewModel.Complex;
|
||||
using Snap.Hutao.ViewModel.GachaLog;
|
||||
using Snap.Hutao.ViewModel.Wiki;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Avatar;
|
||||
|
||||
/// <summary>
|
||||
/// 角色
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal partial class Avatar : INameQualityAccess,
|
||||
IStatisticsItemConvertible,
|
||||
ISummaryItemConvertible,
|
||||
IItemConvertible,
|
||||
ICalculableSource<ICalculableAvatar>,
|
||||
ICultivationItemsAccess
|
||||
internal partial class Avatar
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
public AvatarId Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 突破提升 Id 外键
|
||||
/// </summary>
|
||||
public PromoteId PromoteId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序号
|
||||
/// </summary>
|
||||
public uint Sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 体型
|
||||
/// </summary>
|
||||
public BodyType Body { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 正面图标
|
||||
/// </summary>
|
||||
public string Icon { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 侧面图标
|
||||
/// </summary>
|
||||
public string SideIcon { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 角色加入游戏时间
|
||||
/// </summary>
|
||||
public DateTimeOffset BeginTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 星级
|
||||
/// </summary>
|
||||
public QualityType Quality { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 武器类型
|
||||
/// </summary>
|
||||
public WeaponType Weapon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 基础数值
|
||||
/// </summary>
|
||||
public AvatarBaseValue BaseValue { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 生长曲线
|
||||
/// </summary>
|
||||
public List<TypeValue<FightProperty, GrowCurveType>> GrowCurves { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 技能
|
||||
/// </summary>
|
||||
public SkillDepot SkillDepot { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 好感信息/基本信息
|
||||
/// </summary>
|
||||
public FetterInfo FetterInfo { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 皮肤
|
||||
/// </summary>
|
||||
public List<Costume> Costumes { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 养成物品
|
||||
/// </summary>
|
||||
public List<MaterialId> CultivationItems { get; set; } = default!;
|
||||
|
||||
[JsonIgnore]
|
||||
public AvatarCollocationView? CollocationView { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public CookBonusView? CookBonusView { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<Material>? CultivationItemsView { get; set; }
|
||||
|
||||
[SuppressMessage("", "CA1822")]
|
||||
public uint MaxLevel { get => GetMaxLevel(); }
|
||||
|
||||
public static uint GetMaxLevel()
|
||||
{
|
||||
return 90U;
|
||||
}
|
||||
|
||||
public ICalculableAvatar ToCalculable()
|
||||
{
|
||||
return CalculableAvatar.From(this);
|
||||
}
|
||||
|
||||
public Model.Item ToItem()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
};
|
||||
}
|
||||
|
||||
public StatisticsItem ToStatisticsItem(int count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
|
||||
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = AvatarIconConverter.IconNameToUri(Icon),
|
||||
Badge = ElementNameIconConverter.ElementNameToIconUri(FetterInfo.VisionBefore),
|
||||
Quality = Quality,
|
||||
|
||||
Time = time,
|
||||
LastPull = lastPull,
|
||||
IsUp = isUp,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -97,11 +97,6 @@ internal static class AvatarIds
|
||||
public static readonly AvatarId Navia = 10000091;
|
||||
public static readonly AvatarId Gaming = 10000092;
|
||||
public static readonly AvatarId Xianyun = 10000093;
|
||||
public static readonly AvatarId Chiori = 10000094;
|
||||
public static readonly AvatarId Sigewinne = 10000095;
|
||||
public static readonly AvatarId Arlecchino = 10000096;
|
||||
public static readonly AvatarId Sethos = 10000097;
|
||||
public static readonly AvatarId Clorinde = 10000098;
|
||||
|
||||
/// <summary>
|
||||
/// 检查该角色是否为主角
|
||||
|
||||
@@ -75,7 +75,7 @@ internal sealed class Material : DisplayItem
|
||||
DayOfWeek.Monday or DayOfWeek.Thursday => Materials.MondayThursdayItems.Contains(Id),
|
||||
DayOfWeek.Tuesday or DayOfWeek.Friday => Materials.TuesdayFridayItems.Contains(Id),
|
||||
DayOfWeek.Wednesday or DayOfWeek.Saturday => Materials.WednesdaySaturdayItems.Contains(Id),
|
||||
_ => treatSundayAsTrue && (Materials.MondayThursdayItems.Contains(Id) || Materials.TuesdayFridayItems.Contains(Id) || Materials.WednesdaySaturdayItems.Contains(Id)),
|
||||
_ => treatSundayAsTrue,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||
using Snap.Hutao.Model.Metadata.Converter;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.ViewModel.Complex;
|
||||
using Snap.Hutao.ViewModel.GachaLog;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Weapon;
|
||||
|
||||
/// <summary>
|
||||
/// 武器的接口实现
|
||||
/// </summary>
|
||||
internal sealed partial class Weapon : IStatisticsItemSource, ISummaryItemSource, IItemSource, INameQuality, ICalculableSource<ICalculableWeapon>
|
||||
{
|
||||
/// <summary>
|
||||
/// [非元数据] 搭配数据
|
||||
/// TODO:Add View suffix.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public WeaponCollocationView? Collocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// [非元数据] 养成物品视图
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public List<Material>? CultivationItemsView { get; set; }
|
||||
|
||||
/// <inheritdoc cref="INameQuality.Quality" />
|
||||
[JsonIgnore]
|
||||
public QualityType Quality
|
||||
{
|
||||
get => RankLevel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 最大等级
|
||||
/// </summary>
|
||||
internal uint MaxLevel { get => GetMaxLevelByQuality(Quality); }
|
||||
|
||||
public static uint GetMaxLevelByQuality(QualityType quality)
|
||||
{
|
||||
return quality >= QualityType.QUALITY_BLUE ? 90U : 70U;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ICalculableWeapon ToCalculable()
|
||||
{
|
||||
return CalculableWeapon.From(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为基础物品
|
||||
/// </summary>
|
||||
/// <returns>基础物品</returns>
|
||||
public Model.Item ToItem()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Quality = RankLevel,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换到统计物品
|
||||
/// </summary>
|
||||
/// <param name="count">个数</param>
|
||||
/// <returns>统计物品</returns>
|
||||
public StatisticsItem ToStatisticsItem(int count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Quality = RankLevel,
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换到简述统计物品
|
||||
/// </summary>
|
||||
/// <param name="lastPull">距上个五星</param>
|
||||
/// <param name="time">时间</param>
|
||||
/// <param name="isUp">是否为Up物品</param>
|
||||
/// <returns>简述统计物品</returns>
|
||||
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Time = time,
|
||||
Quality = RankLevel,
|
||||
LastPull = lastPull,
|
||||
IsUp = isUp,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,107 +1,69 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||
using Snap.Hutao.Model.Metadata.Converter;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.ViewModel.Complex;
|
||||
using Snap.Hutao.ViewModel.GachaLog;
|
||||
|
||||
namespace Snap.Hutao.Model.Metadata.Weapon;
|
||||
|
||||
/// <summary>
|
||||
/// 武器
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
internal sealed partial class Weapon : INameQualityAccess,
|
||||
IStatisticsItemConvertible,
|
||||
ISummaryItemConvertible,
|
||||
IItemConvertible,
|
||||
ICalculableSource<ICalculableWeapon>,
|
||||
ICultivationItemsAccess
|
||||
internal sealed partial class Weapon
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
public WeaponId Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 突破 Id
|
||||
/// </summary>
|
||||
public PromoteId PromoteId { get; set; }
|
||||
|
||||
public uint Sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 武器类型
|
||||
/// </summary>
|
||||
public WeaponType WeaponType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 等级
|
||||
/// </summary>
|
||||
public QualityType RankLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 图标
|
||||
/// </summary>
|
||||
public string Icon { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 觉醒图标
|
||||
/// </summary>
|
||||
public string AwakenIcon { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 生长曲线
|
||||
/// </summary>
|
||||
public List<WeaponTypeValue> GrowCurves { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 被动信息, 无被动的武器为 <see langword="null"/>
|
||||
/// </summary>
|
||||
public NameDescriptions? Affix { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 养成物品
|
||||
/// </summary>
|
||||
public List<MaterialId> CultivationItems { get; set; } = default!;
|
||||
|
||||
[JsonIgnore]
|
||||
public WeaponCollocationView? CollocationView { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<Material>? CultivationItemsView { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public QualityType Quality
|
||||
{
|
||||
get => RankLevel;
|
||||
}
|
||||
|
||||
internal uint MaxLevel { get => GetMaxLevelByQuality(Quality); }
|
||||
|
||||
public static uint GetMaxLevelByQuality(QualityType quality)
|
||||
{
|
||||
return quality >= QualityType.QUALITY_BLUE ? 90U : 70U;
|
||||
}
|
||||
|
||||
public ICalculableWeapon ToCalculable()
|
||||
{
|
||||
return CalculableWeapon.From(this);
|
||||
}
|
||||
|
||||
public Model.Item ToItem()
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Quality = RankLevel,
|
||||
};
|
||||
}
|
||||
|
||||
public StatisticsItem ToStatisticsItem(int count)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Quality = RankLevel,
|
||||
Count = count,
|
||||
};
|
||||
}
|
||||
|
||||
public SummaryItem ToSummaryItem(int lastPull, in DateTimeOffset time, bool isUp)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Name = Name,
|
||||
Icon = EquipIconConverter.IconNameToUri(Icon),
|
||||
Badge = WeaponTypeIconConverter.WeaponTypeToIconUri(WeaponType),
|
||||
Time = time,
|
||||
Quality = RankLevel,
|
||||
LastPull = lastPull,
|
||||
IsUp = isUp,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
<Identity
|
||||
Name="60568DGPStudio.SnapHutao"
|
||||
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
|
||||
Version="1.10.3.0" />
|
||||
Version="1.10.2.0" />
|
||||
|
||||
<Properties>
|
||||
<DisplayName>Snap Hutao</DisplayName>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<Identity
|
||||
Name="60568DGPStudio.SnapHutaoDev"
|
||||
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
|
||||
Version="1.10.3.0" />
|
||||
Version="1.10.2.0" />
|
||||
|
||||
<Properties>
|
||||
<DisplayName>Snap Hutao Dev</DisplayName>
|
||||
|
||||
@@ -2996,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>Document</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>Haven't logged in</value>
|
||||
</data>
|
||||
|
||||
@@ -2996,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>文档</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>尚未登录</value>
|
||||
</data>
|
||||
|
||||
@@ -2996,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>Dokumen</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>Tidak masuk</value>
|
||||
</data>
|
||||
|
||||
@@ -2996,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>ドキュメント</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>ログインしていません</value>
|
||||
</data>
|
||||
|
||||
@@ -2996,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>문서</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>尚未登录</value>
|
||||
</data>
|
||||
|
||||
@@ -2996,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>Documentação</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>Sem login</value>
|
||||
</data>
|
||||
|
||||
@@ -552,10 +552,10 @@
|
||||
<value>精炼 {0} 阶</value>
|
||||
</data>
|
||||
<data name="MustSelectUserAndUid" xml:space="preserve">
|
||||
<value>必须登录 米游社 / HoYoLAB 并选择一个用户与角色</value>
|
||||
<value>必须登录 米游社/HoYoLAB 并选择一个用户与角色</value>
|
||||
</data>
|
||||
<data name="ServerGachaLogServiceDeleteEntrySucceed" xml:space="preserve">
|
||||
<value>删除了 UID:{0} 的 {1} 条祈愿记录</value>
|
||||
<value>删除了 Uid:{0} 的 {1} 条祈愿记录</value>
|
||||
</data>
|
||||
<data name="ServerGachaLogServiceInsufficientRecordSlot" xml:space="preserve">
|
||||
<value>胡桃云保存的祈愿记录存档数已达当前账号上限</value>
|
||||
@@ -570,7 +570,7 @@
|
||||
<value>数据异常,无法保存至云端,请勿跨账号上传或尝试删除云端数据后重试</value>
|
||||
</data>
|
||||
<data name="ServerGachaLogServiceUploadEntrySucceed" xml:space="preserve">
|
||||
<value>上传了 UID:{0} 的 {1} 条祈愿记录,存储了 {2} 条</value>
|
||||
<value>上传了 Uid:{0} 的 {1} 条祈愿记录,存储了 {2} 条</value>
|
||||
</data>
|
||||
<data name="ServerPassportLoginRequired" xml:space="preserve">
|
||||
<value>请先登录或注册胡桃账号</value>
|
||||
@@ -621,7 +621,7 @@
|
||||
<value>验证请求过快,请 1 分钟后再试</value>
|
||||
</data>
|
||||
<data name="ServerRecordBannedUid" xml:space="preserve">
|
||||
<value>上传深渊记录失败,当前 UID 已被胡桃数据库封禁</value>
|
||||
<value>上传深渊记录失败,当前 Uid 已被胡桃数据库封禁</value>
|
||||
</data>
|
||||
<data name="ServerRecordComputingStatistics" xml:space="preserve">
|
||||
<value>上传深渊记录失败,正在计算统计数据</value>
|
||||
@@ -636,13 +636,13 @@
|
||||
<value>上传深渊记录失败,存在无效的数据</value>
|
||||
</data>
|
||||
<data name="ServerRecordInvalidUid" xml:space="preserve">
|
||||
<value>无效的 UID</value>
|
||||
<value>无效的 Uid</value>
|
||||
</data>
|
||||
<data name="ServerRecordNotCurrentSchedule" xml:space="preserve">
|
||||
<value>上传深渊记录失败,不是本期数据</value>
|
||||
</data>
|
||||
<data name="ServerRecordPreviousRequestNotCompleted" xml:space="preserve">
|
||||
<value>上传深渊记录失败,当前 UID 的记录仍在处理中,请勿重复操作</value>
|
||||
<value>上传深渊记录失败,当前 Uid 的记录仍在处理中,请勿重复操作</value>
|
||||
</data>
|
||||
<data name="ServerRecordUploadSuccessAndGachaLogServiceTimeExtended" xml:space="preserve">
|
||||
<value>上传深渊记录成功,获赠祈愿记录上传服务时长</value>
|
||||
@@ -1545,10 +1545,10 @@
|
||||
<value>养成计划添加失败</value>
|
||||
</data>
|
||||
<data name="ViewModelCultivationBatchAddCompletedFormat" xml:space="preserve">
|
||||
<value>操作完成:添加 / 更新:{0} 个,跳过 {1} 个</value>
|
||||
<value>操作完成:添加/更新:{0} 个,跳过 {1} 个</value>
|
||||
</data>
|
||||
<data name="ViewModelCultivationBatchAddIncompletedFormat" xml:space="preserve">
|
||||
<value>操作未全部完成:添加 / 更新:{0} 个,跳过 {1} 个</value>
|
||||
<value>操作未全部完成:添加/更新:{0} 个,跳过 {1} 个</value>
|
||||
</data>
|
||||
<data name="ViewModelCultivationEntryAddSuccess" xml:space="preserve">
|
||||
<value>已成功添加至当前养成计划</value>
|
||||
@@ -1568,9 +1568,6 @@
|
||||
<data name="ViewModelCultivationProjectInvalidName" xml:space="preserve">
|
||||
<value>不能添加名称无效的计划</value>
|
||||
</data>
|
||||
<data name="ViewModelCultivationRefreshInventoryProgress" xml:space="preserve">
|
||||
<value>正在同步背包物品</value>
|
||||
</data>
|
||||
<data name="ViewModelCultivationRemoveProjectContent" xml:space="preserve">
|
||||
<value>此操作不可逆,此计划的养成物品与背包材料将会丢失</value>
|
||||
</data>
|
||||
@@ -1928,9 +1925,6 @@
|
||||
<data name="ViewPageCultivationNavigateAction" xml:space="preserve">
|
||||
<value>前往</value>
|
||||
</data>
|
||||
<data name="ViewPageCultivationRefreshInventory" xml:space="preserve">
|
||||
<value>同步背包物品</value>
|
||||
</data>
|
||||
<data name="ViewPageCultivationRemoveEntry" xml:space="preserve">
|
||||
<value>删除清单</value>
|
||||
</data>
|
||||
@@ -2073,10 +2067,10 @@
|
||||
<value>前往爱发电购买相关服务</value>
|
||||
</data>
|
||||
<data name="ViewPageGachaLogHutaoCloudAfdianPurchaseHeader" xml:space="preserve">
|
||||
<value>购买 / 续费云服务</value>
|
||||
<value>购买/续费云服务</value>
|
||||
</data>
|
||||
<data name="ViewPageGachaLogHutaoCloudDelete" xml:space="preserve">
|
||||
<value>删除此 UID 的云端存档</value>
|
||||
<value>删除此 Uid 的云端存档</value>
|
||||
</data>
|
||||
<data name="ViewPageGachaLogHutaoCloudDeveloperHint" xml:space="preserve">
|
||||
<value>开发者账号无视服务到期时间</value>
|
||||
@@ -2085,7 +2079,7 @@
|
||||
<value>胡桃云服务时长不足</value>
|
||||
</data>
|
||||
<data name="ViewPageGachaLogHutaoCloudRetrieve" xml:space="preserve">
|
||||
<value>下载此 UID 的云端存档</value>
|
||||
<value>下载此 Uid 的云端存档</value>
|
||||
</data>
|
||||
<data name="ViewPageGachaLogHutaoCloudSpiralAbyssActivityDescription" xml:space="preserve">
|
||||
<value>每期深渊首次上传可免费获得 3 天时长</value>
|
||||
@@ -2412,7 +2406,7 @@
|
||||
<value>重命名</value>
|
||||
</data>
|
||||
<data name="ViewPageLaunchGameSwitchSchemeDescription" xml:space="preserve">
|
||||
<value>切换游戏服务器(国服 / 渠道服 / 国际服)</value>
|
||||
<value>切换游戏服务器(国服/渠道服/国际服)</value>
|
||||
</data>
|
||||
<data name="ViewPageLaunchGameSwitchSchemeHeader" xml:space="preserve">
|
||||
<value>服务器</value>
|
||||
@@ -2421,7 +2415,7 @@
|
||||
<value>版本更新前需要提前转换至与启动器匹配的服务器</value>
|
||||
</data>
|
||||
<data name="ViewPageLaunchGameUnlockFpsDescription" xml:space="preserve">
|
||||
<value>请在游戏内关闭「垂直同步」选项,需要高性能的显卡以支持更高的帧率</value>
|
||||
<value>请在游戏内关闭垂直同步选项,需要高性能的显卡以支持更高的帧率</value>
|
||||
</data>
|
||||
<data name="ViewPageLaunchGameUnlockFpsHeader" xml:space="preserve">
|
||||
<value>解锁帧率限制</value>
|
||||
@@ -2439,7 +2433,7 @@
|
||||
<value>Windows HDR</value>
|
||||
</data>
|
||||
<data name="ViewPageLoginHoyoverseUserHint" xml:space="preserve">
|
||||
<value>请输入你的 HoYoLab UID</value>
|
||||
<value>请输入你的 HoYoLab Uid</value>
|
||||
</data>
|
||||
<data name="ViewPageLoginMihoyoUserDescription" xml:space="preserve">
|
||||
<value>你正在通过由我们提供的内嵌网页视图登录 米哈游通行证,我们会在你点击 我已登录 按钮后,读取你的 Cookie 信息,由此视图发起的网络通信只发生于你的计算机与米哈游服务器之间</value>
|
||||
@@ -2517,7 +2511,7 @@
|
||||
<value>除非开发人员明确要求你这么做,否则不应尝试执行下方的操作!</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingDataFolderDescription" xml:space="preserve">
|
||||
<value>用户数据 / 元数据 在此处存放</value>
|
||||
<value>用户数据/元数据 在此处存放</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingDataFolderHeader" xml:space="preserve">
|
||||
<value>数据 文件夹</value>
|
||||
@@ -2595,7 +2589,7 @@
|
||||
<value>选择想要获取公告的游戏服务器</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingHomeAnnouncementRegionHeader" xml:space="preserve">
|
||||
<value>游戏公告所属服务器</value>
|
||||
<value>公告所属服务器</value>
|
||||
</data>
|
||||
<data name="ViewpageSettingHomeCardDescription" xml:space="preserve">
|
||||
<value>管理主页仪表板中的卡片</value>
|
||||
@@ -2652,7 +2646,7 @@
|
||||
<value>您可以无限制的使用任何测试功能</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingHutaoPassportMaintainerHeader" xml:space="preserve">
|
||||
<value>胡桃开发 / 运维</value>
|
||||
<value>胡桃开发/运维</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingHutaoPassportRedeemCodeDescription" xml:space="preserve">
|
||||
<value>我们有时会向某些用户赠送胡桃云兑换码</value>
|
||||
@@ -2709,7 +2703,7 @@
|
||||
<value>重置图片资源</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingsAdvancedOptionsLaunchUnlockFpsDescription" xml:space="preserve">
|
||||
<value>在「启动游戏-进程」选项卡加入「解锁帧率限制」选项</value>
|
||||
<value>在启动游戏页面的进程部分加入解锁帧率限制选项</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingsAdvancedOptionsLaunchUnlockFpsHeader" xml:space="preserve">
|
||||
<value>启动游戏-解锁帧率限制</value>
|
||||
@@ -2757,7 +2751,7 @@
|
||||
<value>贡献翻译</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingUnobtainedWishItemVisibleDescription" xml:space="preserve">
|
||||
<value>在「祈愿记录-角色」与「祈愿记录-武器」中显示未抽取到的祈愿物品</value>
|
||||
<value>在祈愿记录页面角色与武器页签显示未抽取到的祈愿物品</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingUnobtainedWishItemVisibleHeader" xml:space="preserve">
|
||||
<value>未抽取到的祈愿物品</value>
|
||||
@@ -3002,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>文档</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>尚未登录</value>
|
||||
</data>
|
||||
|
||||
@@ -2996,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>Документация</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>Вы не вошли в приложение</value>
|
||||
</data>
|
||||
|
||||
@@ -2996,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>文档</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>尚未登录</value>
|
||||
</data>
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
<value>胡桃 Dev {0}</value>
|
||||
</data>
|
||||
<data name="AppElevatedDevNameAndVersion" xml:space="preserve">
|
||||
<value>胡桃 Dev {0} [系統管理員]</value>
|
||||
<value>胡桃Dev {0} [系統管理员]</value>
|
||||
</data>
|
||||
<data name="AppElevatedNameAndVersion" xml:space="preserve">
|
||||
<value>胡桃 {0} [系統管理員]</value>
|
||||
@@ -166,7 +166,7 @@
|
||||
<value>數據庫已損壞:{0}</value>
|
||||
</data>
|
||||
<data name="CoreExceptionServiceUserdataCorruptedMessage" xml:space="preserve">
|
||||
<value>用戶數據已損壞:{0}</value>
|
||||
<value>用户數據已損壞:{0}</value>
|
||||
</data>
|
||||
<data name="CoreIOPickerExtensionPickerExceptionInfoBarMessage" xml:space="preserve">
|
||||
<value>請勿在系統管理員模式下使用此功能 {0}</value>
|
||||
@@ -274,13 +274,13 @@
|
||||
<value>上場 {0} 次</value>
|
||||
</data>
|
||||
<data name="ModelBindingLaunchGameLaunchSchemeBilibili" xml:space="preserve">
|
||||
<value>渠道服</value>
|
||||
<value>渠道伺服器</value>
|
||||
</data>
|
||||
<data name="ModelBindingLaunchGameLaunchSchemeChinese" xml:space="preserve">
|
||||
<value>官方服</value>
|
||||
<value>官方伺服器</value>
|
||||
</data>
|
||||
<data name="ModelBindingLaunchGameLaunchSchemeOversea" xml:space="preserve">
|
||||
<value>國際服</value>
|
||||
<value>國際伺服器</value>
|
||||
</data>
|
||||
<data name="ModelBindingUserInitializationFailed" xml:space="preserve">
|
||||
<value>網絡異常</value>
|
||||
@@ -573,7 +573,7 @@
|
||||
<value>上傳了 UID:{0} 的 {1} 筆祈願記錄,儲存了 {2} 筆</value>
|
||||
</data>
|
||||
<data name="ServerPassportLoginRequired" xml:space="preserve">
|
||||
<value>請先登入或註冊胡桃帳號</value>
|
||||
<value>請先登入或注冊胡桃帳號</value>
|
||||
</data>
|
||||
<data name="ServerPassportLoginSucceed" xml:space="preserve">
|
||||
<value>登入成功</value>
|
||||
@@ -1011,7 +1011,7 @@
|
||||
<value>無法找到遊戲本體路徑,請前往設定修改</value>
|
||||
</data>
|
||||
<data name="ServiceGameRegisteryInteropLongPathsDisabled" xml:space="preserve">
|
||||
<value>未開啟長路徑功能,無法設定登錄檔鍵值</value>
|
||||
<value>未開啟長路徑功能,無法設定註冊表鍵值</value>
|
||||
</data>
|
||||
<data name="ServiceGameSetMultiChannelConfigFileNotFound" xml:space="preserve">
|
||||
<value>無法讀取遊戲設定檔 {0},可能是檔案不存在</value>
|
||||
@@ -1878,7 +1878,7 @@
|
||||
<value>同步角色天賦信息</value>
|
||||
</data>
|
||||
<data name="ViewPageAvatarPropertyRefreshFromHoyolabGameRecord" xml:space="preserve">
|
||||
<value>從 HoYoLAB - 戰績同步</value>
|
||||
<value>從 HoYoLAB 戰績同步</value>
|
||||
</data>
|
||||
<data name="ViewPageAvatarPropertyRefreshFromHoyolabGameRecordDescription" xml:space="preserve">
|
||||
<value>同步角色天賦外的大部分信息</value>
|
||||
@@ -2064,7 +2064,7 @@
|
||||
<value>胡桃雲</value>
|
||||
</data>
|
||||
<data name="ViewPageGachaLogHutaoCloudAfdianPurchaseDescription" xml:space="preserve">
|
||||
<value>前往爱发电購買相關服務</value>
|
||||
<value>前往愛發電購買相關服務</value>
|
||||
</data>
|
||||
<data name="ViewPageGachaLogHutaoCloudAfdianPurchaseHeader" xml:space="preserve">
|
||||
<value>購買/續費雲服務</value>
|
||||
@@ -2436,13 +2436,13 @@
|
||||
<value>請輸入您的 HoYoLAB UID</value>
|
||||
</data>
|
||||
<data name="ViewPageLoginMihoyoUserDescription" xml:space="preserve">
|
||||
<value>你正在通過由我們提供的內嵌網頁視圖登錄 米哈游通行证,我們會在你點擊 我已登錄 按鈕後,讀取你的 Cookie 信息,由此視圖發起的網絡通信只發生於你的計算機與米哈遊服務器之間</value>
|
||||
<value>你正在通過由我們提供的內嵌網頁視圖登入 miHoYo 通行證賬號,我們會在你點擊 我已登入 按鈕後,讀取你的 Cookie 信息,由此視圖發起的網絡通信只發生於你的計算機與 miHoYo 服務器之間</value>
|
||||
</data>
|
||||
<data name="ViewPageLoginMihoyoUserLoggedInAction" xml:space="preserve">
|
||||
<value>我已登入</value>
|
||||
</data>
|
||||
<data name="ViewPageLoginMihoyoUserTitle" xml:space="preserve">
|
||||
<value>在下方登入米哈游通行证</value>
|
||||
<value>在下方登入 miHoYo 通行證賬號</value>
|
||||
</data>
|
||||
<data name="ViewPageOpenScreenshotFolderAction" xml:space="preserve">
|
||||
<value>開啟截圖檔案夾</value>
|
||||
@@ -2961,7 +2961,7 @@
|
||||
<value>工具</value>
|
||||
</data>
|
||||
<data name="ViewUserCookieOperation" xml:space="preserve">
|
||||
<value>米游社</value>
|
||||
<value>米遊社</value>
|
||||
</data>
|
||||
<data name="ViewUserCookieOperation2" xml:space="preserve">
|
||||
<value>HoYoLAB</value>
|
||||
@@ -2996,9 +2996,6 @@
|
||||
<data name="ViewUserDocumentationHeader" xml:space="preserve">
|
||||
<value>文檔</value>
|
||||
</data>
|
||||
<data name="ViewUserLoginMihoyoUserDisabledTooltip" xml:space="preserve">
|
||||
<value>由于米游社安全策略的相关更改,网页登录暂不可用</value>
|
||||
</data>
|
||||
<data name="ViewUserNoUserHint" xml:space="preserve">
|
||||
<value>尚未登入</value>
|
||||
</data>
|
||||
@@ -3228,10 +3225,10 @@
|
||||
<value>無效的 UID</value>
|
||||
</data>
|
||||
<data name="WebHoyolabRegionCNGF01" xml:space="preserve">
|
||||
<value>陸服 官方服</value>
|
||||
<value>大陸伺服器 官方伺服器</value>
|
||||
</data>
|
||||
<data name="WebHoyolabRegionCNQD01" xml:space="preserve">
|
||||
<value>陸服 渠道服</value>
|
||||
<value>大陸伺服器 渠道伺服器</value>
|
||||
</data>
|
||||
<data name="WebHoyolabRegionOSASIA" xml:space="preserve">
|
||||
<value>國際服 亞服</value>
|
||||
|
||||
@@ -82,10 +82,31 @@ internal abstract partial class DbStoreOptions : ObservableObject
|
||||
return storage.Value;
|
||||
}
|
||||
|
||||
[return: NotNullIfNotNull(nameof(defaultValue))]
|
||||
protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, T defaultValue)
|
||||
[return: NotNull]
|
||||
protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, [DisallowNull] T defaultValue)
|
||||
{
|
||||
return GetOption(ref storage, key, deserializer, () => defaultValue);
|
||||
if (storage is not null)
|
||||
{
|
||||
return storage;
|
||||
}
|
||||
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
{
|
||||
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == key)?.Value;
|
||||
if (value is null)
|
||||
{
|
||||
storage = defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
T targetValue = deserializer(value);
|
||||
ArgumentNullException.ThrowIfNull(targetValue);
|
||||
storage = targetValue;
|
||||
}
|
||||
}
|
||||
|
||||
return storage;
|
||||
}
|
||||
|
||||
protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, Func<T> defaultValueFactory)
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Snap.Hutao.Service;
|
||||
[Injection(InjectAs.Scoped, typeof(IAnnouncementService))]
|
||||
internal sealed partial class AnnouncementService : IAnnouncementService
|
||||
{
|
||||
private const string CacheKey = $"{nameof(AnnouncementService)}.Cache.{nameof(AnnouncementWrapper)}";
|
||||
private static readonly string CacheKey = $"{nameof(AnnouncementService)}.Cache.{nameof(AnnouncementWrapper)}";
|
||||
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
private readonly ITaskContext taskContext;
|
||||
|
||||
@@ -16,6 +16,16 @@ internal sealed partial class CultivationDbService : ICultivationDbService
|
||||
|
||||
public IServiceProvider ServiceProvider { get => serviceProvider; }
|
||||
|
||||
public List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId)
|
||||
{
|
||||
return this.List<InventoryItem>(i => i.ProjectId == projectId);
|
||||
}
|
||||
|
||||
public ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default)
|
||||
{
|
||||
return this.ListAsync<InventoryItem>(i => i.ProjectId == projectId, token);
|
||||
}
|
||||
|
||||
public ValueTask<List<CultivateEntry>> GetCultivateEntryListByProjectIdAsync(Guid projectId, CancellationToken token = default)
|
||||
{
|
||||
return this.ListAsync<CultivateEntry>(e => e.ProjectId == projectId, token);
|
||||
|
||||
@@ -2,14 +2,15 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.Database;
|
||||
using Snap.Hutao.Model;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Entity.Primitive;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
using Snap.Hutao.Service.Inventory;
|
||||
using Snap.Hutao.Service.Metadata.ContextAbstraction;
|
||||
using Snap.Hutao.ViewModel.Cultivation;
|
||||
using System.Collections.ObjectModel;
|
||||
using CalculateItem = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Item;
|
||||
using ModelItem = Snap.Hutao.Model.Item;
|
||||
|
||||
namespace Snap.Hutao.Service.Cultivation;
|
||||
|
||||
@@ -50,6 +51,22 @@ internal sealed partial class CultivationService : ICultivationService
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand)
|
||||
{
|
||||
Guid projectId = cultivateProject.InnerId;
|
||||
List<InventoryItem> entities = cultivationDbService.GetInventoryItemListByProjectId(projectId);
|
||||
|
||||
List<InventoryItemView> results = [];
|
||||
foreach (Material meta in context.EnumerateInventoryMaterial())
|
||||
{
|
||||
InventoryItem entity = entities.SingleOrDefault(e => e.ItemId == meta.Id) ?? InventoryItem.From(projectId, meta.Id);
|
||||
results.Add(new(entity, meta, saveCommand));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async ValueTask<ObservableCollection<CultivateEntryView>> GetCultivateEntriesAsync(CultivateProject cultivateProject, ICultivationMetadataContext context)
|
||||
{
|
||||
@@ -69,7 +86,7 @@ internal sealed partial class CultivationService : ICultivationService
|
||||
entryItems.Add(new(cultivateItem, context.GetMaterial(cultivateItem.ItemId)));
|
||||
}
|
||||
|
||||
ModelItem item = entry.Type switch
|
||||
Item item = entry.Type switch
|
||||
{
|
||||
CultivateType.AvatarAndSkill => context.GetAvatar(entry.Id).ToItem(),
|
||||
CultivateType.Weapon => context.GetWeapon(entry.Id).ToItem(),
|
||||
@@ -113,7 +130,7 @@ internal sealed partial class CultivationService : ICultivationService
|
||||
}
|
||||
}
|
||||
|
||||
foreach (InventoryItem inventoryItem in await inventoryDbService.GetInventoryItemListByProjectIdAsync(projectId, token).ConfigureAwait(false))
|
||||
foreach (InventoryItem inventoryItem in await cultivationDbService.GetInventoryItemListByProjectIdAsync(projectId, token).ConfigureAwait(false))
|
||||
{
|
||||
if (resultItems.SingleOrDefault(i => i.Inner.Id == inventoryItem.ItemId) is { } existedItem)
|
||||
{
|
||||
@@ -130,6 +147,12 @@ internal sealed partial class CultivationService : ICultivationService
|
||||
await cultivationDbService.RemoveCultivateEntryByIdAsync(entryId).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SaveInventoryItem(InventoryItemView item)
|
||||
{
|
||||
inventoryDbService.UpdateInventoryItem(item.Entity);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SaveCultivateItem(CultivateItemView item)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,8 @@ using System.Collections.ObjectModel;
|
||||
|
||||
namespace Snap.Hutao.Service.Cultivation;
|
||||
|
||||
internal interface ICultivationDbService : IAppDbService<CultivateEntryLevelInformation>,
|
||||
internal interface ICultivationDbService : IAppDbService<InventoryItem>,
|
||||
IAppDbService<CultivateEntryLevelInformation>,
|
||||
IAppDbService<CultivateProject>,
|
||||
IAppDbService<CultivateEntry>,
|
||||
IAppDbService<CultivateItem>
|
||||
@@ -28,6 +29,10 @@ internal interface ICultivationDbService : IAppDbService<CultivateEntryLevelInfo
|
||||
|
||||
ObservableCollection<CultivateProject> GetCultivateProjectCollection();
|
||||
|
||||
List<InventoryItem> GetInventoryItemListByProjectId(Guid projectId);
|
||||
|
||||
ValueTask<List<InventoryItem>> GetInventoryItemListByProjectIdAsync(Guid projectId, CancellationToken token = default);
|
||||
|
||||
ValueTask AddCultivateEntryAsync(CultivateEntry entry, CancellationToken token = default);
|
||||
|
||||
ValueTask AddCultivateItemRangeAsync(IEnumerable<CultivateItem> toAdd, CancellationToken token = default);
|
||||
|
||||
@@ -27,6 +27,8 @@ internal interface ICultivationService
|
||||
|
||||
ValueTask<ObservableCollection<CultivateEntryView>> GetCultivateEntriesAsync(CultivateProject cultivateProject, ICultivationMetadataContext context);
|
||||
|
||||
List<InventoryItemView> GetInventoryItemViews(CultivateProject cultivateProject, ICultivationMetadataContext context, ICommand saveCommand);
|
||||
|
||||
ValueTask<ObservableCollection<StatisticsCultivateItem>> GetStatisticsCultivateItemCollectionAsync(
|
||||
CultivateProject cultivateProject, ICultivationMetadataContext context, CancellationToken token);
|
||||
|
||||
@@ -52,6 +54,12 @@ internal interface ICultivationService
|
||||
/// <param name="item">养成物品</param>
|
||||
void SaveCultivateItem(CultivateItemView item);
|
||||
|
||||
/// <summary>
|
||||
/// 保存单个物品
|
||||
/// </summary>
|
||||
/// <param name="item">物品</param>
|
||||
void SaveInventoryItem(InventoryItemView item);
|
||||
|
||||
/// <summary>
|
||||
/// 异步尝试添加新的项目
|
||||
/// </summary>
|
||||
|
||||
@@ -48,7 +48,7 @@ internal sealed partial class DailyNoteOptions : DbStoreOptions
|
||||
{
|
||||
quartzService.UpdateJobAsync(JobIdentity.DailyNoteGroupName, JobIdentity.DailyNoteRefreshTriggerName, builder =>
|
||||
{
|
||||
return builder.WithSimpleSchedule(sb => sb.WithIntervalInSeconds(SelectedRefreshTime.Value).RepeatForever());
|
||||
return builder.WithSimpleSchedule(sb => sb.WithIntervalInMinutes(SelectedRefreshTime.Value).RepeatForever());
|
||||
}).SafeForget();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,6 @@ internal sealed partial class DailyNoteWebhookOperation
|
||||
.SetHeader("x-uid", $"{playerUid}")
|
||||
.PostJson(dailyNote);
|
||||
|
||||
await builder.SendAsync(httpClient, logger, token).ConfigureAwait(false);
|
||||
await builder.TryCatchSendAsync(httpClient, logger, token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ internal static class GachaStatisticsExtension
|
||||
/// <param name="dict">计数器</param>
|
||||
/// <returns>统计物品列表</returns>
|
||||
public static List<StatisticsItem> ToStatisticsList<TItem>(this Dictionary<TItem, int> dict)
|
||||
where TItem : IStatisticsItemConvertible
|
||||
where TItem : IStatisticsItemSource
|
||||
{
|
||||
IOrderedEnumerable<StatisticsItem> result = dict
|
||||
.Select(kvp => kvp.Key.ToStatisticsItem(kvp.Value))
|
||||
|
||||
@@ -27,7 +27,7 @@ internal sealed partial class GachaStatisticsSlimFactory : IGachaStatisticsSlimF
|
||||
return CreateCore(context, items, uid);
|
||||
}
|
||||
|
||||
private static void Track(INameQualityAccess nameQuality, ref int orangeTracker, ref int purpleTracker)
|
||||
private static void Track(INameQuality nameQuality, ref int orangeTracker, ref int purpleTracker)
|
||||
{
|
||||
switch (nameQuality.Quality)
|
||||
{
|
||||
@@ -69,7 +69,7 @@ internal sealed partial class GachaStatisticsSlimFactory : IGachaStatisticsSlimF
|
||||
// O(n) operation
|
||||
foreach (ref readonly GachaItem item in CollectionsMarshal.AsSpan(items))
|
||||
{
|
||||
INameQualityAccess nameQuality = context.GetNameQualityByItemId(item.ItemId);
|
||||
INameQuality nameQuality = context.GetNameQualityByItemId(item.ItemId);
|
||||
switch (item.QueryType)
|
||||
{
|
||||
case GachaType.Standard:
|
||||
|
||||
@@ -16,11 +16,11 @@ internal sealed class HistoryWishBuilder
|
||||
{
|
||||
private readonly GachaEvent gachaEvent;
|
||||
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> orangeUpCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> purpleUpCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> orangeCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> purpleCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemConvertible, int> blueCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemSource, int> orangeUpCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemSource, int> purpleUpCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemSource, int> orangeCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemSource, int> purpleCounter = [];
|
||||
private readonly Dictionary<IStatisticsItemSource, int> blueCounter = [];
|
||||
|
||||
private int totalCountTracker;
|
||||
|
||||
@@ -37,18 +37,18 @@ internal sealed class HistoryWishBuilder
|
||||
switch (ConfigType)
|
||||
{
|
||||
case GachaType.ActivityAvatar or GachaType.SpecialActivityAvatar:
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemConvertible)a, a => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemConvertible)a, a => 0);
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemSource)a, a => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemSource)a, a => 0);
|
||||
break;
|
||||
case GachaType.ActivityWeapon:
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemConvertible)w, w => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemConvertible)w, w => 0);
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemSource)w, w => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdWeaponMap[id]).ToDictionary(w => (IStatisticsItemSource)w, w => 0);
|
||||
break;
|
||||
case GachaType.ActivityCity:
|
||||
|
||||
// Avatars are less than weapons, so we try to get the value from avatar map first
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => (IStatisticsItemConvertible?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => (IStatisticsItemConvertible?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
|
||||
orangeUpCounter = gachaEvent.UpOrangeList.Select(id => (IStatisticsItemSource?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
|
||||
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => (IStatisticsItemSource?)context.IdAvatarMap.GetValueOrDefault(id) ?? context.IdWeaponMap[id]).ToDictionary(c => c, c => 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ internal sealed class HistoryWishBuilder
|
||||
/// </summary>
|
||||
/// <param name="item">物品</param>
|
||||
/// <returns>是否为Up物品</returns>
|
||||
public bool IncreaseOrange(IStatisticsItemConvertible item)
|
||||
public bool IncreaseOrange(IStatisticsItemSource item)
|
||||
{
|
||||
orangeCounter.IncreaseOne(item);
|
||||
++totalCountTracker;
|
||||
@@ -86,7 +86,7 @@ internal sealed class HistoryWishBuilder
|
||||
/// 计数四星物品
|
||||
/// </summary>
|
||||
/// <param name="item">物品</param>
|
||||
public void IncreasePurple(IStatisticsItemConvertible item)
|
||||
public void IncreasePurple(IStatisticsItemSource item)
|
||||
{
|
||||
purpleUpCounter.TryIncreaseOne(item);
|
||||
purpleCounter.IncreaseOne(item);
|
||||
@@ -97,7 +97,7 @@ internal sealed class HistoryWishBuilder
|
||||
/// 计数三星武器
|
||||
/// </summary>
|
||||
/// <param name="item">武器</param>
|
||||
public void IncreaseBlue(IStatisticsItemConvertible item)
|
||||
public void IncreaseBlue(IStatisticsItemSource item)
|
||||
{
|
||||
blueCounter.IncreaseOne(item);
|
||||
++totalCountTracker;
|
||||
|
||||
@@ -55,7 +55,7 @@ internal sealed class HutaoStatisticsFactory
|
||||
|
||||
foreach (ref readonly ItemCount item in CollectionsMarshal.AsSpan(items))
|
||||
{
|
||||
IStatisticsItemConvertible source = item.Item.StringLength() switch
|
||||
IStatisticsItemSource source = item.Item.StringLength() switch
|
||||
{
|
||||
8U => context.GetAvatar(item.Item),
|
||||
5U => context.GetWeapon(item.Item),
|
||||
|
||||
@@ -44,7 +44,7 @@ internal sealed class TypedWishSummaryBuilder
|
||||
/// <param name="item">祈愿物品</param>
|
||||
/// <param name="source">对应武器</param>
|
||||
/// <param name="isUp">是否为Up物品</param>
|
||||
public void Track(GachaItem item, ISummaryItemConvertible source, bool isUp)
|
||||
public void Track(GachaItem item, ISummaryItemSource source, bool isUp)
|
||||
{
|
||||
if (!context.TypeEvaluator(item.GachaType))
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ internal sealed class GachaLogServiceMetadataContext : IMetadataContext,
|
||||
return result;
|
||||
}
|
||||
|
||||
public INameQualityAccess GetNameQualityByItemId(uint id)
|
||||
public INameQuality GetNameQualityByItemId(uint id)
|
||||
{
|
||||
uint place = id.StringLength();
|
||||
return place switch
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
using Snap.Hutao.Win32.System.Com;
|
||||
using Windows.Graphics.DirectX.Direct3D11;
|
||||
using WinRT;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
using static Snap.Hutao.Win32.D3d11;
|
||||
using static Snap.Hutao.Win32.Dxgi;
|
||||
using static Snap.Hutao.Win32.Macros;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal static class DirectX
|
||||
{
|
||||
public static unsafe bool TryCreateDXGIFactory(uint flags, out IDXGIFactory6* factory, out HRESULT hr)
|
||||
{
|
||||
hr = CreateDXGIFactory2(flags, in IDXGIFactory6.IID, out factory);
|
||||
return SUCCEEDED(hr);
|
||||
}
|
||||
|
||||
public static unsafe bool TryGetHighPerformanceAdapter(IDXGIFactory6* factory, out IDXGIAdapter* adapter, out HRESULT hr)
|
||||
{
|
||||
hr = factory->EnumAdapterByGpuPreference(0U, DXGI_GPU_PREFERENCE.DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, in IDXGIAdapter.IID, out adapter);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(adapter);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static unsafe bool TryCreateD3D11Device(IDXGIAdapter* adapter, D3D11_CREATE_DEVICE_FLAG flags, out ID3D11Device* device, out HRESULT hr)
|
||||
{
|
||||
hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_HARDWARE, default, flags, [], D3D11_SDK_VERSION, out device, out _, out _);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(device);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static unsafe bool TryAsDXGIDevice(ID3D11Device* device, out IDXGIDevice* dxgiDevice, out HRESULT hr)
|
||||
{
|
||||
hr = IUnknownMarshal.QueryInterface(device, in IDXGIDevice.IID, out dxgiDevice);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(dxgiDevice);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static unsafe bool TryCreateDirect3D11Device(IDXGIDevice* dxgiDevice, [NotNullWhen(true)] out IDirect3DDevice? direct3DDevice, out HRESULT hr)
|
||||
{
|
||||
hr = CreateDirect3D11DeviceFromDXGIDevice(dxgiDevice, out Win32.System.WinRT.IInspectable* inspectable);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
direct3DDevice = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
direct3DDevice = IInspectable.FromAbi((nint)inspectable).ObjRef.AsInterface<IDirect3DDevice>();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static unsafe bool TryCreateSwapChainForComposition(IDXGIFactory6* factory, ID3D11Device* device, ref readonly DXGI_SWAP_CHAIN_DESC1 desc, out IDXGISwapChain1* swapChain, out HRESULT hr)
|
||||
{
|
||||
hr = factory->CreateSwapChainForComposition((IUnknown*)device, in desc, default, out swapChain);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -4,106 +4,44 @@
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
using Snap.Hutao.Win32.Graphics.Dwm;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi.Common;
|
||||
using Snap.Hutao.Win32.Graphics.Gdi;
|
||||
using Snap.Hutao.Win32.System.Com;
|
||||
using Snap.Hutao.Win32.System.WinRT.Graphics.Capture;
|
||||
using Windows.Graphics.Capture;
|
||||
using Windows.Graphics.DirectX;
|
||||
using Windows.Graphics.DirectX.Direct3D11;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
using static Snap.Hutao.Win32.DwmApi;
|
||||
using static Snap.Hutao.Win32.Gdi32;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal struct GameScreenCaptureContext : IDisposable
|
||||
internal readonly struct GameScreenCaptureContext
|
||||
{
|
||||
public readonly GraphicsCaptureItem Item;
|
||||
public readonly bool PreviewEnabled;
|
||||
|
||||
private const uint CreateDXGIFactoryFlag =
|
||||
#if DEBUG
|
||||
DXGI_CREATE_FACTORY_DEBUG;
|
||||
#else
|
||||
0;
|
||||
#endif
|
||||
|
||||
private const D3D11_CREATE_DEVICE_FLAG D3d11CreateDeviceFlag =
|
||||
D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_BGRA_SUPPORT
|
||||
#if DEBUG
|
||||
| D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_DEBUG
|
||||
#endif
|
||||
;
|
||||
|
||||
private readonly IDirect3DDevice direct3DDevice;
|
||||
private readonly HWND hwnd;
|
||||
|
||||
private unsafe IDXGIFactory6* factory;
|
||||
private unsafe IDXGIAdapter* adapter;
|
||||
private unsafe ID3D11Device* d3d11Device;
|
||||
private unsafe IDXGIDevice* dxgiDevice;
|
||||
private IDirect3DDevice? direct3DDevice;
|
||||
private unsafe IDXGISwapChain1* swapChain;
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
private unsafe GameScreenCaptureContext(HWND hwnd, bool preview)
|
||||
public GameScreenCaptureContext(IDirect3DDevice direct3DDevice, HWND hwnd)
|
||||
{
|
||||
this.direct3DDevice = direct3DDevice;
|
||||
this.hwnd = hwnd;
|
||||
|
||||
GraphicsCaptureItem.As<IGraphicsCaptureItemInterop>().CreateForWindow(hwnd, out Item);
|
||||
|
||||
PreviewEnabled = preview;
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static unsafe GameScreenCaptureContextCreationResult Create(HWND hwnd, bool preview)
|
||||
{
|
||||
GameScreenCaptureContext context = new(hwnd, preview);
|
||||
|
||||
if (!DirectX.TryCreateDXGIFactory(CreateDXGIFactoryFlag, out context.factory, out HRESULT hr))
|
||||
{
|
||||
return new(GameScreenCaptureContextCreationResultKind.CreateDxgiFactoryFailed, hr);
|
||||
}
|
||||
|
||||
if (!DirectX.TryGetHighPerformanceAdapter(context.factory, out context.adapter, out hr))
|
||||
{
|
||||
return new(GameScreenCaptureContextCreationResultKind.EnumAdapterByGpuPreferenceFailed, hr);
|
||||
}
|
||||
|
||||
if (!DirectX.TryCreateD3D11Device(default, D3d11CreateDeviceFlag, out context.d3d11Device, out hr))
|
||||
{
|
||||
return new(GameScreenCaptureContextCreationResultKind.D3D11CreateDeviceFailed, hr);
|
||||
}
|
||||
|
||||
if (!DirectX.TryAsDXGIDevice(context.d3d11Device, out context.dxgiDevice, out hr))
|
||||
{
|
||||
return new(GameScreenCaptureContextCreationResultKind.D3D11DeviceQueryDXGIDeviceFailed, hr);
|
||||
}
|
||||
|
||||
if (!DirectX.TryCreateDirect3D11Device(context.dxgiDevice, out context.direct3DDevice, out hr))
|
||||
{
|
||||
return new(GameScreenCaptureContextCreationResultKind.CreateDirect3D11DeviceFromDXGIDeviceFailed, hr);
|
||||
}
|
||||
|
||||
return new GameScreenCaptureContextCreationResult(GameScreenCaptureContextCreationResultKind.Success, context);
|
||||
}
|
||||
|
||||
public Direct3D11CaptureFramePool CreatePool()
|
||||
{
|
||||
(DirectXPixelFormat winrt, DXGI_FORMAT dx) = DeterminePixelFormat(hwnd);
|
||||
CreateOrUpdateDXGISwapChain(dx);
|
||||
return Direct3D11CaptureFramePool.CreateFreeThreaded(direct3DDevice, winrt, 2, Item.Size);
|
||||
return Direct3D11CaptureFramePool.CreateFreeThreaded(direct3DDevice, DeterminePixelFormat(hwnd), 2, Item.Size);
|
||||
}
|
||||
|
||||
public void RecreatePool(Direct3D11CaptureFramePool framePool)
|
||||
{
|
||||
(DirectXPixelFormat winrt, DXGI_FORMAT dx) = DeterminePixelFormat(hwnd);
|
||||
CreateOrUpdateDXGISwapChain(dx);
|
||||
framePool.Recreate(direct3DDevice, winrt, 2, Item.Size);
|
||||
framePool.Recreate(direct3DDevice, DeterminePixelFormat(hwnd), 2, Item.Size);
|
||||
}
|
||||
|
||||
public readonly GraphicsCaptureSession CreateSession(Direct3D11CaptureFramePool framePool)
|
||||
public GraphicsCaptureSession CreateSession(Direct3D11CaptureFramePool framePool)
|
||||
{
|
||||
GraphicsCaptureSession session = framePool.CreateCaptureSession(Item);
|
||||
session.IsCursorCaptureEnabled = false;
|
||||
@@ -111,7 +49,7 @@ internal struct GameScreenCaptureContext : IDisposable
|
||||
return session;
|
||||
}
|
||||
|
||||
public readonly bool TryGetClientBox(uint width, uint height, out D3D11_BOX clientBox)
|
||||
public bool TryGetClientBox(uint width, uint height, out D3D11_BOX clientBox)
|
||||
{
|
||||
clientBox = default;
|
||||
|
||||
@@ -150,39 +88,8 @@ internal struct GameScreenCaptureContext : IDisposable
|
||||
return clientBox.right <= width && clientBox.bottom <= height;
|
||||
}
|
||||
|
||||
public unsafe readonly void AttachPreview(GameScreenCaptureDebugPreviewWindow? window)
|
||||
{
|
||||
if (PreviewEnabled && window is not null)
|
||||
{
|
||||
window.UpdateSwapChain(swapChain);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe readonly void UpdatePreview(GameScreenCaptureDebugPreviewWindow? window, IDirect3DSurface surface)
|
||||
{
|
||||
if (PreviewEnabled && window is not null)
|
||||
{
|
||||
window.UnsafeUpdatePreview(d3d11Device, surface);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe readonly void DetachPreview(GameScreenCaptureDebugPreviewWindow? window)
|
||||
{
|
||||
if (PreviewEnabled && window is not null)
|
||||
{
|
||||
window.UpdateSwapChain(null);
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe readonly void Dispose()
|
||||
{
|
||||
IUnknownMarshal.Release(factory);
|
||||
IUnknownMarshal.Release(swapChain);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
private static (DirectXPixelFormat WinRTFormat, DXGI_FORMAT DXFormat) DeterminePixelFormat(HWND hwnd)
|
||||
private static DirectXPixelFormat DeterminePixelFormat(HWND hwnd)
|
||||
{
|
||||
HDC hdc = GetDC(hwnd);
|
||||
if (hdc != HDC.NULL)
|
||||
@@ -191,31 +98,10 @@ internal struct GameScreenCaptureContext : IDisposable
|
||||
_ = ReleaseDC(hwnd, hdc);
|
||||
if (bitsPerPixel >= 32)
|
||||
{
|
||||
return (DirectXPixelFormat.R16G16B16A16Float, DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_FLOAT);
|
||||
return DirectXPixelFormat.R16G16B16A16Float;
|
||||
}
|
||||
}
|
||||
|
||||
return (DirectXPixelFormat.B8G8R8A8UIntNormalized, DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM);
|
||||
}
|
||||
|
||||
private unsafe void CreateOrUpdateDXGISwapChain(DXGI_FORMAT format)
|
||||
{
|
||||
if (!PreviewEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DXGI_SWAP_CHAIN_DESC1 desc = default;
|
||||
desc.Width = (uint)Item.Size.Width;
|
||||
desc.Height = (uint)Item.Size.Height;
|
||||
desc.Format = format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.BufferUsage = DXGI_USAGE.DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
desc.BufferCount = 2;
|
||||
desc.Scaling = DXGI_SCALING.DXGI_SCALING_STRETCH;
|
||||
desc.SwapEffect = DXGI_SWAP_EFFECT.DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
||||
desc.AlphaMode = DXGI_ALPHA_MODE.DXGI_ALPHA_MODE_PREMULTIPLIED;
|
||||
|
||||
DirectX.TryCreateSwapChainForComposition(factory, d3d11Device, in desc, out swapChain, out HRESULT hr);
|
||||
return DirectXPixelFormat.B8G8R8A8UIntNormalized;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal readonly struct GameScreenCaptureContextCreationResult
|
||||
{
|
||||
public readonly GameScreenCaptureContextCreationResultKind Kind;
|
||||
public readonly HRESULT HResult;
|
||||
public readonly GameScreenCaptureContext Context;
|
||||
|
||||
public GameScreenCaptureContextCreationResult(GameScreenCaptureContextCreationResultKind kind, HRESULT hResult)
|
||||
{
|
||||
Kind = kind;
|
||||
HResult = hResult;
|
||||
}
|
||||
|
||||
public GameScreenCaptureContextCreationResult(GameScreenCaptureContextCreationResultKind kind, GameScreenCaptureContext context)
|
||||
{
|
||||
Kind = kind;
|
||||
Context = context;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal enum GameScreenCaptureContextCreationResultKind
|
||||
{
|
||||
Success,
|
||||
CreateDxgiFactoryFailed,
|
||||
EnumAdapterByGpuPreferenceFailed,
|
||||
D3D11CreateDeviceFailed,
|
||||
D3D11DeviceQueryDXGIDeviceFailed,
|
||||
CreateDirect3D11DeviceFromDXGIDeviceFailed,
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<Window
|
||||
x:Class="Snap.Hutao.Service.Game.Automation.ScreenCapture.GameScreenCaptureDebugPreviewWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="using:Snap.Hutao.Service.Game.Automation.ScreenCapture"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<SwapChainPanel
|
||||
x:Name="Presenter"
|
||||
AllowFocusOnInteraction="False"
|
||||
AllowFocusWhenDisabled="False"/>
|
||||
</Window>
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Windowing;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
using Snap.Hutao.Win32.System.WinRT.Graphics.Capture;
|
||||
using Snap.Hutao.Win32.System.WinRT.Xaml;
|
||||
using Windows.Graphics.DirectX.Direct3D11;
|
||||
using WinRT;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal sealed partial class GameScreenCaptureDebugPreviewWindow : Window
|
||||
{
|
||||
private unsafe IDXGISwapChain1* swapChain1;
|
||||
|
||||
public GameScreenCaptureDebugPreviewWindow()
|
||||
{
|
||||
if (AppWindow.Presenter is OverlappedPresenter presenter)
|
||||
{
|
||||
presenter.IsMaximizable = false;
|
||||
}
|
||||
|
||||
InitializeComponent();
|
||||
this.InitializeController(Ioc.Default);
|
||||
}
|
||||
|
||||
public unsafe void UpdateSwapChain(IDXGISwapChain1* swapChain1)
|
||||
{
|
||||
this.swapChain1 = swapChain1;
|
||||
ISwapChainPanelNative native = Presenter.As<IInspectable>().ObjRef.AsInterface<ISwapChainPanelNative>();
|
||||
native.SetSwapChain((IDXGISwapChain*)swapChain1);
|
||||
}
|
||||
|
||||
public unsafe void UnsafeUpdatePreview(ID3D11Device* device, IDirect3DSurface surface)
|
||||
{
|
||||
IDirect3DDxgiInterfaceAccess access = surface.As<IDirect3DDxgiInterfaceAccess>();
|
||||
swapChain1->GetBuffer(0, in ID3D11Texture2D.IID, out ID3D11Texture2D* buffer);
|
||||
device->GetImmediateContext(out ID3D11DeviceContext* deviceContext);
|
||||
access.GetInterface(in ID3D11Resource.IID, out ID3D11Resource* resource);
|
||||
deviceContext->CopyResource((ID3D11Resource*)buffer, resource);
|
||||
swapChain1->Present(0, default);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,17 @@
|
||||
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
using Snap.Hutao.Win32.System.Com;
|
||||
using Windows.Graphics.Capture;
|
||||
using Windows.Graphics.DirectX.Direct3D11;
|
||||
using WinRT;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
using static Snap.Hutao.Win32.D3d11;
|
||||
using static Snap.Hutao.Win32.Dxgi;
|
||||
using static Snap.Hutao.Win32.Macros;
|
||||
|
||||
namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
@@ -47,34 +55,61 @@ internal sealed partial class GameScreenCaptureService : IGameScreenCaptureServi
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public unsafe bool TryStartCapture(HWND hwnd, bool preview, [NotNullWhen(true)] out GameScreenCaptureSession? session)
|
||||
public unsafe bool TryStartCapture(HWND hwnd, [NotNullWhen(true)] out GameScreenCaptureSession? session)
|
||||
{
|
||||
session = default;
|
||||
|
||||
GameScreenCaptureContextCreationResult result = GameScreenCaptureContext.Create(hwnd, preview);
|
||||
|
||||
switch (result.Kind)
|
||||
HRESULT hr;
|
||||
hr = CreateDXGIFactory2(CreateDXGIFactoryFlag, in IDXGIFactory6.IID, out IDXGIFactory6* factory);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
case GameScreenCaptureContextCreationResultKind.Success:
|
||||
session = new(result.Context, logger);
|
||||
return true;
|
||||
case GameScreenCaptureContextCreationResultKind.CreateDxgiFactoryFailed:
|
||||
logger.LogWarning("CreateDXGIFactory2 failed with code: {Code}", result.HResult);
|
||||
return false;
|
||||
case GameScreenCaptureContextCreationResultKind.EnumAdapterByGpuPreferenceFailed:
|
||||
logger.LogWarning("IDXGIFactory6.EnumAdapterByGpuPreference failed with code: {Code}", result.HResult);
|
||||
return false;
|
||||
case GameScreenCaptureContextCreationResultKind.D3D11CreateDeviceFailed:
|
||||
logger.LogWarning("D3D11CreateDevice failed with code: {Code}", result.HResult);
|
||||
return false;
|
||||
case GameScreenCaptureContextCreationResultKind.D3D11DeviceQueryDXGIDeviceFailed:
|
||||
logger.LogWarning("ID3D11Device.QueryInterface<IDXGIDevice> failed with code: {Code}", result.HResult);
|
||||
return false;
|
||||
case GameScreenCaptureContextCreationResultKind.CreateDirect3D11DeviceFromDXGIDeviceFailed:
|
||||
logger.LogWarning("CreateDirect3D11DeviceFromDXGIDevice failed with code: {Code}", result.HResult);
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
logger.LogWarning("CreateDXGIFactory2 failed with code: {Code}", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(factory);
|
||||
|
||||
hr = factory->EnumAdapterByGpuPreference(0U, DXGI_GPU_PREFERENCE.DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, in IDXGIAdapter.IID, out IDXGIAdapter* adapter);
|
||||
if (hr != HRESULT.DXGI_ERROR_NOT_FOUND)
|
||||
{
|
||||
logger.LogWarning("IDXGIFactory6.EnumAdapterByGpuPreference failed with code: {Code}", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(adapter);
|
||||
|
||||
hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_HARDWARE, default, D3d11CreateDeviceFlag, [], D3D11_SDK_VERSION, out ID3D11Device* pD3D11Device, out _, out _);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
logger.LogWarning("D3D11CreateDevice failed with code: {Code}", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pD3D11Device);
|
||||
|
||||
hr = IUnknownMarshal.QueryInterface(pD3D11Device, in IDXGIDevice.IID, out IDXGIDevice* pDXGIDevice);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
logger.LogWarning("ID3D11Device.QueryInterface<IDXGIDevice> failed with code: {Code}", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pDXGIDevice);
|
||||
|
||||
hr = CreateDirect3D11DeviceFromDXGIDevice(pDXGIDevice, out Win32.System.WinRT.IInspectable* inspectable);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
logger.LogWarning("CreateDirect3D11DeviceFromDXGIDevice failed with code: {Code}", hr);
|
||||
return false;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(inspectable);
|
||||
|
||||
IDirect3DDevice direct3DDevice = IInspectable.FromAbi((nint)inspectable).ObjRef.AsInterface<IDirect3DDevice>();
|
||||
|
||||
GameScreenCaptureContext captureContext = new(direct3DDevice, hwnd);
|
||||
session = new(captureContext, logger);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi.Common;
|
||||
using Snap.Hutao.Win32.System.Com;
|
||||
using Snap.Hutao.Win32.System.WinRT.Graphics.Capture;
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -25,7 +24,6 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
private static readonly Half ByteMaxValue = 255;
|
||||
|
||||
private readonly GameScreenCaptureContext captureContext;
|
||||
private readonly GameScreenCaptureDebugPreviewWindow? previewWindow;
|
||||
private readonly Direct3D11CaptureFramePool framePool;
|
||||
private readonly GraphicsCaptureSession session;
|
||||
private readonly ILogger logger;
|
||||
@@ -37,23 +35,16 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
private bool isDisposed;
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public unsafe GameScreenCaptureSession(GameScreenCaptureContext captureContext, ILogger logger)
|
||||
public GameScreenCaptureSession(GameScreenCaptureContext captureContext, ILogger logger)
|
||||
{
|
||||
this.captureContext = captureContext;
|
||||
this.logger = logger;
|
||||
|
||||
contentSize = captureContext.Item.Size;
|
||||
|
||||
if (captureContext.PreviewEnabled)
|
||||
{
|
||||
previewWindow = new();
|
||||
}
|
||||
|
||||
captureContext.Item.Closed += OnItemClosed;
|
||||
|
||||
framePool = captureContext.CreatePool();
|
||||
captureContext.AttachPreview(previewWindow);
|
||||
|
||||
framePool.FrameArrived += OnFrameArrived;
|
||||
|
||||
session = captureContext.CreateSession(framePool);
|
||||
@@ -85,7 +76,6 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
captureContext.DetachPreview(previewWindow);
|
||||
session.Dispose();
|
||||
framePool.Dispose();
|
||||
isDisposed = true;
|
||||
@@ -121,9 +111,7 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
|
||||
try
|
||||
{
|
||||
captureContext.UpdatePreview(previewWindow, frame.Surface);
|
||||
|
||||
// UnsafeProcessFrameSurface(frame.Surface);
|
||||
UnsafeProcessFrameSurface(frame.Surface);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -147,8 +135,6 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pDXGISurface);
|
||||
|
||||
if (FAILED(pDXGISurface->GetDesc(out DXGI_SURFACE_DESC dxgiSurfaceDesc)))
|
||||
{
|
||||
return;
|
||||
@@ -165,8 +151,6 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pD3D11Device);
|
||||
|
||||
D3D11_TEXTURE2D_DESC d3d11Texture2DDesc = default;
|
||||
d3d11Texture2DDesc.Width = textureWidth;
|
||||
d3d11Texture2DDesc.Height = textureHeight;
|
||||
@@ -182,17 +166,12 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pD3D11Texture2D);
|
||||
|
||||
if (FAILED(access.GetInterface(in ID3D11Resource.IID, out ID3D11Resource* pD3D11Resource)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pD3D11Resource);
|
||||
|
||||
pD3D11Device->GetImmediateContext(out ID3D11DeviceContext* pD3D11DeviceContext);
|
||||
IUnknownMarshal.Release(pD3D11DeviceContext);
|
||||
|
||||
if (boxAvailable)
|
||||
{
|
||||
|
||||
@@ -9,5 +9,5 @@ internal interface IGameScreenCaptureService
|
||||
{
|
||||
bool IsSupported();
|
||||
|
||||
bool TryStartCapture(HWND hwnd, bool preview, [NotNullWhen(true)] out GameScreenCaptureSession? session);
|
||||
bool TryStartCapture(HWND hwnd, [NotNullWhen(true)] out GameScreenCaptureSession? session);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Service.Game.Scheme;
|
||||
using System.IO;
|
||||
|
||||
namespace Snap.Hutao.Service.Game;
|
||||
@@ -39,6 +38,4 @@ internal sealed class GameFileSystem
|
||||
public string PCGameSDKFilePath { get => pcGameSDKFilePath ??= Path.Combine(GameDirectory, GameConstants.PCGameSDKFilePath); }
|
||||
|
||||
public string ScreenShotDirectory { get => Path.Combine(GameDirectory, "ScreenShot"); }
|
||||
|
||||
public string DataDirectory { get => Path.Combine(GameDirectory, LaunchScheme.ExecutableIsOversea(GameFileName) ? GameConstants.GenshinImpactData : GameConstants.YuanShenData); }
|
||||
}
|
||||
@@ -19,12 +19,7 @@ internal sealed class LaunchExecutionUnlockFpsHandler : ILaunchExecutionDelegate
|
||||
|
||||
IProgressFactory progressFactory = context.ServiceProvider.GetRequiredService<IProgressFactory>();
|
||||
IProgress<GameFpsUnlockerContext> progress = progressFactory.CreateForMainThread<GameFpsUnlockerContext>(c => context.Progress.Report(LaunchStatus.FromUnlockerContext(c)));
|
||||
if (!context.TryGetGameFileSystem(out GameFileSystem? gameFileSystem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GameFpsUnlocker unlocker = new(context.ServiceProvider, context.Process, new(gameFileSystem, 100, 20000, 3000), progress);
|
||||
GameFpsUnlocker unlocker = new(context.ServiceProvider, context.Process, new(100, 20000, 3000), progress);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Memory;
|
||||
using System.Diagnostics;
|
||||
using static Snap.Hutao.Win32.Kernel32;
|
||||
|
||||
@@ -15,30 +16,43 @@ internal static class GameFpsAddress
|
||||
private const byte ASM_JMP = 0xE9;
|
||||
#pragma warning restore SA1310
|
||||
|
||||
public static unsafe void UnsafeFindFpsAddress(GameFpsUnlockerContext context, in RequiredRemoteModule remoteModule, in RequiredLocalModule localModule)
|
||||
public static unsafe void UnsafeFindFpsAddress(GameFpsUnlockerContext state, in RequiredGameModule requiredGameModule)
|
||||
{
|
||||
int offsetToUserAssembly = IndexOfPattern(localModule.UserAssembly.AsSpan());
|
||||
HutaoException.ThrowIfNot(offsetToUserAssembly >= 0, SH.ServiceGameUnlockerInterestedPatternNotFound);
|
||||
bool readOk = UnsafeReadModulesMemory(state.GameProcess, requiredGameModule, out VirtualMemory localMemory);
|
||||
HutaoException.ThrowIfNot(readOk, SH.ServiceGameUnlockerReadModuleMemoryCopyVirtualMemoryFailed);
|
||||
|
||||
nuint rip = localModule.UserAssembly.Address + (uint)offsetToUserAssembly;
|
||||
rip += 5U;
|
||||
rip += (nuint)(*(int*)(rip + 2U) + 6);
|
||||
|
||||
nuint remoteVirtualAddress = remoteModule.UserAssembly.Address + (rip - localModule.UserAssembly.Address);
|
||||
|
||||
nuint ptr = 0;
|
||||
SpinWait.SpinUntil(() => UnsafeReadProcessMemory(context.GameProcess, remoteVirtualAddress, out ptr) && ptr != 0);
|
||||
|
||||
nuint localVirtualAddress = ptr - remoteModule.UnityPlayer.Address + localModule.UnityPlayer.Address;
|
||||
|
||||
while (*(byte*)localVirtualAddress is ASM_CALL or ASM_JMP)
|
||||
using (localMemory)
|
||||
{
|
||||
localVirtualAddress += (nuint)(*(int*)(localVirtualAddress + 1) + 5);
|
||||
}
|
||||
int offset = IndexOfPattern(localMemory.AsSpan()[(int)requiredGameModule.UnityPlayer.Size..]);
|
||||
HutaoException.ThrowIfNot(offset >= 0, SH.ServiceGameUnlockerInterestedPatternNotFound);
|
||||
|
||||
localVirtualAddress += *(uint*)(localVirtualAddress + 2) + 6;
|
||||
nuint relativeVirtualAddress = localVirtualAddress - localModule.UnityPlayer.Address;
|
||||
context.FpsAddress = remoteModule.UnityPlayer.Address + relativeVirtualAddress;
|
||||
byte* pLocalMemory = (byte*)localMemory.Pointer;
|
||||
ref readonly Module unityPlayer = ref requiredGameModule.UnityPlayer;
|
||||
ref readonly Module userAssembly = ref requiredGameModule.UserAssembly;
|
||||
|
||||
nuint localMemoryUnityPlayerAddress = (nuint)pLocalMemory;
|
||||
nuint localMemoryUserAssemblyAddress = localMemoryUnityPlayerAddress + unityPlayer.Size;
|
||||
|
||||
nuint rip = localMemoryUserAssemblyAddress + (uint)offset;
|
||||
rip += 5U;
|
||||
rip += (nuint)(*(int*)(rip + 2U) + 6);
|
||||
|
||||
nuint address = userAssembly.Address + (rip - localMemoryUserAssemblyAddress);
|
||||
|
||||
nuint ptr = 0;
|
||||
SpinWait.SpinUntil(() => UnsafeReadProcessMemory(state.GameProcess, address, out ptr) && ptr != 0);
|
||||
|
||||
rip = ptr - unityPlayer.Address + localMemoryUnityPlayerAddress;
|
||||
|
||||
while (*(byte*)rip is ASM_CALL or ASM_JMP)
|
||||
{
|
||||
rip += (nuint)(*(int*)(rip + 1) + 5);
|
||||
}
|
||||
|
||||
nuint localMemoryActualAddress = rip + *(uint*)(rip + 2) + 6;
|
||||
nuint actualOffset = localMemoryActualAddress - localMemoryUnityPlayerAddress;
|
||||
state.FpsAddress = unityPlayer.Address + actualOffset;
|
||||
}
|
||||
}
|
||||
|
||||
private static int IndexOfPattern(in ReadOnlySpan<byte> memory)
|
||||
@@ -48,6 +62,16 @@ internal static class GameFpsAddress
|
||||
return memory.IndexOf(part);
|
||||
}
|
||||
|
||||
private static unsafe bool UnsafeReadModulesMemory(Process process, in RequiredGameModule moduleEntryInfo, out VirtualMemory memory)
|
||||
{
|
||||
ref readonly Module unityPlayer = ref moduleEntryInfo.UnityPlayer;
|
||||
ref readonly Module userAssembly = ref moduleEntryInfo.UserAssembly;
|
||||
|
||||
memory = new VirtualMemory(unityPlayer.Size + userAssembly.Size);
|
||||
return ReadProcessMemory(process.Handle, (void*)unityPlayer.Address, memory.AsSpan()[..(int)unityPlayer.Size], out _)
|
||||
&& ReadProcessMemory(process.Handle, (void*)userAssembly.Address, memory.AsSpan()[(int)unityPlayer.Size..], out _);
|
||||
}
|
||||
|
||||
private static unsafe bool UnsafeReadProcessMemory(Process process, nuint baseAddress, out nuint value)
|
||||
{
|
||||
value = 0;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.System.LibraryLoader;
|
||||
using System.Diagnostics;
|
||||
using static Snap.Hutao.Win32.Kernel32;
|
||||
|
||||
@@ -19,12 +18,12 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker
|
||||
private readonly LaunchOptions launchOptions;
|
||||
private readonly GameFpsUnlockerContext context = new();
|
||||
|
||||
public GameFpsUnlocker(IServiceProvider serviceProvider, Process gameProcess, in UnlockOptions options, IProgress<GameFpsUnlockerContext> progress)
|
||||
public GameFpsUnlocker(IServiceProvider serviceProvider, Process gameProcess, in UnlockTimingOptions options, IProgress<GameFpsUnlockerContext> progress)
|
||||
{
|
||||
launchOptions = serviceProvider.GetRequiredService<LaunchOptions>();
|
||||
|
||||
context.GameProcess = gameProcess;
|
||||
context.Options = options;
|
||||
context.TimingOptions = options;
|
||||
context.Progress = progress;
|
||||
}
|
||||
|
||||
@@ -32,22 +31,18 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker
|
||||
public async ValueTask<bool> UnlockAsync(CancellationToken token = default)
|
||||
{
|
||||
HutaoException.ThrowIfNot(context.IsUnlockerValid, "This Unlocker is invalid");
|
||||
(FindModuleResult result, RequiredRemoteModule remoteModule) = await GameProcessModule.FindModuleAsync(context).ConfigureAwait(false);
|
||||
(FindModuleResult result, RequiredGameModule gameModule) = await GameProcessModule.FindModuleAsync(context).ConfigureAwait(false);
|
||||
HutaoException.ThrowIfNot(result != FindModuleResult.TimeLimitExeeded, SH.ServiceGameUnlockerFindModuleTimeLimitExeeded);
|
||||
HutaoException.ThrowIfNot(result != FindModuleResult.NoModuleFound, SH.ServiceGameUnlockerFindModuleNoModuleFound);
|
||||
|
||||
using (RequiredLocalModule localModule = LoadRequiredLocalModule(context.Options.GameFileSystem))
|
||||
{
|
||||
GameFpsAddress.UnsafeFindFpsAddress(context, remoteModule, localModule);
|
||||
}
|
||||
|
||||
GameFpsAddress.UnsafeFindFpsAddress(context, gameModule);
|
||||
context.Report();
|
||||
return context.FpsAddress != 0U;
|
||||
}
|
||||
|
||||
public async ValueTask PostUnlockAsync(CancellationToken token = default)
|
||||
{
|
||||
using (PeriodicTimer timer = new(context.Options.AdjustFpsDelay))
|
||||
using (PeriodicTimer timer = new(context.TimingOptions.AdjustFpsDelay))
|
||||
{
|
||||
while (await timer.WaitForNextTickAsync(token).ConfigureAwait(false))
|
||||
{
|
||||
@@ -71,15 +66,4 @@ internal sealed class GameFpsUnlocker : IGameFpsUnlocker
|
||||
{
|
||||
return WriteProcessMemory((HANDLE)process.Handle, (void*)baseAddress, ref value, out _);
|
||||
}
|
||||
|
||||
private static RequiredLocalModule LoadRequiredLocalModule(GameFileSystem gameFileSystem)
|
||||
{
|
||||
string gameFoler = gameFileSystem.GameDirectory;
|
||||
string dataFoler = gameFileSystem.DataDirectory;
|
||||
LOAD_LIBRARY_FLAGS flags = LOAD_LIBRARY_FLAGS.LOAD_LIBRARY_AS_IMAGE_RESOURCE;
|
||||
HMODULE unityPlayerAddress = LoadLibraryExW(System.IO.Path.Combine(gameFoler, "UnityPlayer.dll"), default, flags);
|
||||
HMODULE userAssemblyAddress = LoadLibraryExW(System.IO.Path.Combine(dataFoler, "Native", "UserAssembly.dll"), default, flags);
|
||||
|
||||
return new(unityPlayerAddress, userAssemblyAddress);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user