Skip to content

Commit

Permalink
Create method to force dispose all routines in cached vaults
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Feb 6, 2025
1 parent 0f0ca1f commit 10ce3b1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions CollapseLauncher/Classes/GamePropertyVault.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using CollapseLauncher.Helper.Metadata;
using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Shared.ClassStruct;
using Microsoft.UI.Xaml;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -143,6 +145,35 @@ public static void DetachNotificationForCurrentRegion(int hashID = int.MinValue)
if (hashID < 0) hashID = CurrentGameHashID;
if (Vault.ContainsKey(hashID)) BackgroundActivityManager.Detach(hashID);
}

public static void SafeDisposeVaults()
{
int[] cachedPropertyKeys = Vault.Keys.ToArray();

int i = cachedPropertyKeys.Length;
while (i > 0)
{
try
{
if (Vault.Remove(cachedPropertyKeys[--i], out GamePresetProperty? value))
{
value.Dispose();
#if DEBUG
Logger.LogWriteLine($"[GamePropertyVault] A preset property at index: {i} for: {value.GamePreset.GameName} - {value.GamePreset.ZoneName} has been disposed!", LogType.Debug, true);
#endif
return;
}

#if DEBUG
Logger.LogWriteLine($"[GamePropertyVault] Cannot dispose the preset property as it cannot be detached from vault on index: {i}", LogType.Debug, true);
#endif
}
catch (Exception ex)
{
SentryHelper.ExceptionHandler(ex, SentryHelper.ExceptionType.UnhandledOther);
}
}
}
}

[SuppressMessage("ReSharper", "PartialTypeWithSinglePart")]
Expand Down

0 comments on commit 10ce3b1

Please sign in to comment.