Skip to content

Commit

Permalink
Merge pull request #2110 from erri120/fix/2107
Browse files Browse the repository at this point in the history
Use mapped filesystem
  • Loading branch information
erri120 authored Oct 1, 2024
2 parents c9461de + cac7569 commit b97031c
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 13 deletions.
5 changes: 2 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<PackageVersion Include="AvaloniaEdit.TextMate" Version="11.1.0" />
<PackageVersion Include="FlatSharp.Compiler" Version="7.6.0" />
<PackageVersion Include="FlatSharp.Runtime" Version="7.6.0" />
<PackageVersion Include="GameFinder.Launcher.Heroic" Version="4.3.0" />
<PackageVersion Include="LinqGen" Version="0.3.1" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.8.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="8.0.0" />
Expand Down Expand Up @@ -121,7 +120,7 @@
<PackageVersion Include="BitFaster.Caching" Version="2.5.0" />
<PackageVersion Include="CliWrap" Version="3.6.6" />
<PackageVersion Include="DynamicData" Version="9.0.4" />
<PackageVersion Include="GameFinder" Version="4.3.0" />
<PackageVersion Include="GameFinder" Version="4.3.1" />
<PackageVersion Include="Humanizer" Version="2.14.1" />
<PackageVersion Include="ini-parser-netstandard" Version="2.5.2" />
<PackageVersion Include="Mutagen.Bethesda.Skyrim" Version="0.44.0" />
Expand All @@ -134,4 +133,4 @@
<PackageVersion Include="Splat.Microsoft.Extensions.Logging" Version="15.0.1" />
<PackageVersion Include="TransparentValueObjects" Version="1.0.1" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ namespace NexusMods.Abstractions.GameLocators;
/// which will stop the rest of the system from trying to find the version by other means (such as file analysis).
/// </summary>
/// <param name="Path">Full path to the folder which contains the game.</param>
/// <param name="GameFileSystem">Mapped filesystem of the game. This can either be the real filesystem or a WINE wrapper</param>
/// <param name="Store"><see cref="GameStore"/> which installed the game.</param>
/// <param name="Metadata">Metadata about the game.</param>
/// <param name="Version">Version of the game found.</param>
public record GameLocatorResult(AbsolutePath Path, GameStore Store, IGameLocatorResultMetadata Metadata, Version? Version = null);
public record GameLocatorResult(
AbsolutePath Path,
IFileSystem GameFileSystem,
GameStore Store,
IGameLocatorResultMetadata Metadata,
Version? Version = null
);
2 changes: 1 addition & 1 deletion src/Abstractions/NexusMods.Abstractions.Games/AGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected virtual ILoadoutSynchronizer MakeSynchronizer(IServiceProvider provide
/// <inheritdoc />
public GameInstallation InstallationFromLocatorResult(GameLocatorResult metadata, EntityId dbId, IGameLocator locator)
{
var locations = GetLocations(metadata.Path.FileSystem, metadata);
var locations = GetLocations(metadata.GameFileSystem, metadata);
return new GameInstallation
{
Game = this,
Expand Down
4 changes: 3 additions & 1 deletion src/NexusMods.StandardGameLocators/AGameLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public IEnumerable<GameLocatorResult> Find(ILocatableGame game)
foreach (var id in Ids(tg))
{
if (!_cachedGames.TryGetValue(id, out var found)) continue;
yield return new GameLocatorResult(Path(found), Store, CreateMetadata(found));
yield return new GameLocatorResult(Path(found), GetMappedFileSystem(found), Store, CreateMetadata(found));
}
}

Expand All @@ -119,6 +119,8 @@ public IEnumerable<GameLocatorResult> Find(ILocatableGame game)
/// <returns>Absolute path to game folder.</returns>
protected abstract AbsolutePath Path(TGameType record);

protected virtual IFileSystem GetMappedFileSystem(TGameType game) => Path(game).FileSystem;

/// <summary>
/// Creates <see cref="IGameLocatorResultMetadata"/> for the specific result.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/NexusMods.StandardGameLocators/HeroicGogLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ 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 HeroicGOGLocatorResultMetadata
var fs = found.Path.FileSystem;

if (found is HeroicGOGGame { WinePrefixPath.FileExists: true } heroicGOGGame)
{
fs = heroicGOGGame.GetWinePrefix().CreateOverlayFileSystem(fs);
}

yield return new GameLocatorResult(found.Path, fs, GameStore.GOG, new HeroicGOGLocatorResultMetadata
{
Id = id,
});
Expand Down
4 changes: 2 additions & 2 deletions src/NexusMods.StandardGameLocators/ManuallyAddedLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ManuallyAddedLocator(IServiceProvider provider, IFileSystem fileSystem)
var result = await tx.Commit();
var addedGame = result.Remap(ent);
var gameRegistry = _provider.GetRequiredService<IGameRegistry>();
var install = await gameRegistry.Register(game, new GameLocatorResult(path, GameStore.ManuallyAdded, addedGame, version), this);
var install = await gameRegistry.Register(game, new GameLocatorResult(path, path.FileSystem, GameStore.ManuallyAdded, addedGame, version), this);
var newId = result[ent.Id];
return (newId, install);
}
Expand All @@ -71,7 +71,7 @@ public async Task Remove(EntityId id)
public IEnumerable<GameLocatorResult> Find(ILocatableGame game)
{
var games = ManuallyAddedGame.FindByGameDomain(_conn.Value.Db, game.Domain)
.Select(g => new GameLocatorResult(_fileSystem.FromUnsanitizedFullPath(g.Path),
.Select(g => new GameLocatorResult(_fileSystem.FromUnsanitizedFullPath(g.Path), _fileSystem,
GameStore.ManuallyAdded, g, Version.Parse(g.Version)));
return games;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<ItemGroup>
<PackageReference Include="GameFinder" />
<PackageReference Include="GameFinder.Launcher.Heroic" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/NexusMods.StandardGameLocators/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ public static IServiceCollection AddStandardGameLocators(
{
CreateDelegateFor<GOGGame, IGogGame>(
(foundGame, requestedGame) => requestedGame.GogIds.Any(x => foundGame.Id.Equals(x)),
game => new GameLocatorResult(game.Path, GameStore.GOG, GogLocator.CreateMetadataCore(game))
game => new GameLocatorResult(game.Path, game.Path.FileSystem, GameStore.GOG, GogLocator.CreateMetadataCore(game))
),
CreateDelegateFor<EGSGame, IEpicGame>(
(foundGame, requestedGame) => requestedGame.EpicCatalogItemId.Any(x => foundGame.CatalogItemId.Equals(x)),
game => new GameLocatorResult(game.InstallLocation, GameStore.EGS, EpicLocator.CreateMetadataCore(game))
game => new GameLocatorResult(game.InstallLocation, game.InstallLocation.FileSystem, GameStore.EGS, EpicLocator.CreateMetadataCore(game))
),
CreateDelegateFor<OriginGame, IOriginGame>(
(foundGame, requestedGame) => requestedGame.OriginGameIds.Any(x => foundGame.Id.Equals(x)),
game => new GameLocatorResult(game.InstallPath, GameStore.Origin, OriginLocator.CreateMetadataCore(game))
game => new GameLocatorResult(game.InstallPath, game.InstallPath.FileSystem, GameStore.Origin, OriginLocator.CreateMetadataCore(game))
),
}
));
Expand Down
11 changes: 11 additions & 0 deletions src/NexusMods.StandardGameLocators/SteamLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ public SteamLocator(IServiceProvider provider) : base(provider) { }
/// <inheritdoc />
protected override AbsolutePath Path(SteamGame record) => record.Path;

/// <inheritdoc />
protected override IFileSystem GetMappedFileSystem(SteamGame game)
{
if (!OSInformation.Shared.IsLinux) return base.GetMappedFileSystem(game);

var protonPrefix = game.GetProtonPrefix();
if (protonPrefix is null) return base.GetMappedFileSystem(game);

return protonPrefix.CreateOverlayFileSystem(FileSystem.Shared);
}

/// <inheritdoc />
protected override IGameLocatorResultMetadata CreateMetadata(SteamGame game)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public IEnumerable<GameLocatorResult> Find(ILocatableGame game)

yield return new GameLocatorResult(
_path,
_path.Path.FileSystem,
GameStore.Unknown,
new UnknownLocatorResultMetadata(),
_version ?? new Version(1, 0, 0, 0));
Expand Down

0 comments on commit b97031c

Please sign in to comment.