mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix cloud gacha download crash
This commit is contained in:
@@ -10,6 +10,20 @@ namespace Snap.Hutao.Extension;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static partial class EnumerableExtension
|
internal static partial class EnumerableExtension
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 尝试添加物品
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">物品类型</typeparam>
|
||||||
|
/// <param name="collection">集合</param>
|
||||||
|
/// <param name="item">物品</param>
|
||||||
|
public static void AddIfNotContains<T>(this Collection<T> collection, T item)
|
||||||
|
{
|
||||||
|
if (!collection.Contains(item))
|
||||||
|
{
|
||||||
|
collection.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 移除集合中满足条件的项
|
/// 移除集合中满足条件的项
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ internal sealed class GachaLogService : IGachaLogService
|
|||||||
{
|
{
|
||||||
if (archive == null)
|
if (archive == null)
|
||||||
{
|
{
|
||||||
archive = appDbContext.GachaArchives.SingleOrDefault(a => a.Uid == uid);
|
archive = appDbContext.GachaArchives.AsNoTracking().SingleOrDefault(a => a.Uid == uid);
|
||||||
|
|
||||||
if (archive == null)
|
if (archive == null)
|
||||||
{
|
{
|
||||||
@@ -320,7 +320,7 @@ internal sealed class GachaLogService : IGachaLogService
|
|||||||
|
|
||||||
// System.InvalidOperationException: Sequence contains no elements
|
// System.InvalidOperationException: Sequence contains no elements
|
||||||
// ? how this happen here?
|
// ? how this happen here?
|
||||||
archive = appDbContext.GachaArchives.Single(a => a.Uid == uid);
|
archive = appDbContext.GachaArchives.AsNoTracking().Single(a => a.Uid == uid);
|
||||||
GachaArchive temp = archive;
|
GachaArchive temp = archive;
|
||||||
ThreadHelper.InvokeOnMainThread(() => archiveCollection!.Add(temp));
|
ThreadHelper.InvokeOnMainThread(() => archiveCollection!.Add(temp));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ internal sealed class GachaLogViewModel : Abstraction.ViewModel
|
|||||||
if (isOk)
|
if (isOk)
|
||||||
{
|
{
|
||||||
await ThreadHelper.SwitchToMainThreadAsync();
|
await ThreadHelper.SwitchToMainThreadAsync();
|
||||||
|
Archives?.AddIfNotContains(archive!);
|
||||||
SetSelectedArchiveAndUpdateStatistics(archive, true);
|
SetSelectedArchiveAndUpdateStatistics(archive, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user