mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
add gacha import validation
This commit is contained in:
@@ -427,7 +427,6 @@
|
|||||||
</VisualState>
|
</VisualState>
|
||||||
|
|
||||||
</VisualStateGroup>
|
</VisualStateGroup>
|
||||||
|
|
||||||
</VisualStateManager.VisualStateGroups>
|
</VisualStateManager.VisualStateGroups>
|
||||||
</Border>
|
</Border>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
@@ -443,4 +442,4 @@
|
|||||||
</ItemsPanelTemplate>
|
</ItemsPanelTemplate>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
||||||
@@ -49,8 +49,8 @@ public partial class App : Application
|
|||||||
firstInstance.Activated += Activation.Activate;
|
firstInstance.Activated += Activation.Activate;
|
||||||
ToastNotificationManagerCompat.OnActivated += Activation.NotificationActivate;
|
ToastNotificationManagerCompat.OnActivated += Activation.NotificationActivate;
|
||||||
|
|
||||||
logger.LogInformation(EventIds.CommonLog, "Snap Hutao | {name} : {version}", CoreEnvironment.FamilyName, CoreEnvironment.Version);
|
logger.LogInformation("Snap Hutao | {name} : {version}", CoreEnvironment.FamilyName, CoreEnvironment.Version);
|
||||||
logger.LogInformation(EventIds.CommonLog, "Cache folder : {folder}", ApplicationData.Current.LocalCacheFolder.Path);
|
logger.LogInformation("Cache folder : {folder}", ApplicationData.Current.LocalCacheFolder.Path);
|
||||||
|
|
||||||
JumpListHelper.ConfigureAsync().SafeForget(logger);
|
JumpListHelper.ConfigureAsync().SafeForget(logger);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ internal class BitsJob : DisposableObject, IBackgroundCopyCallback
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const string JobNamePrefix = "SnapHutaoBitsJob";
|
public const string JobNamePrefix = "SnapHutaoBitsJob";
|
||||||
|
|
||||||
private const uint BitsEngineNoProgressTimeout = 120;
|
private const uint BitsEngineNoProgressTimeout = 30;
|
||||||
private const int MaxResumeAttempts = 10;
|
private const int MaxResumeAttempts = 10;
|
||||||
|
|
||||||
private readonly string displayName;
|
private readonly string displayName;
|
||||||
|
|||||||
@@ -41,4 +41,21 @@ public class UIGF
|
|||||||
{
|
{
|
||||||
return SupportedVersion.Contains(Info?.UIGFVersion ?? string.Empty);
|
return SupportedVersion.Contains(Info?.UIGFVersion ?? string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 列表物品是否正常
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>是否正常</returns>
|
||||||
|
public bool IsValidList()
|
||||||
|
{
|
||||||
|
foreach (UIGFItem item in List)
|
||||||
|
{
|
||||||
|
if (item.ItemType != "角色" || item.ItemType != "武器")
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -600,6 +600,15 @@ namespace Snap.Hutao.Resource.Localization {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 不支持的 Item Id: {0} 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
internal static string ServiceGachaStatisticsFactoryItemIdInvalid {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("ServiceGachaStatisticsFactoryItemIdInvalid", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 存在多个匹配账号,请删除重复的账号 的本地化字符串。
|
/// 查找类似 存在多个匹配账号,请删除重复的账号 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1617,6 +1626,15 @@ namespace Snap.Hutao.Resource.Localization {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 导入数据中包含了不支持的物品 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
internal static string ViewModelGachaLogImportWarningMessage2 {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("ViewModelGachaLogImportWarningMessage2", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 导入失败 的本地化字符串。
|
/// 查找类似 导入失败 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -297,6 +297,9 @@
|
|||||||
<data name="ServiceGachaLogUrlProviderManualInputInvalid" xml:space="preserve">
|
<data name="ServiceGachaLogUrlProviderManualInputInvalid" xml:space="preserve">
|
||||||
<value>提供的 Url 无效</value>
|
<value>提供的 Url 无效</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="ServiceGachaStatisticsFactoryItemIdInvalid" xml:space="preserve">
|
||||||
|
<value>不支持的 Item Id: {0}</value>
|
||||||
|
</data>
|
||||||
<data name="ServiceGameDetectGameAccountMultiMatched" xml:space="preserve">
|
<data name="ServiceGameDetectGameAccountMultiMatched" xml:space="preserve">
|
||||||
<value>存在多个匹配账号,请删除重复的账号</value>
|
<value>存在多个匹配账号,请删除重复的账号</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -636,6 +639,9 @@
|
|||||||
<data name="ViewModelGachaLogImportWarningMessage" xml:space="preserve">
|
<data name="ViewModelGachaLogImportWarningMessage" xml:space="preserve">
|
||||||
<value>数据的 UIGF 版本过低,无法导入</value>
|
<value>数据的 UIGF 版本过低,无法导入</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="ViewModelGachaLogImportWarningMessage2" xml:space="preserve">
|
||||||
|
<value>导入数据中包含了不支持的物品</value>
|
||||||
|
</data>
|
||||||
<data name="ViewModelGachaLogImportWarningTitle" xml:space="preserve">
|
<data name="ViewModelGachaLogImportWarningTitle" xml:space="preserve">
|
||||||
<value>导入失败</value>
|
<value>导入失败</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
using Snap.Hutao.Core.Database;
|
using Snap.Hutao.Core.Database;
|
||||||
|
using Snap.Hutao.Core.ExceptionService;
|
||||||
using Snap.Hutao.Extension;
|
using Snap.Hutao.Extension;
|
||||||
using Snap.Hutao.Model.Binding.Gacha;
|
using Snap.Hutao.Model.Binding.Gacha;
|
||||||
using Snap.Hutao.Model.Entity;
|
using Snap.Hutao.Model.Entity;
|
||||||
@@ -137,7 +138,7 @@ internal class GachaStatisticsFactory : IGachaStatisticsFactory
|
|||||||
{
|
{
|
||||||
// ItemId place not correct.
|
// ItemId place not correct.
|
||||||
// TODO: check items id when importing
|
// TODO: check items id when importing
|
||||||
Must.NeverHappen();
|
ThrowHelper.UserdataCorrupted(string.Format(SH.ServiceGachaStatisticsFactoryItemIdInvalid, item.ItemId), null!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using Snap.Hutao.Model.Entity.Database;
|
|||||||
using Snap.Hutao.Model.InterChange.GachaLog;
|
using Snap.Hutao.Model.InterChange.GachaLog;
|
||||||
using Snap.Hutao.Model.Metadata.Abstraction;
|
using Snap.Hutao.Model.Metadata.Abstraction;
|
||||||
using Snap.Hutao.Model.Primitive;
|
using Snap.Hutao.Model.Primitive;
|
||||||
|
using Snap.Hutao.Service.Abstraction;
|
||||||
using Snap.Hutao.Service.GachaLog.Factory;
|
using Snap.Hutao.Service.GachaLog.Factory;
|
||||||
using Snap.Hutao.Service.GachaLog.QueryProvider;
|
using Snap.Hutao.Service.GachaLog.QueryProvider;
|
||||||
using Snap.Hutao.Service.Metadata;
|
using Snap.Hutao.Service.Metadata;
|
||||||
@@ -163,6 +164,7 @@ internal class GachaLogService : IGachaLogService
|
|||||||
.Where(i => i.ArchiveId == archive.InnerId);
|
.Where(i => i.ArchiveId == archive.InnerId);
|
||||||
|
|
||||||
GachaStatistics statistics = await gachaStatisticsFactory.CreateAsync(items).ConfigureAwait(false);
|
GachaStatistics statistics = await gachaStatisticsFactory.CreateAsync(items).ConfigureAwait(false);
|
||||||
|
|
||||||
logger.LogInformation(EventIds.GachaStatisticGeneration, "GachaStatistic Generation toke {time} ms.", stopwatch.GetElapsedTime().TotalMilliseconds);
|
logger.LogInformation(EventIds.GachaStatisticGeneration, "GachaStatistic Generation toke {time} ms.", stopwatch.GetElapsedTime().TotalMilliseconds);
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Snap.Hutao.Control.Extension;
|
using Snap.Hutao.Control.Extension;
|
||||||
|
using Snap.Hutao.Core.ExceptionService;
|
||||||
using Snap.Hutao.Core.IO;
|
using Snap.Hutao.Core.IO;
|
||||||
using Snap.Hutao.Extension;
|
using Snap.Hutao.Extension;
|
||||||
using Snap.Hutao.Factory.Abstraction;
|
using Snap.Hutao.Factory.Abstraction;
|
||||||
@@ -343,10 +344,18 @@ internal class GachaLogViewModel : Abstraction.ViewModel
|
|||||||
|
|
||||||
private async Task UpdateStatisticsAsync(GachaArchive? archive)
|
private async Task UpdateStatisticsAsync(GachaArchive? archive)
|
||||||
{
|
{
|
||||||
GachaStatistics temp = await gachaLogService.GetStatisticsAsync(archive).ConfigureAwait(false);
|
try
|
||||||
await ThreadHelper.SwitchToMainThreadAsync();
|
{
|
||||||
Statistics = temp;
|
GachaStatistics? temp = await gachaLogService.GetStatisticsAsync(archive).ConfigureAwait(false);
|
||||||
IsInitialized = true;
|
|
||||||
|
await ThreadHelper.SwitchToMainThreadAsync();
|
||||||
|
Statistics = temp;
|
||||||
|
IsInitialized = true;
|
||||||
|
}
|
||||||
|
catch (UserdataCorruptedException ex)
|
||||||
|
{
|
||||||
|
Ioc.Default.GetRequiredService<IInfoBarService>().Error(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> TryImportUIGFInternalAsync(UIGF uigf)
|
private async Task<bool> TryImportUIGFInternalAsync(UIGF uigf)
|
||||||
@@ -357,16 +366,23 @@ internal class GachaLogViewModel : Abstraction.ViewModel
|
|||||||
await ThreadHelper.SwitchToMainThreadAsync();
|
await ThreadHelper.SwitchToMainThreadAsync();
|
||||||
if (await new GachaLogImportDialog(uigf).GetShouldImportAsync().ConfigureAwait(true))
|
if (await new GachaLogImportDialog(uigf).GetShouldImportAsync().ConfigureAwait(true))
|
||||||
{
|
{
|
||||||
ContentDialog dialog = await contentDialogFactory.CreateForIndeterminateProgressAsync(SH.ViewModelGachaLogImportProgress).ConfigureAwait(true);
|
if (uigf.IsValidList())
|
||||||
await using (await dialog.BlockAsync().ConfigureAwait(false))
|
|
||||||
{
|
{
|
||||||
await gachaLogService.ImportFromUIGFAsync(uigf.List, uigf.Info.Uid).ConfigureAwait(false);
|
ContentDialog dialog = await contentDialogFactory.CreateForIndeterminateProgressAsync(SH.ViewModelGachaLogImportProgress).ConfigureAwait(true);
|
||||||
}
|
await using (await dialog.BlockAsync().ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
await gachaLogService.ImportFromUIGFAsync(uigf.List, uigf.Info.Uid).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
infoBarService.Success(SH.ViewModelGachaLogImportComplete);
|
infoBarService.Success(SH.ViewModelGachaLogImportComplete);
|
||||||
await ThreadHelper.SwitchToMainThreadAsync();
|
await ThreadHelper.SwitchToMainThreadAsync();
|
||||||
SetSelectedArchiveAndUpdateStatistics(gachaLogService.CurrentArchive, true);
|
SetSelectedArchiveAndUpdateStatistics(gachaLogService.CurrentArchive, true);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
infoBarService.Warning(SH.ViewModelGachaLogImportWarningTitle, SH.ViewModelGachaLogImportWarningMessage2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user