Skip to content

Commit

Permalink
Merge pull request #2152 from Nexus-Mods/migrate-more-to-v2
Browse files Browse the repository at this point in the history
Migrate everything possible to V2 APIs
  • Loading branch information
Sewer56 authored Oct 10, 2024
2 parents 9a378cf + 18ebf39 commit 05b1c4c
Show file tree
Hide file tree
Showing 87 changed files with 670 additions and 761 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json.Serialization;
using NexusMods.Abstractions.Games.DTO;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.NexusWebApi.Types;

namespace NexusMods.Abstractions.Collections.Json;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
using NexusMods.Abstractions.Games.DTO;
using NexusMods.Paths;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.NexusWebApi.Types;
using NexusMods.Abstractions.NexusWebApi.Types.V2;

namespace NexusMods.Abstractions.Collections.Json;
Expand Down
23 changes: 0 additions & 23 deletions src/Abstractions/NexusMods.Abstractions.GameLocators/GameDomain.cs

This file was deleted.

43 changes: 43 additions & 0 deletions src/Abstractions/NexusMods.Abstractions.GameLocators/GamePath.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Diagnostics;
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.MnemonicDB.Abstractions.Attributes;
using NexusMods.MnemonicDB.Abstractions.ElementComparers;
using NexusMods.Paths;
using NexusMods.Paths.Extensions;

Expand Down Expand Up @@ -130,3 +133,43 @@ public int CompareTo(GamePath other)
/// </summary>
public (EntityId, LocationId, RelativePath) ToGamePathParentTuple(EntityId id) => (id, LocationId, Path);
}

/// <summary>
/// Defines a GamePath attribute.
/// </summary>
public class GamePathAttribute(string ns, string name) : ScalarAttribute<GamePath, string>(ValueTags.Utf8, ns, name)
{
/// <inheritdoc />
protected override string ToLowLevel(GamePath value)
{
// TODO: make this a reference or something
return $"{value.LocationId.Value}|{value.Path}";
}

/// <inheritdoc />
protected override GamePath FromLowLevel(string value, ValueTags tags, AttributeResolver resolver)
{
var parts = value.Split('|');
Debug.Assert(parts.Length == 2);
return new GamePath(LocationId.From(parts[0]), RelativePath.FromUnsanitizedInput(parts[1]));
}
}

/// <summary>
/// An attribute that combines an EntityId, LocationId and RelativePath into a single attribute. This is used to represent GamePaths prefixed
/// with a parent entity so that range queries only return the paths that are children of the parent entity.
/// </summary>
public class GamePathParentAttribute(string ns, string name) : TupleAttribute<EntityId, ulong, LocationId, ushort, RelativePath, string>(ValueTags.Reference, ValueTags.UInt16, ValueTags.Utf8, ns, name)
{
/// <inheritdoc />
protected override (EntityId, LocationId, RelativePath) FromLowLevel((ulong, ushort, string) value)
{
return (EntityId.From(value.Item1), LocationId.From(value.Item2), RelativePath.FromUnsanitizedInput(value.Item3));
}

/// <inheritdoc />
protected override (ulong, ushort, string) ToLowLevel((EntityId, LocationId, RelativePath) value)
{
return (value.Item1.Value, value.Item2.Value, value.Item3);
}
}
21 changes: 21 additions & 0 deletions src/Abstractions/NexusMods.Abstractions.GameLocators/GameStore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.MnemonicDB.Abstractions.Attributes;
using NexusMods.MnemonicDB.Abstractions.ElementComparers;
using TransparentValueObjects;

namespace NexusMods.Abstractions.GameLocators;
Expand Down Expand Up @@ -52,3 +55,21 @@ public readonly partial struct GameStore
/// </summary>
public static readonly GameStore ManuallyAdded = From("Manually Added");
}

/// <summary>
/// An attribute that contains the name of a game store.
/// </summary>
public class GameStoreAttribute(string ns, string name) : ScalarAttribute<GameStore, string>(ValueTags.Ascii, ns, name)
{
/// <inheritdoc />
protected override string ToLowLevel(GameStore value)
{
return value.Value;
}

/// <inheritdoc />
protected override GameStore FromLowLevel(string value, ValueTags tag, AttributeResolver resolver)
{
return GameStore.From(value);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NexusMods.Abstractions.Games.DTO;

using NexusMods.Abstractions.NexusWebApi.Types.V2;
namespace NexusMods.Abstractions.GameLocators;

/// <summary>
Expand All @@ -11,13 +10,23 @@ public interface ILocatableGame
/// Human readable name of the game.
/// </summary>
public string Name { get; }

/// <summary>
/// Machine friendly name for the game, should be devoid of special characters
/// that may conflict with URLs or file paths.
/// Unique identifier for the game.
/// This ID can be obtained from the V2 API.
/// </summary>
/// <remarks>
/// Usually we match these with NexusMods' URLs.
/// This can be obtained with a V2 call like:
///
/// ```
/// query Game {
/// game(domainName: "site") {
/// id
/// }
/// }
///
/// To https://api.nexusmods.com/v2/graphql
/// ```
/// </remarks>
public GameDomain Domain { get; }
public GameId GameId { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Extensions\NexusMods.Extensions.Hashing\NexusMods.Extensions.Hashing.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.NexusWebApi\NexusMods.Abstractions.NexusWebApi.csproj" />
</ItemGroup>

</Project>
5 changes: 3 additions & 2 deletions src/Abstractions/NexusMods.Abstractions.Games/AGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NexusMods.Abstractions.IO;
using NexusMods.Abstractions.Library.Installers;
using NexusMods.Abstractions.Loadouts.Synchronizers;
using NexusMods.Abstractions.NexusWebApi.Types.V2;
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.Paths;

Expand Down Expand Up @@ -44,9 +45,9 @@ protected virtual ILoadoutSynchronizer MakeSynchronizer(IServiceProvider provide

/// <inheritdoc />
public abstract string Name { get; }

/// <inheritdoc />
public abstract GameDomain Domain { get; }
public abstract GameId GameId { get; }

/// <summary>
/// The path to the main executable file for the game.
Expand Down
6 changes: 3 additions & 3 deletions src/Abstractions/NexusMods.Abstractions.Games/RunGameTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using Microsoft.Extensions.DependencyInjection;
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.Abstractions.NexusWebApi.Types.V2;
using NexusMods.CrossPlatform.Process;
using NexusMods.Paths;

Expand Down Expand Up @@ -48,7 +48,7 @@ public RunGameTool(IServiceProvider serviceProvider, T game)
}

/// <inheritdoc />
public IEnumerable<GameDomain> Domains => new[] { _game.Domain };
public IEnumerable<GameId> GameIds => [_game.GameId];

/// <inheritdoc />
public string Name => $"Run {_game.Name}";
Expand Down Expand Up @@ -100,7 +100,7 @@ public async Task Execute(Loadout.ReadOnly loadout, CancellationToken cancellati
}
else
{
var result = await RunCommand(cancellationToken, program);
_ = await RunCommand(cancellationToken, program);
}

// Check if the process has spawned any new processes that we need to wait for (e.g. Launcher -> Game)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.Loadouts.Mods;
using NexusMods.Abstractions.MnemonicDB.Attributes;
using NexusMods.MnemonicDB.Abstractions.Attributes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using NexusMods.Abstractions.DiskState;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.MnemonicDB.Attributes;
using NexusMods.Abstractions.NexusWebApi.Types.V2;
using NexusMods.MnemonicDB.Abstractions.Attributes;
using NexusMods.MnemonicDB.Abstractions.BuiltInEntities;
using NexusMods.MnemonicDB.Abstractions.Models;
Expand All @@ -13,11 +15,17 @@ namespace NexusMods.Abstractions.Loadouts;
public partial class GameInstallMetadata : IModelDefinition
{
private const string Namespace = "NexusMods.Abstractions.Loadouts.GameMetadata";

/// <summary>
/// The game's unique id.
/// </summary>
public static readonly GameIdAttribute GameId = new(Namespace, nameof(GameId));

/// <summary>
/// The game's domain.
/// User friendly name for the game.
/// May be referred to from diagnostics, telemetry or otherwise.
/// </summary>
public static readonly GameDomainAttribute Domain = new(Namespace, "Domain");
public static readonly StringAttribute Name = new(Namespace, nameof(Name));

/// <summary>
/// The name of the store the game is from
Expand Down
7 changes: 4 additions & 3 deletions src/Abstractions/NexusMods.Abstractions.Loadouts/ITool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NexusMods.Abstractions.Games.DTO;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.NexusWebApi.Types.V2;

namespace NexusMods.Abstractions.Loadouts;

Expand All @@ -9,9 +10,9 @@ namespace NexusMods.Abstractions.Loadouts;
public interface ITool
{
/// <summary>
/// List of supported game IDs (domains).
/// List of supported game IDs.
/// </summary>
public IEnumerable<GameDomain> Domains { get; }
public IEnumerable<GameId> GameIds { get; }

/// <summary>
/// Human friendly name of the tool.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public GameInstallation InstallationInstance
{
var registry = Db.Connection.ServiceProvider.GetRequiredService<IGameRegistry>();
if (!registry.Installations.TryGetValue(Loadout.Installation.Get(this), out var gameInstallation))
throw new KeySelectorException($"Game installation of `{Installation.Domain}` at `{Installation.Path}` not found in registry!");
throw new KeySelectorException($"Game installation of `{Installation.GameId}` at `{Installation.Path}` not found in registry!");
return gameInstallation;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using JetBrains.Annotations;
using NexusMods.Abstractions.Library.Models;
using NexusMods.Abstractions.MnemonicDB.Attributes;
using NexusMods.MnemonicDB.Abstractions.Attributes;
using NexusMods.MnemonicDB.Abstractions.Models;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JetBrains.Annotations;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.MnemonicDB.Attributes;
using NexusMods.MnemonicDB.Abstractions.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ProjectReference Include="..\NexusMods.Abstractions.GameLocators\NexusMods.Abstractions.GameLocators.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.Library.Models\NexusMods.Abstractions.Library.Models.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.MnemonicDB.Analyzers\NexusMods.Abstractions.MnemonicDB.Analyzers.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.NexusWebApi\NexusMods.Abstractions.NexusWebApi.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.Serialization\NexusMods.Abstractions.Serialization.csproj" />
<PackageReference Include="NexusMods.MnemonicDB.Abstractions" />
<PackageReference Include="TransparentValueObjects" PrivateAssets="all" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 05b1c4c

Please sign in to comment.