diff --git a/EmuLibrary/EmuLibrary.cs b/EmuLibrary/EmuLibrary.cs index ce4b1ac..f0319fc 100644 --- a/EmuLibrary/EmuLibrary.cs +++ b/EmuLibrary/EmuLibrary.cs @@ -9,6 +9,7 @@ using System.IO; using System.Linq; using System.Reflection; +using System.Threading; using System.Windows.Controls; namespace EmuLibrary @@ -138,7 +139,7 @@ public override IEnumerable GetGames(LibraryGetGamesArgs args) if (Settings.AutoRemoveUninstalledGamesMissingFromSource) { - RemoveSuperUninstalledGames(false); + RemoveSuperUninstalledGames(false, args.CancelToken); } } @@ -175,7 +176,7 @@ public override IEnumerable GetMainMenuItems(GetMainMenuItemsArgs { yield return new MainMenuItem() { - Action = (arags) => RemoveSuperUninstalledGames(true), + Action = (arags) => RemoveSuperUninstalledGames(true, default), Description = "Remove uninstalled games with missing source file...", MenuSection = "EmuLibrary" }; @@ -203,9 +204,9 @@ public override IEnumerable GetGameMenuItems(GetGameMenuItemsArgs } } - private void RemoveSuperUninstalledGames(bool promptUser) + private void RemoveSuperUninstalledGames(bool promptUser, CancellationToken ct) { - var toRemove = _scanners.Values.SelectMany(s => s.GetUninstalledGamesMissingSourceFiles()); + var toRemove = _scanners.Values.SelectMany(s => s.GetUninstalledGamesMissingSourceFiles(ct)); if (toRemove.Any()) { System.Windows.MessageBoxResult res; diff --git a/EmuLibrary/RomTypes/MultiFile/MultiFileScanner.cs b/EmuLibrary/RomTypes/MultiFile/MultiFileScanner.cs index 91964b8..eda6bf9 100644 --- a/EmuLibrary/RomTypes/MultiFile/MultiFileScanner.cs +++ b/EmuLibrary/RomTypes/MultiFile/MultiFileScanner.cs @@ -9,6 +9,7 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; +using System.Threading; namespace EmuLibrary.RomTypes.MultiFile { @@ -190,9 +191,10 @@ public override bool TryGetGameInfoBaseFromLegacyGameId(Game game, EmuLibrarySet return true; } - public override IEnumerable GetUninstalledGamesMissingSourceFiles() + public override IEnumerable GetUninstalledGamesMissingSourceFiles(CancellationToken ct) { - return _playniteAPI.Database.Games.Where(g => + return _playniteAPI.Database.Games.TakeWhile(g => !ct.IsCancellationRequested) + .Where(g => { if (g.PluginId != EmuLibrary.PluginId || g.IsInstalled) return false; diff --git a/EmuLibrary/RomTypes/RomTypeScanner.cs b/EmuLibrary/RomTypes/RomTypeScanner.cs index a53c54f..40268f7 100644 --- a/EmuLibrary/RomTypes/RomTypeScanner.cs +++ b/EmuLibrary/RomTypes/RomTypeScanner.cs @@ -3,6 +3,7 @@ using Playnite.SDK.Plugins; using System; using System.Collections.Generic; +using System.Threading; namespace EmuLibrary.RomTypes { @@ -17,6 +18,6 @@ internal abstract class RomTypeScanner public abstract bool TryGetGameInfoBaseFromLegacyGameId(Game game, EmuLibrarySettings.ROMInstallerEmulatorMapping mapping, out ELGameInfo gameInfo); public abstract IEnumerable GetGames(EmuLibrarySettings.ROMInstallerEmulatorMapping mapping, LibraryGetGamesArgs args); - public abstract IEnumerable GetUninstalledGamesMissingSourceFiles(); + public abstract IEnumerable GetUninstalledGamesMissingSourceFiles(CancellationToken ct); } } diff --git a/EmuLibrary/RomTypes/SingleFile/SingleFileScanner.cs b/EmuLibrary/RomTypes/SingleFile/SingleFileScanner.cs index f40ee5a..9f2a5d4 100644 --- a/EmuLibrary/RomTypes/SingleFile/SingleFileScanner.cs +++ b/EmuLibrary/RomTypes/SingleFile/SingleFileScanner.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Runtime; using System.Text.RegularExpressions; +using System.Threading; namespace EmuLibrary.RomTypes.SingleFile { @@ -193,9 +194,10 @@ public override bool TryGetGameInfoBaseFromLegacyGameId(Game game, EmuLibrarySet } } - public override IEnumerable GetUninstalledGamesMissingSourceFiles() + public override IEnumerable GetUninstalledGamesMissingSourceFiles(CancellationToken ct) { - return _playniteAPI.Database.Games.Where(g => + return _playniteAPI.Database.Games.TakeWhile(g => !ct.IsCancellationRequested) + .Where(g => { if (g.PluginId != EmuLibrary.PluginId || g.IsInstalled) return false;