add gacha import validation

This commit is contained in:
DismissedLight
2023-02-07 16:57:53 +08:00
parent 898d95bb1d
commit c245fe654e
9 changed files with 77 additions and 18 deletions

View File

@@ -427,7 +427,6 @@
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</ControlTemplate>
@@ -443,4 +442,4 @@
</ItemsPanelTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
</Application>

View File

@@ -49,8 +49,8 @@ public partial class App : Application
firstInstance.Activated += Activation.Activate;
ToastNotificationManagerCompat.OnActivated += Activation.NotificationActivate;
logger.LogInformation(EventIds.CommonLog, "Snap Hutao | {name} : {version}", CoreEnvironment.FamilyName, CoreEnvironment.Version);
logger.LogInformation(EventIds.CommonLog, "Cache folder : {folder}", ApplicationData.Current.LocalCacheFolder.Path);
logger.LogInformation("Snap Hutao | {name} : {version}", CoreEnvironment.FamilyName, CoreEnvironment.Version);
logger.LogInformation("Cache folder : {folder}", ApplicationData.Current.LocalCacheFolder.Path);
JumpListHelper.ConfigureAsync().SafeForget(logger);
}

View File

@@ -22,7 +22,7 @@ internal class BitsJob : DisposableObject, IBackgroundCopyCallback
/// </summary>
public const string JobNamePrefix = "SnapHutaoBitsJob";
private const uint BitsEngineNoProgressTimeout = 120;
private const uint BitsEngineNoProgressTimeout = 30;
private const int MaxResumeAttempts = 10;
private readonly string displayName;

View File

@@ -41,4 +41,21 @@ public class UIGF
{
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;
}
}

View File

@@ -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>
@@ -1617,6 +1626,15 @@ namespace Snap.Hutao.Resource.Localization {
}
}
/// <summary>
/// 查找类似 导入数据中包含了不支持的物品 的本地化字符串。
/// </summary>
internal static string ViewModelGachaLogImportWarningMessage2 {
get {
return ResourceManager.GetString("ViewModelGachaLogImportWarningMessage2", resourceCulture);
}
}
/// <summary>
/// 查找类似 导入失败 的本地化字符串。
/// </summary>

View File

@@ -297,6 +297,9 @@
<data name="ServiceGachaLogUrlProviderManualInputInvalid" xml:space="preserve">
<value>提供的 Url 无效</value>
</data>
<data name="ServiceGachaStatisticsFactoryItemIdInvalid" xml:space="preserve">
<value>不支持的 Item Id: {0}</value>
</data>
<data name="ServiceGameDetectGameAccountMultiMatched" xml:space="preserve">
<value>存在多个匹配账号,请删除重复的账号</value>
</data>
@@ -636,6 +639,9 @@
<data name="ViewModelGachaLogImportWarningMessage" xml:space="preserve">
<value>数据的 UIGF 版本过低,无法导入</value>
</data>
<data name="ViewModelGachaLogImportWarningMessage2" xml:space="preserve">
<value>导入数据中包含了不支持的物品</value>
</data>
<data name="ViewModelGachaLogImportWarningTitle" xml:space="preserve">
<value>导入失败</value>
</data>

View File

@@ -2,6 +2,7 @@
// Licensed under the MIT license.
using Snap.Hutao.Core.Database;
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Extension;
using Snap.Hutao.Model.Binding.Gacha;
using Snap.Hutao.Model.Entity;
@@ -137,7 +138,7 @@ internal class GachaStatisticsFactory : IGachaStatisticsFactory
{
// ItemId place not correct.
// TODO: check items id when importing
Must.NeverHappen();
ThrowHelper.UserdataCorrupted(string.Format(SH.ServiceGachaStatisticsFactoryItemIdInvalid, item.ItemId), null!);
}
}

View File

@@ -16,6 +16,7 @@ using Snap.Hutao.Model.Entity.Database;
using Snap.Hutao.Model.InterChange.GachaLog;
using Snap.Hutao.Model.Metadata.Abstraction;
using Snap.Hutao.Model.Primitive;
using Snap.Hutao.Service.Abstraction;
using Snap.Hutao.Service.GachaLog.Factory;
using Snap.Hutao.Service.GachaLog.QueryProvider;
using Snap.Hutao.Service.Metadata;
@@ -163,6 +164,7 @@ internal class GachaLogService : IGachaLogService
.Where(i => i.ArchiveId == archive.InnerId);
GachaStatistics statistics = await gachaStatisticsFactory.CreateAsync(items).ConfigureAwait(false);
logger.LogInformation(EventIds.GachaStatisticGeneration, "GachaStatistic Generation toke {time} ms.", stopwatch.GetElapsedTime().TotalMilliseconds);
return statistics;
}

View File

@@ -4,6 +4,7 @@
using CommunityToolkit.Mvvm.Input;
using Microsoft.UI.Xaml.Controls;
using Snap.Hutao.Control.Extension;
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Core.IO;
using Snap.Hutao.Extension;
using Snap.Hutao.Factory.Abstraction;
@@ -343,10 +344,18 @@ internal class GachaLogViewModel : Abstraction.ViewModel
private async Task UpdateStatisticsAsync(GachaArchive? archive)
{
GachaStatistics temp = await gachaLogService.GetStatisticsAsync(archive).ConfigureAwait(false);
await ThreadHelper.SwitchToMainThreadAsync();
Statistics = temp;
IsInitialized = true;
try
{
GachaStatistics? temp = await gachaLogService.GetStatisticsAsync(archive).ConfigureAwait(false);
await ThreadHelper.SwitchToMainThreadAsync();
Statistics = temp;
IsInitialized = true;
}
catch (UserdataCorruptedException ex)
{
Ioc.Default.GetRequiredService<IInfoBarService>().Error(ex);
}
}
private async Task<bool> TryImportUIGFInternalAsync(UIGF uigf)
@@ -357,16 +366,23 @@ internal class GachaLogViewModel : Abstraction.ViewModel
await ThreadHelper.SwitchToMainThreadAsync();
if (await new GachaLogImportDialog(uigf).GetShouldImportAsync().ConfigureAwait(true))
{
ContentDialog dialog = await contentDialogFactory.CreateForIndeterminateProgressAsync(SH.ViewModelGachaLogImportProgress).ConfigureAwait(true);
await using (await dialog.BlockAsync().ConfigureAwait(false))
if (uigf.IsValidList())
{
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);
await ThreadHelper.SwitchToMainThreadAsync();
SetSelectedArchiveAndUpdateStatistics(gachaLogService.CurrentArchive, true);
return true;
infoBarService.Success(SH.ViewModelGachaLogImportComplete);
await ThreadHelper.SwitchToMainThreadAsync();
SetSelectedArchiveAndUpdateStatistics(gachaLogService.CurrentArchive, true);
return true;
}
else
{
infoBarService.Warning(SH.ViewModelGachaLogImportWarningTitle, SH.ViewModelGachaLogImportWarningMessage2);
}
}
}
else