Compare commits

..

83 Commits

Author SHA1 Message Date
qhy040404
8fbd648b1b add profile picture for each game role 2024-06-14 01:09:32 +08:00
qhy040404
107963b7ac Update issue template 2024-06-13 18:39:03 +08:00
DismissedLight
4e89406f2f Merge pull request #1721 from DGP-Studio/feat/1715 2024-06-13 16:15:21 +08:00
Lightczx
8119de3fa9 code style 2024-06-13 16:15:08 +08:00
qhy040404
7a8c233b10 review requests 2024-06-13 15:36:50 +08:00
qhy040404
cc71aa9c82 impl #1715 2024-06-13 12:51:22 +08:00
DismissedLight
4276481284 Add CachedImage Debug Layer 2024-06-11 21:05:24 +08:00
Lightczx
6f3159ae0c [skip ci] QA announcement name 2024-06-11 17:01:14 +08:00
Lightczx
c1b3412ba1 fix QA ComboBox width issue 2024-06-11 16:56:33 +08:00
Lightczx
99b3613319 fix #1688 2024-06-11 15:42:23 +08:00
Lightczx
069407abbc use weapon sort 2024-06-11 15:06:15 +08:00
DismissedLight
98c8df5c8e Merge pull request #1712 from DGP-Studio/feat/v3_cultivation 2024-06-11 14:04:49 +08:00
Lightczx
7cfcc17763 refactor 2024-06-11 14:00:48 +08:00
qhy040404
23741c4e48 exclude unavailable avatars 2024-06-11 13:12:37 +08:00
qhy040404
5f4b68d538 add cache to minimal deltas 2024-06-11 12:55:54 +08:00
Lightczx
9ef0d8c57d add SCIP solver 2024-06-11 12:31:51 +08:00
qhy040404
f0bfea51cf move to inventory service 2024-06-11 00:06:01 +08:00
DismissedLight
905454eb02 refactor 2024-06-10 23:31:38 +08:00
DismissedLight
05c3a575bc adjust db service parameter 2024-06-10 23:03:23 +08:00
DismissedLight
3e26e247cd refactor metadata abstraction 2024-06-10 22:43:50 +08:00
qhy040404
293b1e214d migrate all v2 api to v3 api 2024-06-10 22:37:56 +08:00
qhy040404
063665e77e refresh inventory 2024-06-10 22:37:55 +08:00
DismissedLight
50389ac06c Merge pull request #1713 from DGP-Studio/fix/dailynote 2024-06-10 22:12:57 +08:00
qhy040404
b99b34945e fix #1711 2024-06-10 11:05:58 +08:00
qhy040404
94a96c76bc fix #1710 2024-06-10 10:57:29 +08:00
DismissedLight
5cf3046257 Merge pull request #1694 from Mikachu2333/develop 2024-06-06 15:16:22 +08:00
Lightczx
89f8dedb57 fix url protocol launch lock 2024-06-06 13:11:24 +08:00
LinkChou
3c1e9237aa replace Uid to UID 2024-06-06 11:54:11 +08:00
LinkChou
e7cb01b302 Merge branch 'develop' of https://github.com/Mikachu2333/Snap.Hutao into develop 2024-06-06 11:48:03 +08:00
LinkChou
4cd971e166 Add some 2024-06-06 11:47:37 +08:00
Mikachu2333
7a9657f0cb Merge branch 'DGP-Studio:develop' into develop 2024-06-06 11:44:31 +08:00
Lightczx
82e6b62231 correctly free library 2024-06-06 09:29:50 +08:00
LinkChou
374c4d796d reformat 2024-06-06 07:25:11 +08:00
Mikachu2333
6e149a5be3 Update SH.resx 2024-06-06 01:44:32 +08:00
Mikachu2333
00ad0ef346 correct format 2024-06-06 01:39:10 +08:00
Mikachu2333
f22f165592 Merge branch 'develop' into develop 2024-06-06 01:33:09 +08:00
DismissedLight
5d8a39fe43 bump version 2024-06-05 21:29:28 +08:00
DismissedLight
521534be05 Merge pull request #1667 from DGP-Studio/l10n_develop 2024-06-05 21:22:17 +08:00
DismissedLight
b1364db3ac Merge pull request #1697 from DGP-Studio/opt/launch_game_activation 2024-06-05 20:35:18 +08:00
qhy040404
031cf77c27 refine LaunchGameAction 2024-06-05 19:09:57 +08:00
LinkChou
49c75dde2a Chinese text improve 2024-06-05 18:43:45 +08:00
Lightczx
3200c5e60b fix NTHeader offset 2024-06-05 17:22:45 +08:00
Lightczx
b392a6f8e5 Align HMODULE ptr 2024-06-05 17:17:52 +08:00
Lightczx
3e8e109123 use image header to fetch image size 2024-06-05 16:51:59 +08:00
Lightczx
91c886befb code style 2024-06-05 16:15:46 +08:00
Lightczx
32bdfe12af Fix Unlock Fps Attempt 2 2024-06-05 16:05:51 +08:00
Lightczx
eac67b6f44 Fix Unlock Fps Attempt 1 2024-06-05 15:28:50 +08:00
Lightczx
0dcba220c5 fix Launch Game ViewModel scope 2024-06-05 13:42:31 +08:00
Masterain
a204eaa95c New translations sh.resx (Vietnamese) 2024-06-04 18:31:38 -07:00
Masterain
35491c4eb1 New translations sh.resx (French) 2024-06-04 18:31:36 -07:00
Masterain
706401350c New translations sh.resx (Indonesian) 2024-06-04 18:31:36 -07:00
Masterain
c8ba04ee11 New translations sh.resx (English) 2024-06-04 18:31:34 -07:00
Masterain
b080a553c3 New translations sh.resx (Chinese Traditional) 2024-06-04 18:31:33 -07:00
Masterain
baf5612333 New translations sh.resx (Russian) 2024-06-04 18:31:32 -07:00
Masterain
eacd697cfe New translations sh.resx (Portuguese) 2024-06-04 18:31:31 -07:00
Masterain
11dc8e60bb New translations sh.resx (Korean) 2024-06-04 18:31:29 -07:00
Masterain
bba62996a0 New translations sh.resx (Japanese) 2024-06-04 18:31:28 -07:00
DismissedLight
db15b6a30c Merge pull request #1673 from DGP-Studio/ref/disable_web_login 2024-06-05 09:26:14 +08:00
Lightczx
1b0356b5ef fix #1669 2024-06-05 09:24:29 +08:00
qhy040404
6e498f5ede disable web login temporarily
maybe temporarily...
2024-06-04 22:30:32 +08:00
qhy040404
3117aefd54 try to fix permission 2024-06-04 21:00:27 +08:00
qhy040404
34ea240272 inline sign 2024-06-04 20:51:03 +08:00
DismissedLight
6b23ae5332 fix viewmode locker scope 2024-06-04 20:40:52 +08:00
qhy040404
c197d8a35a fix unresolved makeappx.exe 2024-06-04 20:22:47 +08:00
Lightczx
b0fa05283a code style 2024-06-04 17:19:45 +08:00
Masterain
c85a74dfc3 New translations sh.resx (Chinese Traditional) 2024-06-03 07:31:29 -07:00
DismissedLight
f7e53399b4 4.7 compatible 2024-06-03 21:49:06 +08:00
DismissedLight
52ac588a3a Merge pull request #1670 from DGP-Studio/dependabot/nuget/src/Snap.Hutao/develop/packages-7c1ae0f6e4 2024-06-03 16:21:21 +08:00
Lightczx
cd6c1f6b59 batch compute api endpoint 2024-06-03 16:18:12 +08:00
dependabot[bot]
7c734ce4aa Bump the packages group in /src/Snap.Hutao with 2 updates
Bumps the packages group in /src/Snap.Hutao with 2 updates: [MSTest.TestAdapter](https://github.com/microsoft/testfx) and [MSTest.TestFramework](https://github.com/microsoft/testfx).


Updates `MSTest.TestAdapter` from 3.4.0 to 3.4.3
- [Release notes](https://github.com/microsoft/testfx/releases)
- [Changelog](https://github.com/microsoft/testfx/blob/main/docs/Changelog.md)
- [Commits](https://github.com/microsoft/testfx/compare/v3.4.0...v3.4.3)

Updates `MSTest.TestFramework` from 3.4.0 to 3.4.3
- [Release notes](https://github.com/microsoft/testfx/releases)
- [Changelog](https://github.com/microsoft/testfx/blob/main/docs/Changelog.md)
- [Commits](https://github.com/microsoft/testfx/compare/v3.4.0...v3.4.3)

---
updated-dependencies:
- dependency-name: MSTest.TestAdapter
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: packages
- dependency-name: MSTest.TestFramework
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: packages
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-03 08:00:29 +00:00
DismissedLight
a640374b62 Merge pull request #1665 from DGP-Studio/feat/1663
Co-authored-by: Lightczx <1686188646@qq.com>
2024-06-03 14:11:28 +08:00
Lightczx
ca66176d64 code style 2024-06-03 14:11:00 +08:00
Lightczx
0f3a85e35c code style 2024-06-03 11:23:22 +08:00
qhy040404
4bb7316ce5 apply suggestion 2024-06-03 11:11:20 +08:00
qhy040404
7d6a9691a2 code style 2024-06-02 09:15:39 +08:00
qhy040404
1d4409aa43 code style 2024-06-02 09:10:31 +08:00
qhy040404
ea345f4854 use client to determine whether to redirect 2024-06-02 09:10:31 +08:00
qhy040404
72e163f613 auto constructor 2024-06-02 09:10:31 +08:00
qhy040404
86b04bb5a3 impl #1663 2024-06-02 09:10:31 +08:00
Masterain
5859ca3c12 New translations sh.resx (Chinese Traditional) 2024-06-01 11:19:36 -07:00
Masterain
e34e87359f New translations sh.resx (Chinese Traditional) 2024-06-01 09:51:13 -07:00
DismissedLight
53cda02071 screen capture preview 2024-06-01 22:53:56 +08:00
Masterain
ff6c682e1b New translations sh.resx (Chinese Traditional) 2024-05-31 10:16:41 -07:00
230 changed files with 3830 additions and 1398 deletions

View File

@@ -1,7 +1,7 @@
name: 功能请求
name: 功能请求
description: 通过这个议题来向开发团队分享你的想法
title: "[Feat]: 在这里填写一个合适的标题"
labels: ["功能", "needs-triage", "priority:none"]
labels: ["feature request", "needs-triage", "priority:none"]
assignees:
- Lightczx
body:
@@ -24,4 +24,4 @@ body:
label: 想要实现或优化的功能
description: 详细的描述一下你想要的功能,描述的越具体,采纳的可能性越高
validations:
required: true
required: true

View File

@@ -1,7 +1,7 @@
name: Feature Request [English Form]
description: Tell us about your thought
title: "[Feat]: Place your title here"
labels: ["功能", "needs-triage", "priority:none"]
labels: ["feature request", "needs-triage", "priority:none"]
assignees:
- Lightczx
body:
@@ -22,6 +22,6 @@ body:
id: req
attributes:
label: Detail of the Feature
description: Descripbe the feaure in detail. The more detailed and convincing the desciprtion the more likyly feature will be accepted.
description: Descripbe the feaure in detail. The more detailed and convincing the desciprtion the more likyly feature will be accepted.
validations:
required: true
required: true

View File

@@ -29,15 +29,7 @@ on:
jobs:
build:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
runner:
- self-hosted
- windows-latest
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -53,13 +45,55 @@ jobs:
run: dotnet tool restore && dotnet cake
env:
VERSION_API_TOKEN: ${{ secrets.VERSION_API_TOKEN }}
- 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
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: Upload signed msix
if: success() && github.event_name != 'pull_request'

View File

@@ -11,6 +11,9 @@ 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)
@@ -62,6 +65,11 @@ 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}");
}
@@ -88,10 +96,19 @@ 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("Build MSIX")
.IsDependentOn("Sign");
Task("NuGet Restore")
.Does(() =>
@@ -207,8 +224,11 @@ 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(
"makeappx.exe",
makeappxPath,
new ProcessSettings
{
Arguments = arguments
@@ -216,7 +236,46 @@ Task("Build MSIX")
);
if (p != 0)
{
throw new InvalidOperationException("Build failed with exit code " + p);
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;
}
});

View File

@@ -6,14 +6,25 @@ 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)} 期");
DateTimeOffset dateTimeOffset = new(2020, 7, 1, 4, 0, 0, Utc8);
Console.WriteLine($"2020-07-01 04:00:00 为第 {GetForDateTimeOffset(dateTimeOffset)} 期");
// 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))} 期");
}
public static int GetForDateTimeOffset(DateTimeOffset dateTimeOffset)
@@ -38,6 +49,12 @@ public class SpiralAbyssScheduleIdTest
periodNum--;
}
if (dateTimeOffset >= AcrobaticsBattleIntroducedTime)
{
// 当超过 96 期时,每一个月一期
periodNum = (4 * 12 * 2) + ((periodNum - (4 * 12 * 2)) / 2);
}
return periodNum;
}
}

View File

@@ -0,0 +1,45 @@
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);
}

View File

@@ -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.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -0,0 +1,51 @@
// 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;
[SuppressMessage("", "CA1001")]
[DependencyProperty("MilliSecondsDelay", typeof(int))]
internal sealed partial class InfoBarDelayCloseBehavior : BehaviorBase<InfoBar>
{
private readonly CancellationTokenSource closeTokenSource = new();
protected override void OnAssociatedObjectLoaded()
{
AssociatedObject.Closed += OnInfoBarClosed;
if (MilliSecondsDelay > 0)
{
DelayCoreAsync().SafeForget();
}
}
private async ValueTask DelayCoreAsync()
{
try
{
await Task.Delay(MilliSecondsDelay, closeTokenSource.Token).ConfigureAwait(true);
}
catch
{
return;
}
if (AssociatedObject is not null)
{
AssociatedObject.IsOpen = false;
}
}
private void OnInfoBarClosed(InfoBar infoBar, InfoBarClosedEventArgs args)
{
if (args.Reason is InfoBarCloseReason.CloseButton)
{
closeTokenSource.Cancel();
}
AssociatedObject.Closed -= OnInfoBarClosed;
}
}

View File

@@ -1,10 +1,15 @@
// 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;
@@ -12,8 +17,12 @@ namespace Snap.Hutao.Control.Image;
/// 缓存图像
/// </summary>
[HighQuality]
internal sealed class CachedImage : Implementation.ImageEx
[DependencyProperty("SourceName", typeof(string), "Unknown")]
[DependencyProperty("CachedName", typeof(string), "Unknown")]
internal sealed partial class CachedImage : Implementation.ImageEx
{
private string? file;
/// <summary>
/// 构造一个新的缓存图像
/// </summary>
@@ -26,12 +35,15 @@ internal sealed 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();
}
@@ -42,4 +54,27 @@ internal sealed 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);
}
}
}
}
}
}

View File

@@ -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,6 +14,13 @@
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}"

View File

@@ -2,6 +2,7 @@
// Licensed under the MIT license.
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Markup;
namespace Snap.Hutao.Control;
@@ -36,9 +37,18 @@ 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;
control?.Update();
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();
}
private void Update()

View File

@@ -23,7 +23,8 @@
<ContentPresenter
x:Name="ContentGrid"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Load="False">
<ContentPresenter.RenderTransform>
<CompositeTransform/>
</ContentPresenter.RenderTransform>
@@ -84,4 +85,4 @@
</Setter>
</Style>
</ResourceDictionary>
</ResourceDictionary>

View File

@@ -53,9 +53,14 @@ internal class ScopedPage : Page
{
try
{
IViewModel viewModel = pageScope.ServiceProvider.GetRequiredService<TViewModel>();
viewModel.CancellationToken = viewCancellationTokenSource.Token;
viewModel.DeferContentLoader = new DeferContentLoader(this);
TViewModel viewModel = pageScope.ServiceProvider.GetRequiredService<TViewModel>();
using (viewModel.DisposeLock.Enter())
{
viewModel.IsViewDisposed = false;
viewModel.CancellationToken = viewCancellationTokenSource.Token;
viewModel.DeferContentLoader = new DeferContentLoader(this);
}
DataContext = viewModel;
}
catch (Exception ex)
@@ -104,10 +109,9 @@ internal class ScopedPage : Page
viewCancellationTokenSource.Cancel();
IViewModel viewModel = (IViewModel)DataContext;
using (SemaphoreSlim locker = viewModel.DisposeLock)
using (viewModel.DisposeLock.Enter())
{
// Wait to ensure viewmodel operation is completed
locker.Wait();
viewModel.IsViewDisposed = true;
// Dispose the scope

View File

@@ -0,0 +1,25 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Service.Notification;
namespace Snap.Hutao.Control.Selector;
internal sealed class InfoBarTemplateSelector : DataTemplateSelector
{
public DataTemplate ActionButtonEnabled { get; set; } = default!;
public DataTemplate ActionButtonDisabled { get; set; } = default!;
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
if (item is InfoBarOptions { ActionButtonContent: { }, ActionButtonCommand: { } })
{
return ActionButtonEnabled;
}
return ActionButtonDisabled;
}
}

View File

@@ -21,8 +21,8 @@ internal sealed partial class SizeRestrictedContentControl : ContentControl
element.Measure(availableSize);
Size contentDesiredSize = element.DesiredSize;
Size contentActualOrDesiredSize = new(
Math.Max(element.ActualWidth, contentDesiredSize.Width),
Math.Max(element.ActualHeight, contentDesiredSize.Height));
Math.Min(Math.Max(element.ActualWidth, contentDesiredSize.Width), availableSize.Width),
Math.Min(Math.Max(element.ActualHeight, contentDesiredSize.Height), availableSize.Height));
if (IsWidthRestricted)
{

View File

@@ -10,6 +10,7 @@
<shmmc:AchievementIconConverter x:Key="AchievementIconConverter"/>
<shmmc:AvatarCardConverter x:Key="AvatarCardConverter"/>
<shmmc:AvatarIconConverter x:Key="AvatarIconConverter"/>
<shmmc:AvatarIconCircleConverter x:Key="AvatarIconCircleConverter"/>
<shmmc:AvatarNameCardPicConverter x:Key="AvatarNameCardPicConverter"/>
<shmmc:AvatarSideIconConverter x:Key="AvatarSideIconConverter"/>
<shmmc:DescriptionsParametersDescriptor x:Key="DescParamDescriptor"/>

View File

@@ -5,5 +5,5 @@ namespace Snap.Hutao.Core.Abstraction;
internal interface IPinnable<TData>
{
ref readonly TData GetPinnableReference();
ref TData GetPinnableReference();
}

View File

@@ -0,0 +1,9 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
namespace Snap.Hutao.Core.Abstraction;
internal interface IResurrectable
{
void Resurrect();
}

View File

@@ -11,16 +11,13 @@ 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))]
@@ -28,10 +25,9 @@ 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 readonly FrozenDictionary<int, TimeSpan> retryCountToDelay = FrozenDictionary.ToFrozenDictionary(
private static readonly FrozenDictionary<int, TimeSpan> DelayFromRetryCount = FrozenDictionary.ToFrozenDictionary(
[
KeyValuePair.Create(0, TimeSpan.FromSeconds(4)),
KeyValuePair.Create(1, TimeSpan.FromSeconds(16)),
@@ -46,16 +42,13 @@ 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, () =>
{
baseFolder ??= serviceProvider.GetRequiredService<RuntimeOptions>().LocalCache;
DirectoryInfo info = Directory.CreateDirectory(Path.Combine(baseFolder, CacheFolderName));
return info.FullName;
return serviceProvider.GetRequiredService<RuntimeOptions>().GetLocalCacheImageCacheFolder();
});
}
@@ -149,8 +142,7 @@ internal sealed partial class ImageCache : IImageCache, IImageCacheFilePathOpera
return treatNullFileAsInvalid;
}
FileInfo fileInfo = new(file);
return fileInfo.Length == 0;
return new FileInfo(file).Length == 0;
}
private void RemoveCore(IEnumerable<string> filePaths)
@@ -172,80 +164,76 @@ internal sealed partial class ImageCache : IImageCache, IImageCacheFilePathOpera
[SuppressMessage("", "SH003")]
private async Task DownloadFileAsync(Uri uri, string baseFile)
{
int retryCount = 0;
HttpClient httpClient = httpClientFactory.CreateClient(nameof(ImageCache));
while (retryCount < 3)
using (HttpClient httpClient = httpClientFactory.CreateClient(nameof(ImageCache)))
{
int retryCount = 0;
HttpRequestMessageBuilder requestMessageBuilder = httpRequestMessageBuilderFactory
.Create()
.SetRequestUri(uri)
// These headers are only available for our own api
.SetStaticResourceControlHeadersIf(uri.Host.Contains("api.snapgenshin.com", StringComparison.OrdinalIgnoreCase))
.SetStaticResourceControlHeadersIf(uri.Host.Contains("api.snapgenshin.com", StringComparison.OrdinalIgnoreCase)) // These headers are only available for our own api
.Get();
using (HttpRequestMessage requestMessage = requestMessageBuilder.HttpRequestMessage)
while (retryCount < 3)
{
using (HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
{
if (responseMessage.RequestMessage is { RequestUri: { } target } && target != uri)
{
logger.LogDebug("The Request '{Source}' has been redirected to '{Target}'", uri, target);
}
requestMessageBuilder.Resurrect();
if (responseMessage.IsSuccessStatusCode)
using (HttpRequestMessage requestMessage = requestMessageBuilder.HttpRequestMessage)
{
using (HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false))
{
if (responseMessage.Content.Headers.ContentType?.MediaType is "application/json")
// Redirect detection
if (responseMessage.RequestMessage is { RequestUri: { } target } && target != uri)
{
#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;
logger.LogDebug("The Request '{Source}' has been redirected to '{Target}'", uri, target);
}
using (Stream httpStream = await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false))
if (responseMessage.IsSuccessStatusCode)
{
using (FileStream fileStream = File.Create(baseFile))
if (responseMessage.Content.Headers.ContentType?.MediaType is "application/json")
{
await httpStream.CopyToAsync(fileStream).ConfigureAwait(false);
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));
return;
}
}
}
switch (responseMessage.StatusCode)
{
case HttpStatusCode.TooManyRequests:
using (Stream httpStream = await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
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;
using (FileStream fileStream = File.Create(baseFile))
{
await httpStream.CopyToAsync(fileStream).ConfigureAwait(false);
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;
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;
}
}
}
}
}
}
}
#if DEBUG
internal partial class ImageCache
{
private void DebugTrack(Uri uri)
[Conditional("DEBUG")]
private void DebugTrackFailedUri(Uri uri)
{
HashSet<string>? set = memoryCache.GetOrCreate(CacheFailedDownloadTasksName, entry => entry.Value ??= new HashSet<string>()) as HashSet<string>;
HashSet<string>? set = memoryCache.GetOrCreate(CacheFailedDownloadTasksName, entry => new HashSet<string>());
set?.Add(uri.ToString());
}
}
#endif
}

View File

@@ -70,7 +70,7 @@ internal sealed class ObservableReorderableDbCollection<TEntity> : ObservableCol
[SuppressMessage("", "SA1402")]
internal sealed class ObservableReorderableDbCollection<TEntityOnly, TEntity> : ObservableCollection<TEntityOnly>
where TEntityOnly : class, IEntityOnly<TEntity>
where TEntityOnly : class, IEntityAccess<TEntity>
where TEntity : class, IReorderable
{
private readonly IServiceProvider serviceProvider;

View File

@@ -73,7 +73,7 @@ internal sealed partial class ScopedDbCurrent<TEntity, TMessage>
[ConstructorGenerated]
internal sealed partial class ScopedDbCurrent<TEntityOnly, TEntity, TMessage>
where TEntityOnly : class, IEntityOnly<TEntity>
where TEntityOnly : class, IEntityAccess<TEntity>
where TEntity : class, ISelectable
where TMessage : Message.ValueChangedMessage<TEntityOnly>, new()
{

View File

@@ -41,7 +41,7 @@ internal static class DependencyInjection
.AddJsonOptions()
.AddDatabase()
.AddInjections()
.AddAllHttpClients()
.AddConfiguredHttpClients()
// Discrete services
.AddSingleton<IMessenger, WeakReferenceMessenger>()

View File

@@ -34,27 +34,27 @@ internal static class IocConfiguration
.AddTransient(typeof(Database.ScopedDbCurrent<,>))
.AddTransient(typeof(Database.ScopedDbCurrent<,,>))
.AddDbContextPool<AppDbContext>(AddDbContextCore);
}
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))
static void AddDbContextCore(IServiceProvider serviceProvider, DbContextOptionsBuilder builder)
{
if (context.Database.GetPendingMigrations().Any())
{
System.Diagnostics.Debug.WriteLine("[Database] Performing AppDbContext Migrations");
context.Database.Migrate();
}
}
RuntimeOptions runtimeOptions = serviceProvider.GetRequiredService<RuntimeOptions>();
string dbFile = System.IO.Path.Combine(runtimeOptions.DataFolder, "Userdata.db");
string sqlConnectionString = $"Data Source={dbFile}";
builder
.EnableSensitiveDataLogging()
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
.UseSqlite(sqlConnectionString);
// Temporarily create a context
using (AppDbContext context = AppDbContext.Create(serviceProvider, sqlConnectionString))
{
if (context.Database.GetPendingMigrations().Any())
{
System.Diagnostics.Debug.WriteLine("[Database] Performing AppDbContext Migrations");
context.Database.Migrate();
}
}
builder
.EnableSensitiveDataLogging()
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
.UseSqlite(sqlConnectionString);
}
}
}

View File

@@ -15,7 +15,7 @@ internal static partial class IocHttpClientConfiguration
{
private const string ApplicationJson = "application/json";
public static IServiceCollection AddAllHttpClients(this IServiceCollection services)
public static IServiceCollection AddConfiguredHttpClients(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<DynamicHttpProxy>();
clientHandler.Proxy = provider.GetRequiredService<HttpProxyUsingSystemProxy>();
});
})
.AddHttpClients();

View File

@@ -1,22 +0,0 @@
// 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);
}
}

View File

@@ -2,7 +2,12 @@
// 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;
@@ -18,4 +23,29 @@ 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;
}
}

View File

@@ -45,6 +45,30 @@ 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;
@@ -73,28 +97,4 @@ 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;
}
}

View File

@@ -6,6 +6,9 @@ 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)

View File

@@ -9,7 +9,7 @@ using System.Reflection;
namespace Snap.Hutao.Core.IO.Http.Proxy;
[Injection(InjectAs.Singleton)]
internal sealed partial class DynamicHttpProxy : ObservableObject, IWebProxy, IDisposable
internal sealed partial class HttpProxyUsingSystemProxy : 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 DynamicHttpProxy : ObservableObject, IWebProxy, ID
private IWebProxy innerProxy = default!;
public DynamicHttpProxy(IServiceProvider serviceProvider)
public HttpProxyUsingSystemProxy(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
UpdateInnerProxy();

View File

@@ -56,30 +56,39 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
/// <inheritdoc/>
public void PostInitialization()
{
serviceProvider.GetRequiredService<PrivateNamedPipeServer>().RunAsync().SafeForget();
ToastNotificationManagerCompat.OnActivated += NotificationActivate;
RunPostInitializationAsync().SafeForget();
using (activateSemaphore.Enter())
async ValueTask RunPostInitializationAsync()
{
// TODO: Introduced in 1.10.2, remove in later version
serviceProvider.GetRequiredService<IJumpListInterop>().ClearAsync().SafeForget();
serviceProvider.GetRequiredService<IScheduleTaskInterop>().UnregisterAllTasks();
await taskContext.SwitchToBackgroundAsync();
if (UnsafeLocalSetting.Get(SettingKeys.Major1Minor10Revision0GuideState, GuideState.Language) < GuideState.Completed)
serviceProvider.GetRequiredService<PrivateNamedPipeServer>().RunAsync().SafeForget();
ToastNotificationManagerCompat.OnActivated += NotificationActivate;
using (await activateSemaphore.EnterAsync().ConfigureAwait(false))
{
return;
// 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();
}
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();
}
}
@@ -96,25 +105,31 @@ internal sealed partial class AppActivation : IAppActivation, IAppActivationActi
await taskContext.SwitchToMainThreadAsync();
if (currentWindowReference.Window is null)
switch (currentWindowReference.Window)
{
currentWindowReference.Window = serviceProvider.GetRequiredService<LaunchGameWindow>();
return;
}
case null:
LaunchGameWindow launchGameWindow = serviceProvider.GetRequiredService<LaunchGameWindow>();
currentWindowReference.Window = launchGameWindow;
if (currentWindowReference.Window is MainWindow)
{
await serviceProvider
.GetRequiredService<INavigationService>()
.NavigateAsync<View.Page.LaunchGamePage>(INavigationAwaiter.Default, true)
.ConfigureAwait(false);
launchGameWindow.SwitchTo();
launchGameWindow.BringToForeground();
return;
return;
}
else
{
// We have a non-Main Window, just exit current process anyway
Process.GetCurrentProcess().Kill();
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;
}
}
@@ -134,6 +149,8 @@ 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))

View File

@@ -0,0 +1,14 @@
// 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; }
}

View File

@@ -6,9 +6,9 @@ namespace Snap.Hutao.Core.LifeCycle.InterProcess;
internal enum PipePacketCommand : byte
{
None = 0,
Connect = 1,
Exit = 1,
RedirectActivation = 10,
Exit = 30,
RequestElevationStatus = 11,
ResponseElevationStatus = 12,
}

View File

@@ -2,27 +2,83 @@
// 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 unsafe byte[] GetValidatedContent(this PipeStream stream, PipePacketHeader* header)
public static TData? ReadJsonContent<TData>(this PipeStream stream, ref readonly PipePacketHeader header)
{
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;
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);
}
}
public static unsafe void WritePacket(this PipeStream stream, PipePacketHeader* header, byte[] content)
public static unsafe void ReadPacket<TData>(this PipeStream stream, out PipePacketHeader header, out TData? data)
where TData : class
{
header->ContentLength = content.Length;
header->Checksum = XxHash64.HashToUInt64(content);
data = default;
stream.Write(new(header, sizeof(PipePacketHeader)));
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(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)));
}
}
}

View File

@@ -0,0 +1,10 @@
// 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";
}

View File

@@ -2,6 +2,7 @@
// 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;
@@ -10,72 +11,30 @@ namespace Snap.Hutao.Core.LifeCycle.InterProcess;
[ConstructorGenerated]
internal sealed partial class PrivateNamedPipeClient : IDisposable
{
private readonly NamedPipeClientStream clientStream = new(".", "Snap.Hutao.PrivateNamedPipe", PipeDirection.InOut, PipeOptions.Asynchronous | PipeOptions.WriteThrough);
private readonly NamedPipeClientStream clientStream = new(".", PrivateNamedPipe.Name, PipeDirection.InOut, PipeOptions.Asynchronous | PipeOptions.WriteThrough);
private readonly RuntimeOptions runtimeOptions;
public unsafe bool TryRedirectActivationTo(AppActivationArguments args)
{
if (clientStream.TryConnectOnce())
{
bool serverElevated = false;
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)
{
// 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)));
// Notify previous instance to exit
clientStream.WritePacket(PrivateNamedPipe.Version, PipePacketType.SessionTermination, PipePacketCommand.Exit);
clientStream.Flush();
return false;
}
{
// 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)));
}
// 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);
clientStream.Flush();
return true;
}

View File

@@ -19,7 +19,7 @@ internal sealed partial class PrivateNamedPipeMessageDispatcher
serviceProvider.GetRequiredService<IAppActivation>().Activate(args);
}
public void Exit()
public void ExitApplication()
{
ITaskContext taskContext = serviceProvider.GetRequiredService<ITaskContext>();
App app = serviceProvider.GetRequiredService<App>();

View File

@@ -1,6 +1,7 @@
// 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;
@@ -12,8 +13,6 @@ 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);
@@ -24,8 +23,6 @@ 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;
@@ -38,7 +35,7 @@ internal sealed partial class PrivateNamedPipeServer : IDisposable
}
serverStream = NamedPipeServerStreamAcl.Create(
"Snap.Hutao.PrivateNamedPipe",
PrivateNamedPipe.Name,
PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Byte,
@@ -78,41 +75,28 @@ internal sealed partial class PrivateNamedPipeServer : IDisposable
private unsafe void RunPacketSession(NamedPipeServerStream serverStream, CancellationToken token)
{
Span<byte> headerSpan = stackalloc byte[sizeof(PipePacketHeader)];
bool sessionTerminated = false;
while (serverStream.IsConnected && !sessionTerminated && !token.IsCancellationRequested)
while (serverStream.IsConnected && !token.IsCancellationRequested)
{
serverStream.ReadExactly(headerSpan);
fixed (byte* pHeader = headerSpan)
serverStream.ReadPacket(out PipePacketHeader header);
switch ((header.Type, header.Command))
{
PipePacketHeader* header = (PipePacketHeader*)pHeader;
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();
}
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;
}
return;
}
}
}

View File

@@ -27,4 +27,11 @@ 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;
}
}

View File

@@ -67,7 +67,7 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop
IUnknownMarshal.Release(pPersistFile);
}
uint value = IUnknownMarshal.Release(pShellLink);
IUnknownMarshal.Release(pShellLink);
}
return result;

View File

@@ -7,22 +7,22 @@ namespace Snap.Hutao.Core.Threading;
internal static class SpinWaitPolyfill
{
public static unsafe void SpinUntil<T>(ref T state, delegate*<ref readonly T, bool> condition)
public static unsafe void SpinUntil<T>(ref readonly T state, delegate*<ref readonly T, bool> condition)
{
SpinWait spinner = default;
while (!condition(ref state))
while (!condition(in state))
{
spinner.SpinOnce();
}
}
[SuppressMessage("", "SH002")]
public static unsafe bool SpinUntil<T>(ref T state, delegate*<ref readonly T, bool> condition, TimeSpan timeout)
public static unsafe bool SpinUntil<T>(ref readonly T state, delegate*<ref readonly T, bool> condition, TimeSpan timeout)
{
long startTime = Stopwatch.GetTimestamp();
SpinWait spinner = default;
while (!condition(ref state))
while (!condition(in state))
{
spinner.SpinOnce();

View File

@@ -103,7 +103,7 @@ internal static class TypeNameHelper
if (builder is null)
{
if (options.NestedTypeDelimiter != DefaultNestedTypeDelimiter)
if (options.NestedTypeDelimiter is not DefaultNestedTypeDelimiter)
{
return name.Replace(DefaultNestedTypeDelimiter, options.NestedTypeDelimiter);
}
@@ -112,7 +112,7 @@ internal static class TypeNameHelper
}
builder.Append(name);
if (options.NestedTypeDelimiter != DefaultNestedTypeDelimiter)
if (options.NestedTypeDelimiter is not DefaultNestedTypeDelimiter)
{
builder.Replace(DefaultNestedTypeDelimiter, options.NestedTypeDelimiter, builder.Length - name.Length, name.Length);
}

View File

@@ -1,19 +1,18 @@
// 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 CompactRect
internal readonly struct RectInt16
{
private readonly short x;
private readonly short y;
private readonly short width;
private readonly short height;
private CompactRect(int x, int y, int width, int height)
private RectInt16(int x, int y, int width, int height)
{
this.x = (short)x;
this.y = (short)y;
@@ -21,24 +20,22 @@ internal readonly struct CompactRect
this.height = (short)height;
}
public static implicit operator RectInt32(CompactRect rect)
public static implicit operator RectInt32(RectInt16 rect)
{
return new(rect.x, rect.y, rect.width, rect.height);
}
public static explicit operator CompactRect(RectInt32 rect)
public static explicit operator RectInt16(RectInt32 rect)
{
return new(rect.X, rect.Y, rect.Width, rect.Height);
}
public static unsafe explicit operator CompactRect(ulong value)
public static unsafe explicit operator RectInt16(ulong value)
{
Unsafe.SkipInit(out CompactRect rect);
*(ulong*)&rect = value;
return rect;
return *(RectInt16*)&value;
}
public static unsafe implicit operator ulong(CompactRect rect)
public static unsafe implicit operator ulong(RectInt16 rect)
{
return *(ulong*)&rect;
}

View File

@@ -63,7 +63,8 @@ internal static class WindowExtension
{
ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_SHOW);
}
else if (IsIconic(hwnd))
if (IsIconic(hwnd))
{
ShowWindow(hwnd, SHOW_WINDOW_CMD.SW_RESTORE);
}

View File

@@ -241,7 +241,7 @@ internal sealed class XamlWindowController
if (window is IXamlWindowRectPersisted rectPersisted)
{
RectInt32 nonDpiPersistedRect = (CompactRect)LocalSetting.Get(rectPersisted.PersistRectKey, (CompactRect)rect);
RectInt32 nonDpiPersistedRect = (RectInt16)LocalSetting.Get(rectPersisted.PersistRectKey, (RectInt16)rect);
RectInt32 persistedRect = nonDpiPersistedRect.Scale(scale);
// If the persisted size is less than min size, we want to reset to the init size.
@@ -266,7 +266,7 @@ internal sealed class XamlWindowController
{
// We save the non-dpi rect here
double scale = 1.0 / window.GetRasterizationScale();
LocalSetting.Set(rectPersisted.PersistRectKey, (CompactRect)window.AppWindow.GetRect().Scale(scale));
LocalSetting.Set(rectPersisted.PersistRectKey, (RectInt16)window.AppWindow.GetRect().Scale(scale));
}
}
#endregion

View File

@@ -199,6 +199,13 @@ 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
@@ -213,4 +220,11 @@ 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;
}
}

View File

@@ -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, IEntityOnly<TEntity>
where TEntityOnly : class, IEntityAccess<TEntity>
where TEntity : class, IReorderable
{
return source is List<TEntityOnly> list

View File

@@ -0,0 +1,654 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Snap.Hutao.Model.Entity.Database;
#nullable disable
namespace Snap.Hutao.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20240613144942_UserGameRoleProfilePicture")]
partial class UserGameRoleProfilePicture
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid>("ArchiveId")
.HasColumnType("TEXT");
b.Property<uint>("Current")
.HasColumnType("INTEGER");
b.Property<uint>("Id")
.HasColumnType("INTEGER");
b.Property<int>("Status")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("Time")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ArchiveId");
b.ToTable("achievements");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.AchievementArchive", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("achievement_archives");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.AvatarInfo", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("CalculatorRefreshTime")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("GameRecordRefreshTime")
.HasColumnType("TEXT");
b.Property<string>("Info")
.IsRequired()
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("ShowcaseRefreshTime")
.HasColumnType("TEXT");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("avatar_infos");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("Id")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.ToTable("cultivate_entries");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarLevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("AvatarLevelTo")
.HasColumnType("INTEGER");
b.Property<Guid>("EntryId")
.HasColumnType("TEXT");
b.Property<uint>("SkillALevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("SkillALevelTo")
.HasColumnType("INTEGER");
b.Property<uint>("SkillELevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("SkillELevelTo")
.HasColumnType("INTEGER");
b.Property<uint>("SkillQLevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("SkillQLevelTo")
.HasColumnType("INTEGER");
b.Property<uint>("WeaponLevelFrom")
.HasColumnType("INTEGER");
b.Property<uint>("WeaponLevelTo")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("EntryId")
.IsUnique();
b.ToTable("cultivate_entry_level_informations");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateItem", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("Count")
.HasColumnType("INTEGER");
b.Property<Guid>("EntryId")
.HasColumnType("TEXT");
b.Property<bool>("IsFinished")
.HasColumnType("INTEGER");
b.Property<uint>("ItemId")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("EntryId");
b.ToTable("cultivate_items");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateProject", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AttachedUid")
.HasColumnType("TEXT");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("cultivate_projects");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.DailyNoteEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("DailyNote")
.HasColumnType("TEXT");
b.Property<bool>("DailyTaskNotify")
.HasColumnType("INTEGER");
b.Property<bool>("DailyTaskNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<bool>("ExpeditionNotify")
.HasColumnType("INTEGER");
b.Property<bool>("ExpeditionNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<bool>("HomeCoinNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<int>("HomeCoinNotifyThreshold")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("RefreshTime")
.HasColumnType("TEXT");
b.Property<bool>("ResinNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<int>("ResinNotifyThreshold")
.HasColumnType("INTEGER");
b.Property<bool>("TransformerNotify")
.HasColumnType("INTEGER");
b.Property<bool>("TransformerNotifySuppressed")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.Property<Guid>("UserId")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("UserId");
b.ToTable("daily_notes");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GachaArchive", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("gacha_archives");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GachaItem", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<Guid>("ArchiveId")
.HasColumnType("TEXT");
b.Property<int>("GachaType")
.HasColumnType("INTEGER");
b.Property<long>("Id")
.HasColumnType("INTEGER");
b.Property<uint>("ItemId")
.HasColumnType("INTEGER");
b.Property<int>("QueryType")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("Time")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ArchiveId");
b.ToTable("gacha_items");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GameAccount", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AttachUid")
.HasColumnType("TEXT");
b.Property<int>("Index")
.HasColumnType("INTEGER");
b.Property<string>("MihoyoSDK")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.ToTable("game_accounts");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryItem", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("Count")
.HasColumnType("INTEGER");
b.Property<uint>("ItemId")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.ToTable("inventory_items");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryReliquary", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("AppendPropIdList")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("ItemId")
.HasColumnType("INTEGER");
b.Property<int>("Level")
.HasColumnType("INTEGER");
b.Property<int>("MainPropId")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.ToTable("inventory_reliquaries");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryWeapon", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<int>("ItemId")
.HasColumnType("INTEGER");
b.Property<int>("Level")
.HasColumnType("INTEGER");
b.Property<Guid>("ProjectId")
.HasColumnType("TEXT");
b.Property<int>("PromoteLevel")
.HasColumnType("INTEGER");
b.HasKey("InnerId");
b.HasIndex("ProjectId");
b.ToTable("inventory_weapons");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.ObjectCacheEntry", b =>
{
b.Property<string>("Key")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("ExpireTime")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("Key");
b.ToTable("object_cache");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.SettingEntry", b =>
{
b.Property<string>("Key")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("Key");
b.ToTable("settings");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.SpiralAbyssEntry", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("ScheduleId")
.HasColumnType("INTEGER");
b.Property<string>("SpiralAbyss")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("spiral_abysses");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.User", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Aid")
.HasColumnType("TEXT");
b.Property<string>("CookieToken")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("CookieTokenLastUpdateTime")
.HasColumnType("TEXT");
b.Property<string>("Fingerprint")
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("FingerprintLastUpdateTime")
.HasColumnType("TEXT");
b.Property<int>("Index")
.HasColumnType("INTEGER");
b.Property<bool>("IsOversea")
.HasColumnType("INTEGER");
b.Property<bool>("IsSelected")
.HasColumnType("INTEGER");
b.Property<string>("LToken")
.HasColumnType("TEXT")
.HasColumnName("Ltoken");
b.Property<string>("Mid")
.HasColumnType("TEXT");
b.Property<string>("PreferredUid")
.HasColumnType("TEXT");
b.Property<string>("SToken")
.HasColumnType("TEXT")
.HasColumnName("Stoken");
b.HasKey("InnerId");
b.ToTable("users");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.UserGameRoleProfilePicture", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarId")
.HasColumnType("INTEGER");
b.Property<uint>("CostumeId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("LastUpdateTime")
.HasColumnType("TEXT");
b.Property<uint>("ProfilePictureId")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("profile_pictures");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.AchievementArchive", "Archive")
.WithMany()
.HasForeignKey("ArchiveId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Archive");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntry", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateEntry", "Entry")
.WithOne("LevelInformation")
.HasForeignKey("Snap.Hutao.Model.Entity.CultivateEntryLevelInformation", "EntryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Entry");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateItem", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateEntry", "Entry")
.WithMany()
.HasForeignKey("EntryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Entry");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.DailyNoteEntry", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.GachaItem", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.GachaArchive", "Archive")
.WithMany()
.HasForeignKey("ArchiveId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Archive");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryItem", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryReliquary", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.InventoryWeapon", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.CultivateProject", "Project")
.WithMany()
.HasForeignKey("ProjectId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Project");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.CultivateEntry", b =>
{
b.Navigation("LevelInformation");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,38 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Snap.Hutao.Migrations
{
/// <inheritdoc />
public partial class UserGameRoleProfilePicture : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "profile_pictures",
columns: table => new
{
InnerId = table.Column<Guid>(type: "TEXT", nullable: false),
Uid = table.Column<string>(type: "TEXT", nullable: false),
ProfilePictureId = table.Column<uint>(type: "INTEGER", nullable: false),
AvatarId = table.Column<uint>(type: "INTEGER", nullable: false),
CostumeId = table.Column<uint>(type: "INTEGER", nullable: false),
LastUpdateTime = table.Column<DateTimeOffset>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_profile_pictures", x => x.InnerId);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "profile_pictures");
}
}
}

View File

@@ -15,7 +15,7 @@ namespace Snap.Hutao.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
@@ -515,6 +515,33 @@ namespace Snap.Hutao.Migrations
b.ToTable("users");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.UserGameRoleProfilePicture", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarId")
.HasColumnType("INTEGER");
b.Property<uint>("CostumeId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("LastUpdateTime")
.HasColumnType("TEXT");
b.Property<uint>("ProfilePictureId")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("profile_pictures");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.AchievementArchive", "Archive")

View File

@@ -65,6 +65,8 @@ internal sealed class AppDbContext : DbContext
public DbSet<SpiralAbyssEntry> SpiralAbysses { get; set; } = default!;
public DbSet<UserGameRoleProfilePicture> UserGameRoleProfilePictures { get; set; } = default!;
public static AppDbContext Create(IServiceProvider serviceProvider, string sqlConnectionString)
{
DbContextOptions<AppDbContext> options = new DbContextOptionsBuilder<AppDbContext>()

View File

@@ -12,7 +12,8 @@ namespace Snap.Hutao.Model.Entity;
/// </summary>
[HighQuality]
[Table("inventory_items")]
internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, uint>
internal sealed class InventoryItem : IDbMappingForeignKeyFrom<InventoryItem, uint>,
IDbMappingForeignKeyFrom<InventoryItem, uint, uint>
{
/// <summary>
/// 内部Id
@@ -56,4 +57,21 @@ 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,
};
}
}

View File

@@ -0,0 +1,41 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Core.Abstraction;
using Snap.Hutao.Web.Enka.Model;
using Snap.Hutao.Web.Hoyolab;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Snap.Hutao.Model.Entity;
[Table("profile_pictures")]
[SuppressMessage("", "SH002")]
internal sealed class UserGameRoleProfilePicture : IMappingFrom<UserGameRoleProfilePicture, PlayerUid, ProfilePicture>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid InnerId { get; set; }
public string Uid { get; set; } = default!;
public uint ProfilePictureId { get; set; }
public uint AvatarId { get; set; }
public uint CostumeId { get; set; }
public DateTimeOffset LastUpdateTime { get; set; }
public static UserGameRoleProfilePicture From(PlayerUid uid, ProfilePicture profilePicture)
{
return new()
{
Uid = uid.ToString(),
ProfilePictureId = profilePicture.ProfilePictureId,
AvatarId = profilePicture.AvatarId,
CostumeId = profilePicture.CostumeId,
LastUpdateTime = DateTimeOffset.Now,
};
}
}

View File

@@ -0,0 +1,14 @@
// 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; }
}

View File

@@ -1,26 +0,0 @@
// 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; }
}

View File

@@ -13,7 +13,7 @@ namespace Snap.Hutao.Model.InterChange.GachaLog;
/// UIGF物品
/// </summary>
[HighQuality]
internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem, INameQuality>
internal sealed class UIGFItem : GachaLogItem, IMappingFrom<UIGFItem, GachaItem, INameQualityAccess>
{
/// <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, INameQuality nameQuality)
public static UIGFItem From(GachaItem item, INameQualityAccess nameQuality)
{
return new()
{

View File

@@ -0,0 +1,13 @@
// 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; }
}

View File

@@ -3,7 +3,7 @@
namespace Snap.Hutao.Model.Metadata.Abstraction;
internal interface IItemSource
internal interface IItemConvertible
{
Model.Item ToItem();
}

View File

@@ -9,7 +9,7 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
/// 物品与星级
/// </summary>
[HighQuality]
internal interface INameQuality
internal interface INameQualityAccess
{
/// <summary>
/// 名称

View File

@@ -9,7 +9,7 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
/// 指示该类为统计物品的源
/// </summary>
[HighQuality]
internal interface IStatisticsItemSource
internal interface IStatisticsItemConvertible
{
/// <summary>
/// 转换到统计物品

View File

@@ -10,19 +10,9 @@ namespace Snap.Hutao.Model.Metadata.Abstraction;
/// 指示该类为简述统计物品的源
/// </summary>
[HighQuality]
internal interface ISummaryItemSource
internal interface ISummaryItemConvertible
{
/// <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);
}

View File

@@ -1,99 +0,0 @@
// 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,
};
}
}

View File

@@ -1,99 +1,118 @@
// 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
internal partial class Avatar : INameQualityAccess,
IStatisticsItemConvertible,
ISummaryItemConvertible,
IItemConvertible,
ICalculableSource<ICalculableAvatar>,
ICultivationItemsAccess
{
/// <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,
};
}
}

View File

@@ -12,4 +12,8 @@ internal sealed class ProfilePicture
public string Icon { get; set; } = default!;
public string Name { get; set; } = default!;
public AvatarId AvatarId { get; set; }
public CostumeId CostumeId { get; set; }
}

View File

@@ -97,6 +97,11 @@ 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>
/// 检查该角色是否为主角

View File

@@ -0,0 +1,29 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Control;
namespace Snap.Hutao.Model.Metadata.Converter;
/// <summary>
/// 玩家头像转换器
/// </summary>
[HighQuality]
internal sealed class AvatarIconCircleConverter : ValueConverter<string, Uri>
{
/// <summary>
/// 名称转Uri
/// </summary>
/// <param name="name">名称</param>
/// <returns>链接</returns>
public static Uri IconNameToUri(string name)
{
return Web.HutaoEndpoints.StaticRaw("AvatarIconCircle", $"{name}.png").ToUri();
}
/// <inheritdoc/>
public override Uri Convert(string from)
{
return IconNameToUri(from);
}
}

View File

@@ -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,
_ => treatSundayAsTrue && (Materials.MondayThursdayItems.Contains(Id) || Materials.TuesdayFridayItems.Contains(Id) || Materials.WednesdaySaturdayItems.Contains(Id)),
};
}

View File

@@ -1,107 +0,0 @@
// 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,
};
}
}

View File

@@ -1,69 +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.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
internal sealed partial class Weapon : INameQualityAccess,
IStatisticsItemConvertible,
ISummaryItemConvertible,
IItemConvertible,
ICalculableSource<ICalculableWeapon>,
ICultivationItemsAccess
{
/// <summary>
/// Id
/// </summary>
public WeaponId Id { get; set; }
/// <summary>
/// 突破 Id
/// </summary>
public PromoteId PromoteId { get; set; }
/// <summary>
/// 武器类型
/// </summary>
public uint Sort { get; set; }
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,
};
}
}

View File

@@ -13,7 +13,7 @@
<Identity
Name="60568DGPStudio.SnapHutao"
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
Version="1.10.2.0" />
Version="1.10.3.0" />
<Properties>
<DisplayName>Snap Hutao</DisplayName>

View File

@@ -13,7 +13,7 @@
<Identity
Name="60568DGPStudio.SnapHutaoDev"
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
Version="1.10.2.0" />
Version="1.10.3.0" />
<Properties>
<DisplayName>Snap Hutao Dev</DisplayName>

View File

@@ -2996,6 +2996,9 @@
<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>

View File

@@ -2996,6 +2996,9 @@
<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>

View File

@@ -2996,6 +2996,9 @@
<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>

View File

@@ -2996,6 +2996,9 @@
<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>

View File

@@ -2996,6 +2996,9 @@
<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>

View File

@@ -2996,6 +2996,9 @@
<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>

View File

@@ -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,6 +1568,9 @@
<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>
@@ -1925,6 +1928,9 @@
<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>
@@ -2067,10 +2073,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>
@@ -2079,7 +2085,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>
@@ -2406,7 +2412,7 @@
<value>重命名</value>
</data>
<data name="ViewPageLaunchGameSwitchSchemeDescription" xml:space="preserve">
<value>切换游戏服务器(国服/渠道服/国际服)</value>
<value>切换游戏服务器(国服 / 渠道服 / 国际服)</value>
</data>
<data name="ViewPageLaunchGameSwitchSchemeHeader" xml:space="preserve">
<value>服务器</value>
@@ -2415,7 +2421,7 @@
<value>版本更新前需要提前转换至与启动器匹配的服务器</value>
</data>
<data name="ViewPageLaunchGameUnlockFpsDescription" xml:space="preserve">
<value>请在游戏内关闭垂直同步选项,需要高性能的显卡以支持更高的帧率</value>
<value>请在游戏内关闭垂直同步选项,需要高性能的显卡以支持更高的帧率</value>
</data>
<data name="ViewPageLaunchGameUnlockFpsHeader" xml:space="preserve">
<value>解锁帧率限制</value>
@@ -2433,7 +2439,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>
@@ -2511,7 +2517,7 @@
<value>除非开发人员明确要求你这么做,否则不应尝试执行下方的操作!</value>
</data>
<data name="ViewPageSettingDataFolderDescription" xml:space="preserve">
<value>用户数据/元数据 在此处存放</value>
<value>用户数据 / 元数据 在此处存放</value>
</data>
<data name="ViewPageSettingDataFolderHeader" xml:space="preserve">
<value>数据 文件夹</value>
@@ -2589,7 +2595,7 @@
<value>选择想要获取公告的游戏服务器</value>
</data>
<data name="ViewPageSettingHomeAnnouncementRegionHeader" xml:space="preserve">
<value>公告所属服务器</value>
<value>游戏公告所属服务器</value>
</data>
<data name="ViewpageSettingHomeCardDescription" xml:space="preserve">
<value>管理主页仪表板中的卡片</value>
@@ -2646,7 +2652,7 @@
<value>您可以无限制的使用任何测试功能</value>
</data>
<data name="ViewPageSettingHutaoPassportMaintainerHeader" xml:space="preserve">
<value>胡桃开发/运维</value>
<value>胡桃开发 / 运维</value>
</data>
<data name="ViewPageSettingHutaoPassportRedeemCodeDescription" xml:space="preserve">
<value>我们有时会向某些用户赠送胡桃云兑换码</value>
@@ -2703,7 +2709,7 @@
<value>重置图片资源</value>
</data>
<data name="ViewPageSettingsAdvancedOptionsLaunchUnlockFpsDescription" xml:space="preserve">
<value>在启动游戏页面的进程部分加入解锁帧率限制选项</value>
<value>在启动游戏-进程」选项卡加入解锁帧率限制选项</value>
</data>
<data name="ViewPageSettingsAdvancedOptionsLaunchUnlockFpsHeader" xml:space="preserve">
<value>启动游戏-解锁帧率限制</value>
@@ -2751,7 +2757,7 @@
<value>贡献翻译</value>
</data>
<data name="ViewPageSettingUnobtainedWishItemVisibleDescription" xml:space="preserve">
<value>在祈愿记录页面角色与武器页签显示未抽取到的祈愿物品</value>
<value>在祈愿记录-角色」与「祈愿记录-武器」中显示未抽取到的祈愿物品</value>
</data>
<data name="ViewPageSettingUnobtainedWishItemVisibleHeader" xml:space="preserve">
<value>未抽取到的祈愿物品</value>
@@ -2996,6 +3002,9 @@
<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>

View File

@@ -2996,6 +2996,9 @@
<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>

View File

@@ -2996,6 +2996,9 @@
<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>

View File

@@ -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>你正在通過由我們提供的內嵌網頁視圖登入 miHoYo 通行證賬號,我們會在你點擊 我已登 按鈕後,讀取你的 Cookie 信息,由此視圖發起的網絡通信只發生於你的計算機與 miHoYo 服務器之間</value>
<value>你正在通過由我們提供的內嵌網頁視圖登錄 米哈游通行证,我們會在你點擊 我已登 按鈕後,讀取你的 Cookie 信息,由此視圖發起的網絡通信只發生於你的計算機與米哈遊服務器之間</value>
</data>
<data name="ViewPageLoginMihoyoUserLoggedInAction" xml:space="preserve">
<value>我已登入</value>
</data>
<data name="ViewPageLoginMihoyoUserTitle" xml:space="preserve">
<value>在下方登入 miHoYo 通行證賬號</value>
<value>在下方登入米哈游通行证</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,6 +2996,9 @@
<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>
@@ -3225,10 +3228,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>

View File

@@ -82,31 +82,10 @@ internal abstract partial class DbStoreOptions : ObservableObject
return storage.Value;
}
[return: NotNull]
protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, [DisallowNull] T defaultValue)
[return: NotNullIfNotNull(nameof(defaultValue))]
protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, T 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;
return GetOption(ref storage, key, deserializer, () => defaultValue);
}
protected T GetOption<T>(ref T? storage, string key, Func<string, T> deserializer, Func<T> defaultValueFactory)

View File

@@ -20,7 +20,7 @@ namespace Snap.Hutao.Service;
[Injection(InjectAs.Scoped, typeof(IAnnouncementService))]
internal sealed partial class AnnouncementService : IAnnouncementService
{
private static readonly string CacheKey = $"{nameof(AnnouncementService)}.Cache.{nameof(AnnouncementWrapper)}";
private const string CacheKey = $"{nameof(AnnouncementService)}.Cache.{nameof(AnnouncementWrapper)}";
private readonly IServiceScopeFactory serviceScopeFactory;
private readonly ITaskContext taskContext;

View File

@@ -16,16 +16,6 @@ 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);

View File

@@ -2,15 +2,14 @@
// 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;
@@ -51,22 +50,6 @@ 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)
{
@@ -86,7 +69,7 @@ internal sealed partial class CultivationService : ICultivationService
entryItems.Add(new(cultivateItem, context.GetMaterial(cultivateItem.ItemId)));
}
Item item = entry.Type switch
ModelItem item = entry.Type switch
{
CultivateType.AvatarAndSkill => context.GetAvatar(entry.Id).ToItem(),
CultivateType.Weapon => context.GetWeapon(entry.Id).ToItem(),
@@ -130,7 +113,7 @@ internal sealed partial class CultivationService : ICultivationService
}
}
foreach (InventoryItem inventoryItem in await cultivationDbService.GetInventoryItemListByProjectIdAsync(projectId, token).ConfigureAwait(false))
foreach (InventoryItem inventoryItem in await inventoryDbService.GetInventoryItemListByProjectIdAsync(projectId, token).ConfigureAwait(false))
{
if (resultItems.SingleOrDefault(i => i.Inner.Id == inventoryItem.ItemId) is { } existedItem)
{
@@ -147,12 +130,6 @@ 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)
{

View File

@@ -7,8 +7,7 @@ using System.Collections.ObjectModel;
namespace Snap.Hutao.Service.Cultivation;
internal interface ICultivationDbService : IAppDbService<InventoryItem>,
IAppDbService<CultivateEntryLevelInformation>,
internal interface ICultivationDbService : IAppDbService<CultivateEntryLevelInformation>,
IAppDbService<CultivateProject>,
IAppDbService<CultivateEntry>,
IAppDbService<CultivateItem>
@@ -29,10 +28,6 @@ internal interface ICultivationDbService : IAppDbService<InventoryItem>,
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);

View File

@@ -27,8 +27,6 @@ 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);
@@ -54,12 +52,6 @@ internal interface ICultivationService
/// <param name="item">养成物品</param>
void SaveCultivateItem(CultivateItemView item);
/// <summary>
/// 保存单个物品
/// </summary>
/// <param name="item">物品</param>
void SaveInventoryItem(InventoryItemView item);
/// <summary>
/// 异步尝试添加新的项目
/// </summary>

View File

@@ -48,7 +48,7 @@ internal sealed partial class DailyNoteOptions : DbStoreOptions
{
quartzService.UpdateJobAsync(JobIdentity.DailyNoteGroupName, JobIdentity.DailyNoteRefreshTriggerName, builder =>
{
return builder.WithSimpleSchedule(sb => sb.WithIntervalInMinutes(SelectedRefreshTime.Value).RepeatForever());
return builder.WithSimpleSchedule(sb => sb.WithIntervalInSeconds(SelectedRefreshTime.Value).RepeatForever());
}).SafeForget();
}
}

View File

@@ -32,6 +32,6 @@ internal sealed partial class DailyNoteWebhookOperation
.SetHeader("x-uid", $"{playerUid}")
.PostJson(dailyNote);
await builder.TryCatchSendAsync(httpClient, logger, token).ConfigureAwait(false);
await builder.SendAsync(httpClient, logger, token).ConfigureAwait(false);
}
}

View File

@@ -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 : IStatisticsItemSource
where TItem : IStatisticsItemConvertible
{
IOrderedEnumerable<StatisticsItem> result = dict
.Select(kvp => kvp.Key.ToStatisticsItem(kvp.Value))

View File

@@ -27,7 +27,7 @@ internal sealed partial class GachaStatisticsSlimFactory : IGachaStatisticsSlimF
return CreateCore(context, items, uid);
}
private static void Track(INameQuality nameQuality, ref int orangeTracker, ref int purpleTracker)
private static void Track(INameQualityAccess 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))
{
INameQuality nameQuality = context.GetNameQualityByItemId(item.ItemId);
INameQualityAccess nameQuality = context.GetNameQualityByItemId(item.ItemId);
switch (item.QueryType)
{
case GachaType.Standard:

View File

@@ -16,11 +16,11 @@ internal sealed class HistoryWishBuilder
{
private readonly GachaEvent gachaEvent;
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 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 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 => (IStatisticsItemSource)a, a => 0);
purpleUpCounter = gachaEvent.UpPurpleList.Select(id => context.IdAvatarMap[id]).ToDictionary(a => (IStatisticsItemSource)a, a => 0);
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);
break;
case GachaType.ActivityWeapon:
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);
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);
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 => (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);
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);
break;
}
}
@@ -74,7 +74,7 @@ internal sealed class HistoryWishBuilder
/// </summary>
/// <param name="item">物品</param>
/// <returns>是否为Up物品</returns>
public bool IncreaseOrange(IStatisticsItemSource item)
public bool IncreaseOrange(IStatisticsItemConvertible item)
{
orangeCounter.IncreaseOne(item);
++totalCountTracker;
@@ -86,7 +86,7 @@ internal sealed class HistoryWishBuilder
/// 计数四星物品
/// </summary>
/// <param name="item">物品</param>
public void IncreasePurple(IStatisticsItemSource item)
public void IncreasePurple(IStatisticsItemConvertible item)
{
purpleUpCounter.TryIncreaseOne(item);
purpleCounter.IncreaseOne(item);
@@ -97,7 +97,7 @@ internal sealed class HistoryWishBuilder
/// 计数三星武器
/// </summary>
/// <param name="item">武器</param>
public void IncreaseBlue(IStatisticsItemSource item)
public void IncreaseBlue(IStatisticsItemConvertible item)
{
blueCounter.IncreaseOne(item);
++totalCountTracker;

View File

@@ -55,7 +55,7 @@ internal sealed class HutaoStatisticsFactory
foreach (ref readonly ItemCount item in CollectionsMarshal.AsSpan(items))
{
IStatisticsItemSource source = item.Item.StringLength() switch
IStatisticsItemConvertible source = item.Item.StringLength() switch
{
8U => context.GetAvatar(item.Item),
5U => context.GetWeapon(item.Item),

View File

@@ -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, ISummaryItemSource source, bool isUp)
public void Track(GachaItem item, ISummaryItemConvertible source, bool isUp)
{
if (!context.TypeEvaluator(item.GachaType))
{

View File

@@ -59,7 +59,7 @@ internal sealed class GachaLogServiceMetadataContext : IMetadataContext,
return result;
}
public INameQuality GetNameQualityByItemId(uint id)
public INameQualityAccess GetNameQualityByItemId(uint id)
{
uint place = id.StringLength();
return place switch

View File

@@ -0,0 +1,85 @@
// 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;
}
}

View File

@@ -4,44 +4,106 @@
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 readonly struct GameScreenCaptureContext
internal struct GameScreenCaptureContext : IDisposable
{
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;
[SuppressMessage("", "SH002")]
public GameScreenCaptureContext(IDirect3DDevice direct3DDevice, HWND hwnd)
{
this.direct3DDevice = direct3DDevice;
this.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)
{
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()
{
return Direct3D11CaptureFramePool.CreateFreeThreaded(direct3DDevice, DeterminePixelFormat(hwnd), 2, Item.Size);
(DirectXPixelFormat winrt, DXGI_FORMAT dx) = DeterminePixelFormat(hwnd);
CreateOrUpdateDXGISwapChain(dx);
return Direct3D11CaptureFramePool.CreateFreeThreaded(direct3DDevice, winrt, 2, Item.Size);
}
public void RecreatePool(Direct3D11CaptureFramePool framePool)
{
framePool.Recreate(direct3DDevice, DeterminePixelFormat(hwnd), 2, Item.Size);
(DirectXPixelFormat winrt, DXGI_FORMAT dx) = DeterminePixelFormat(hwnd);
CreateOrUpdateDXGISwapChain(dx);
framePool.Recreate(direct3DDevice, winrt, 2, Item.Size);
}
public GraphicsCaptureSession CreateSession(Direct3D11CaptureFramePool framePool)
public readonly GraphicsCaptureSession CreateSession(Direct3D11CaptureFramePool framePool)
{
GraphicsCaptureSession session = framePool.CreateCaptureSession(Item);
session.IsCursorCaptureEnabled = false;
@@ -49,7 +111,7 @@ internal readonly struct GameScreenCaptureContext
return session;
}
public bool TryGetClientBox(uint width, uint height, out D3D11_BOX clientBox)
public readonly bool TryGetClientBox(uint width, uint height, out D3D11_BOX clientBox)
{
clientBox = default;
@@ -88,8 +150,39 @@ internal readonly struct GameScreenCaptureContext
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 DeterminePixelFormat(HWND hwnd)
private static (DirectXPixelFormat WinRTFormat, DXGI_FORMAT DXFormat) DeterminePixelFormat(HWND hwnd)
{
HDC hdc = GetDC(hwnd);
if (hdc != HDC.NULL)
@@ -98,10 +191,31 @@ internal readonly struct GameScreenCaptureContext
_ = ReleaseDC(hwnd, hdc);
if (bitsPerPixel >= 32)
{
return DirectXPixelFormat.R16G16B16A16Float;
return (DirectXPixelFormat.R16G16B16A16Float, DXGI_FORMAT.DXGI_FORMAT_R16G16B16A16_FLOAT);
}
}
return DirectXPixelFormat.B8G8R8A8UIntNormalized;
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);
}
}

View File

@@ -0,0 +1,25 @@
// 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;
}
}

View File

@@ -0,0 +1,14 @@
// 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,
}

View File

@@ -0,0 +1,14 @@
<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>

View File

@@ -0,0 +1,47 @@
// 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);
}
}

Some files were not shown because too many files have changed in this diff Show More