-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2103 from erri120/heroic
Find GOG games installed with the Heroic launcher
- Loading branch information
Showing
7 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using GameFinder.Launcher.Heroic; | ||
using GameFinder.StoreHandlers.GOG; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using NexusMods.Abstractions.GameLocators; | ||
using NexusMods.Abstractions.GameLocators.Stores.GOG; | ||
using NexusMods.Abstractions.Games.Stores.GOG; | ||
|
||
namespace NexusMods.StandardGameLocators; | ||
|
||
/// <summary> | ||
/// Find GOG games installed with the Heroic launcher. | ||
/// </summary> | ||
public class HeroicGogLocator : IGameLocator | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
private readonly HeroicGOGHandler _handler; | ||
private IReadOnlyDictionary<GOGGameId, GOGGame>? _cachedGames; | ||
|
||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
public HeroicGogLocator(IServiceProvider provider) | ||
{ | ||
_logger = provider.GetRequiredService<ILogger<HeroicGogLocator>>(); | ||
_handler = provider.GetRequiredService<HeroicGOGHandler>(); | ||
} | ||
|
||
public IEnumerable<GameLocatorResult> Find(ILocatableGame game) | ||
{ | ||
if (game is not IGogGame tg) yield break; | ||
|
||
if (_cachedGames is null) | ||
{ | ||
_cachedGames = _handler.FindAllGamesById(out var errors); | ||
if (errors.Any()) | ||
{ | ||
foreach (var error in errors) | ||
_logger.LogError("While looking for games: {Error}", error); | ||
} | ||
} | ||
|
||
foreach (var id in tg.GogIds) | ||
{ | ||
if (!_cachedGames.TryGetValue(GOGGameId.From(id), out var found)) continue; | ||
yield return new GameLocatorResult(found.Path, GameStore.GOG, new HeroicGOGLocatorResultMetadata | ||
{ | ||
Id = id, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters