Skip to content

Commit

Permalink
Make uninstalled-missing-source scan obey cancellation token when cal…
Browse files Browse the repository at this point in the history
…led from GetGames
  • Loading branch information
psychonic committed Jul 7, 2023
1 parent d2f3973 commit 46a9a0c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
9 changes: 5 additions & 4 deletions EmuLibrary/EmuLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Windows.Controls;

namespace EmuLibrary
Expand Down Expand Up @@ -138,7 +139,7 @@ public override IEnumerable<GameMetadata> GetGames(LibraryGetGamesArgs args)

if (Settings.AutoRemoveUninstalledGamesMissingFromSource)
{
RemoveSuperUninstalledGames(false);
RemoveSuperUninstalledGames(false, args.CancelToken);
}
}

Expand Down Expand Up @@ -175,7 +176,7 @@ public override IEnumerable<MainMenuItem> 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"
};
Expand Down Expand Up @@ -203,9 +204,9 @@ public override IEnumerable<GameMenuItem> 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;
Expand Down
6 changes: 4 additions & 2 deletions EmuLibrary/RomTypes/MultiFile/MultiFileScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;

namespace EmuLibrary.RomTypes.MultiFile
{
Expand Down Expand Up @@ -190,9 +191,10 @@ public override bool TryGetGameInfoBaseFromLegacyGameId(Game game, EmuLibrarySet
return true;
}

public override IEnumerable<Game> GetUninstalledGamesMissingSourceFiles()
public override IEnumerable<Game> 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;
Expand Down
3 changes: 2 additions & 1 deletion EmuLibrary/RomTypes/RomTypeScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Playnite.SDK.Plugins;
using System;
using System.Collections.Generic;
using System.Threading;

namespace EmuLibrary.RomTypes
{
Expand All @@ -17,6 +18,6 @@ internal abstract class RomTypeScanner

public abstract bool TryGetGameInfoBaseFromLegacyGameId(Game game, EmuLibrarySettings.ROMInstallerEmulatorMapping mapping, out ELGameInfo gameInfo);
public abstract IEnumerable<GameMetadata> GetGames(EmuLibrarySettings.ROMInstallerEmulatorMapping mapping, LibraryGetGamesArgs args);
public abstract IEnumerable<Game> GetUninstalledGamesMissingSourceFiles();
public abstract IEnumerable<Game> GetUninstalledGamesMissingSourceFiles(CancellationToken ct);
}
}
6 changes: 4 additions & 2 deletions EmuLibrary/RomTypes/SingleFile/SingleFileScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Runtime;
using System.Text.RegularExpressions;
using System.Threading;

namespace EmuLibrary.RomTypes.SingleFile
{
Expand Down Expand Up @@ -193,9 +194,10 @@ public override bool TryGetGameInfoBaseFromLegacyGameId(Game game, EmuLibrarySet
}
}

public override IEnumerable<Game> GetUninstalledGamesMissingSourceFiles()
public override IEnumerable<Game> 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;
Expand Down

0 comments on commit 46a9a0c

Please sign in to comment.