Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AET.SteamAbstraction/Library/SteamLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public SteamLibrary(IDirectoryInfo libraryLocation, IServiceProvider serviceProv
public IEnumerable<SteamAppManifest> GetApps()
{
if (!SteamAppsLocation.Exists)
return Array.Empty<SteamAppManifest>();
return [];
var apps = new HashSet<SteamAppManifest>();
foreach (var manifestFile in SteamAppsLocation.EnumerateFiles("*.acf", SearchOption.TopDirectoryOnly))
{
Expand Down
9 changes: 4 additions & 5 deletions src/AET.SteamAbstraction/Library/SteamLibraryFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ internal sealed class SteamLibraryFinder(IServiceProvider serviceProvider) : ISt

public IEnumerable<ISteamLibrary> FindLibraries(IDirectoryInfo steamInstallDir)
{
_logger?.LogTrace("Searching for Steam libraries on system");
_logger?.LogTrace("Searching for Steam libraries on system...");
var libraryLocationsFile = GetLibraryLocationsFile(steamInstallDir);

if (!libraryLocationsFile.Exists)
{
_logger?.LogWarning("Config file with Steam libraries not found. No Steam libraries are created.");
return Array.Empty<ISteamLibrary>();
_logger?.LogTrace("Config file that should contain Steam libraries information is not found.");
return [];
}

var libraryLocations = SteamVdfReader.ReadLibraryLocationsFromConfig(libraryLocationsFile);
Expand Down Expand Up @@ -75,8 +75,7 @@ private bool TryCreateLibraryFromLocation(IDirectoryInfo libraryLocation, bool i
var libraryVdf = _fileSystem.Path.Combine(libraryLocation.FullName, libraryVdfSubPath, libraryVdfName);
if (!_fileSystem.File.Exists(libraryVdf))
{
_logger?.LogTrace(
$"Steam library VDF file '{libraryVdf}' was not found. Library not created.");
_logger?.LogTrace($"Steam library VDF file '{libraryVdf}' was not found. Library not created.");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected override GameLocationData FindGameLocation(GameType gameType)
Debug.Assert(registry.Type == gameType);
if (registry.Version is null)
{
Logger?.LogDebug("Registry-Key found, but games are not initialized.");
Logger?.LogTrace("Registry-Key found, but games are not initialized.");
return GameLocationData.RequiresInitialization;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public IGameProcess StartGameProcess(IFileInfo executable, GameProcessInfo proce
{
var arguments = ArgumentCommandLineBuilder.BuildCommandLine(processInfo.Arguments);

_logger?.LogInformation($"Starting game '{processInfo.Game}' in '{processInfo.BuildType}' configuration and with launch arguments '{arguments}'");
_logger?.LogDebug(
$"Starting game '{processInfo.Game}' with '{processInfo.BuildType}' configuration and with launch arguments '{arguments}'");

var processStartInfo = new ProcessStartInfo(executable.FullName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="semver" Version="3.0.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.72" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.74" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
<PackageReference Include="QuikGraph" Version="2.5.0" PrivateAssets="compile" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PG.StarWarsGame.Infrastructure.Games;
Expand Down Expand Up @@ -38,7 +37,7 @@ public CompositeGameDetector(IList<IGameDetector> sortedDetectors, IServiceProvi
if (serviceProvider == null)
throw new ArgumentNullException(nameof(serviceProvider));
ThrowHelper.ThrowIfCollectionNullOrEmptyOrContainsNull(sortedDetectors);
SortedDetectors = sortedDetectors.ToList();
SortedDetectors = [.. sortedDetectors];
_logger = serviceProvider.GetService<ILoggerFactory>()?.CreateLogger(GetType());
_disposeDetectors = disposeDetectors;
}
Expand All @@ -57,19 +56,21 @@ public GameDetectionResult Detect(GameType gameType, params ICollection<GamePlat
GameDetectionResult? lastResult = null;
foreach (var detector in SortedDetectors)
{
_logger?.LogDebug($"Searching for game {gameType} with detector: {detector}");
_logger?.LogTrace($"Searching for game '{gameType}' with detector: '{detector}'");
detector.InitializationRequested += PassThroughInitializationRequest;

try
{
var result = detector.Detect(gameType, platforms);
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
// because this is public API, and we cannot guarantee that the result is not null
if (result is not null && result.Installed)
return result;
lastResult = result;
}
catch (Exception e)
{
_logger?.LogTrace($"Failed detecting game using detector {detector}. {e}");
_logger?.LogDebug($"Failed detecting game using detector {detector}. {e}");
errors.Add(e);

if (detector.Equals(SortedDetectors[^1]))
Expand Down Expand Up @@ -108,7 +109,7 @@ public bool TryDetect(GameType gameType, ICollection<GamePlatform> platforms, ou
}
catch (Exception e)
{
_logger?.LogWarning(e, "Unable to find any games, due to error in detection.");
_logger?.LogDebug(e, "Unable to find any games, due to error in detection.");
result = GameDetectionResult.NotInstalled(gameType);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,19 @@ namespace PG.StarWarsGame.Infrastructure.Services.Detection;
/// <remarks>
/// This detector does not support game initialization requests.
/// </remarks>
public sealed class DirectoryGameDetector : GameDetectorBase
/// <remarks>
/// Creates a new instance of the <see cref="DirectoryGameDetector"/> class.
/// </remarks>
/// <param name="directory">The directory to search for an installation.</param>
/// <param name="serviceProvider">The service provider.</param>
public sealed class DirectoryGameDetector(IDirectoryInfo directory, IServiceProvider serviceProvider) : GameDetectorBase(serviceProvider, false)
{
private readonly IDirectoryInfo _directory;

/// <summary>
/// Creates a new instance of the <see cref="DirectoryGameDetector"/> class.
/// </summary>
/// <param name="directory">The directory to search for an installation.</param>
/// <param name="serviceProvider">The service provider.</param>
public DirectoryGameDetector(IDirectoryInfo directory, IServiceProvider serviceProvider) : base(serviceProvider, false)
{
_directory = directory ?? throw new ArgumentNullException(nameof(directory));
}
private readonly IDirectoryInfo _directory = directory ?? throw new ArgumentNullException(nameof(directory));

/// <inheritdoc/>
protected override GameLocationData FindGameLocation(GameType gameType)
{
Logger?.LogDebug($"Searching for game {gameType} at directory: {_directory}");
Logger?.LogTrace($"Searching for game {gameType} at directory: {_directory}");
return !MinimumGameFilesExist(gameType, _directory) ? GameLocationData.NotInstalled : new GameLocationData(_directory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO.Abstractions;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PG.StarWarsGame.Infrastructure.Games;
Expand Down Expand Up @@ -62,7 +61,7 @@ public bool TryDetect(GameType gameType, ICollection<GamePlatform> platforms, ou
}
catch (Exception e)
{
Logger?.LogWarning(e, "Unable to find any games, due to error in detection.");
Logger?.LogDebug(e, "Unable to find any games, due to error in detection.");
result = GameDetectionResult.NotInstalled(gameType);
return false;
}
Expand All @@ -77,7 +76,7 @@ public GameDetectionResult Detect(GameType gameType, params ICollection<GamePlat

if (!locationData.IsInstalled)
{
Logger?.LogInformation($"Unable to find an installed game of type {gameType}.");
Logger?.LogTrace($"Unable to find an installed game of type {gameType}.");
return GameDetectionResult.NotInstalled(gameType);
}

Expand All @@ -92,20 +91,20 @@ public GameDetectionResult Detect(GameType gameType, params ICollection<GamePlat
// the detector returned a false result.
if (!GameExeExists(location, gameType) || !DataAndMegaFilesXmlExists(location))
{
Logger?.LogDebug($"Unable to find the game's executable or megafiles.xml at the given location: {location.FullName}");
Logger?.LogTrace($"Unable to find the game's executable or megafiles.xml at the given location: {location.FullName}");
return GameDetectionResult.NotInstalled(gameType);
}

if (!MatchesOptionsPlatform(platforms, actualPlatform))
{
var wrongGameFound = GameDetectionResult.NotInstalled(gameType);
Logger?.LogInformation($"Game detected at location: {wrongGameFound.GameLocation?.FullName} " +
Logger?.LogTrace($"Game detected at location: {wrongGameFound.GameLocation?.FullName} " +
$"but Platform {actualPlatform} was not requested.");
return wrongGameFound;
}

var detectedResult = GameDetectionResult.FromInstalled(new GameIdentity(gameType, actualPlatform), location);
Logger?.LogInformation($"Game detected: {detectedResult.GameIdentity} at location: {location.FullName}");
Logger?.LogDebug($"Game detected: {detectedResult.GameIdentity} at location: '{location.FullName}'");
return detectedResult;
}

Expand Down Expand Up @@ -167,7 +166,7 @@ private bool HandleInitialization(GameType gameType, ref GameLocationData locati
if (!locationData.InitializationRequired)
return true;

Logger?.LogDebug($"It appears that the game '{locationData.ToString()}' exists but it is not initialized. Game type '{gameType}'.");
Logger?.LogDebug($"It appears that the game '{locationData}' exists but it is not initialized. Game type '{gameType}'.");
if (!_tryHandleInitialization)
return false;

Expand All @@ -189,17 +188,21 @@ private bool RequestInitialization(GameType gameType)
return request.Handled;
}

private static IList<GamePlatform> NormalizePlatforms(ICollection<GamePlatform> platforms)
private static HashSet<GamePlatform> NormalizePlatforms(ICollection<GamePlatform> platforms)
{
if (platforms.Count == 0 || platforms.Contains(GamePlatform.Undefined))
return [GamePlatform.Undefined];
return platforms.Distinct().ToList();
return [..platforms];
}

/// <summary>
/// Represents location and initialization state of a game.
/// </summary>
public readonly struct GameLocationData
/// <remarks>
/// Initializes a new instance of the <see cref="GameLocationData"/> struct of the specified game location.
/// </remarks>
/// <param name="location">The detected game location or <see langword="null"/> if no game was detected.</param>
public readonly struct GameLocationData(IDirectoryInfo? location)
{
/// <summary>
/// Gets a <see cref="GameLocationData"/> representing a not installed location.
Expand All @@ -211,19 +214,10 @@ public readonly struct GameLocationData
/// </summary>
public static readonly GameLocationData RequiresInitialization = new() { InitializationRequired = true };

/// <summary>
/// Initializes a new instance of the <see cref="GameLocationData"/> struct of the specified game location.
/// </summary>
/// <param name="location">The detected game location or <see langword="null"/> if no game was detected.</param>
public GameLocationData(IDirectoryInfo? location)
{
Location = location;
}

/// <summary>
/// Nullable location entry.
/// </summary>
public IDirectoryInfo? Location { get; }
public IDirectoryInfo? Location { get; } = location;

/// <summary>
/// Indicates whether an initialization is required.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ namespace PG.StarWarsGame.Infrastructure.Services.Detection.Platform;
/// <summary>
/// Default implementation of the <see cref="IGamePlatformIdentifier"/> service.
/// </summary>
internal sealed class GamePlatformIdentifier : IGamePlatformIdentifier
/// <remarks>
/// Creates a new instance.
/// </remarks>
/// <param name="serviceProvider">Service Provider</param>
internal sealed class GamePlatformIdentifier(IServiceProvider serviceProvider) : IGamePlatformIdentifier
{
private readonly IServiceProvider _serviceProvider;
private readonly ILogger? _logger;
private readonly IServiceProvider _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
private readonly ILogger? _logger = serviceProvider.GetService<ILoggerFactory>()?.CreateLogger(typeof(GamePlatformIdentifier));

/// <summary>
/// Default ordering of <see cref="GamePlatform"/>s for identification.
Expand All @@ -31,16 +35,6 @@ internal sealed class GamePlatformIdentifier : IGamePlatformIdentifier
GamePlatform.Disk
];

/// <summary>
/// Creates a new instance.
/// </summary>
/// <param name="serviceProvider">Service Provider</param>
public GamePlatformIdentifier(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
_logger = serviceProvider.GetService<ILoggerFactory>()?.CreateLogger(typeof(GamePlatformIdentifier));
}

/// <inheritdoc/>
public GamePlatform GetGamePlatform(GameType type, ref IDirectoryInfo location)
{
Expand All @@ -49,15 +43,15 @@ public GamePlatform GetGamePlatform(GameType type, ref IDirectoryInfo location)
foreach (var platform in DefaultGamePlatformOrdering)
{
var validator = GamePlatformIdentifierFactory.Create(platform, _serviceProvider);
_logger?.LogDebug($"Validating location for {platform}...");
_logger?.LogTrace($"Validating location for {platform}...");
if (!validator.IsPlatform(type, ref location))
continue;

_logger?.LogDebug($"Game location was identified as {platform}.");
_logger?.LogTrace($"Game location was identified as {platform}.");
return platform;
}

_logger?.LogDebug("Unable to determine which which platform the game has.");
_logger?.LogTrace("Unable to determine which which platform the game has.");
return GamePlatform.Undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public override bool IsPlatformFoc(ref IDirectoryInfo location)
{
if (!GameDetectorBase.GameExeExists(location, GameType.Foc))
{
Logger?.LogWarning("Unable to find FoC Origin at first location. Trying to fix broken registry path");
Logger?.LogTrace("Unable to find FoC Origin at first location. Trying to fix broken registry path");
TryFixBrokenFocLocation(ref location);
if (!GameDetectorBase.GameExeExists(location, GameType.Foc))
{
Logger?.LogWarning("Origin location fix was unsuccessful. This is not a Origin installation.");
Logger?.LogTrace("Origin location fix was unsuccessful. This is not a Origin installation.");
return false;
}
}
Expand All @@ -40,7 +40,7 @@ public override bool IsPlatformEaw(ref IDirectoryInfo location)
{
if (!GameDetectorBase.MinimumGameFilesExist(GameType.Eaw, location))
{
Logger?.LogWarning("Unable to find EaW Origin at first location.");
Logger?.LogTrace("Unable to find EaW Origin at first location.");
return false;
}

Expand All @@ -66,7 +66,7 @@ private void TryFixBrokenFocLocation(ref IDirectoryInfo location)
var correctedPath = location.FileSystem.Path.Combine(parentDir.FullName, "EAWX");
if (!location.FileSystem.Directory.Exists(correctedPath))
{
Logger?.LogDebug($"Unable to sanitize origin path: Corrected path '{correctedPath}' does not exists.");
Logger?.LogTrace($"Unable to sanitize origin path: Corrected path '{correctedPath}' does not exists.");
return;
}
location = location.FileSystem.DirectoryInfo.New(correctedPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ public RegistryGameDetector(IGameRegistry eawRegistry, IGameRegistry focRegistry
/// <inheritdoc/>
protected override GameLocationData FindGameLocation(GameType gameType)
{
Logger?.LogDebug("Attempting to fetch game location from the registry.");
Logger?.LogTrace("Attempting to fetch game location from the registry.");
var registry = GetRegistry(gameType);
if (!registry.Exits)
{
Logger?.LogDebug("The Game's Registry does not exist.");
Logger?.LogTrace("The Game's Registry does not exist.");
return GameLocationData.NotInstalled;
}

if (registry.Version is null)
{
Logger?.LogDebug("Registry-Key found, but games are not initialized.");
Logger?.LogTrace("Registry-Key found, but games are not initialized.");
return GameLocationData.RequiresInitialization;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public IEnumerable<DetectedModReference> FindMods(IGame game, IDirectoryInfo dir
throw new GameException($"The game '{game}' does not exist");

var modLocationKind = GetModLocationKind(game, directory);
_logger?.LogDebug($"Searching mods with at location '{directory.FullName}' of location kind '{modLocationKind}' for game '{game}'");
_logger?.LogTrace($"Searching mods with at location '{directory.FullName}' of location kind '{modLocationKind}' for game '{game}'");
return GetModsFromDirectory(directory, modLocationKind, game.Type);
}

Expand Down
Loading
Loading