Skip to content

Commit

Permalink
Run through heroic
Browse files Browse the repository at this point in the history
  • Loading branch information
erri120 committed Sep 29, 2024
1 parent d56347f commit 2f09c04
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ public record GOGLocatorResultMetadata : IGameLocatorResultMetadata
/// </summary>
public required long Id { get; init; }
}

[PublicAPI]
public record HeroicGOGLocatorResultMetadata : GOGLocatorResultMetadata;
23 changes: 20 additions & 3 deletions src/Abstractions/NexusMods.Abstractions.Games/RunGameTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.Games.DTO;
using NexusMods.Abstractions.Games.Stores.GOG;
using NexusMods.Abstractions.Games.Stores.Steam;
using NexusMods.Abstractions.Loadouts;
using NexusMods.CrossPlatform.Process;
Expand Down Expand Up @@ -60,10 +61,18 @@ public async Task Execute(Loadout.ReadOnly loadout, CancellationToken cancellati
var program = await GetGamePath(loadout);
var primaryFile = _game.GetPrimaryFile(loadout.InstallationInstance.Store).CombineChecked(loadout.InstallationInstance);

if (OSInformation.Shared.IsLinux && program.Equals(primaryFile) && loadout.InstallationInstance.LocatorResultMetadata is SteamLocatorResultMetadata steamLocatorResultMetadata)
if (OSInformation.Shared.IsLinux && program.Equals(primaryFile))
{
await RunThroughSteam(steamLocatorResultMetadata.AppId, cancellationToken);
return;
var locator = loadout.InstallationInstance.LocatorResultMetadata;
switch (locator)
{
case SteamLocatorResultMetadata steamLocatorResultMetadata:
await RunThroughSteam(steamLocatorResultMetadata.AppId, cancellationToken);
return;
case HeroicGOGLocatorResultMetadata heroicGOGLocatorResultMetadata:
await RunThroughHeroic("gog", heroicGOGLocatorResultMetadata.Id, cancellationToken);
return;
}
}

var names = new HashSet<string>
Expand Down Expand Up @@ -177,6 +186,14 @@ private async Task RunThroughSteam(uint appId, CancellationToken cancellationTok
await reaper.WaitForExitAsync(cancellationToken);
}

private async Task RunThroughHeroic(string type, long appId, CancellationToken cancellationToken)
{
Debug.Assert(OSInformation.Shared.IsLinux);

// TODO: track process
await _osInterop.OpenUrl(new Uri($"heroic://launch/{type}/{appId.ToString(CultureInfo.InvariantCulture)}"), fireAndForget: false, cancellationToken: cancellationToken);
}

private async ValueTask<Process?> WaitForProcessToStart(
string processName,
TimeSpan timeout,
Expand Down
2 changes: 1 addition & 1 deletion src/NexusMods.StandardGameLocators/HeroicGogLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public IEnumerable<GameLocatorResult> Find(ILocatableGame game)
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 GOGLocatorResultMetadata
yield return new GameLocatorResult(found.Path, GameStore.GOG, new HeroicGOGLocatorResultMetadata
{
Id = id,
});
Expand Down

0 comments on commit 2f09c04

Please sign in to comment.