2022-10-01 01:35:36 +00:00
|
|
|
using System;
|
2022-09-26 21:58:33 +00:00
|
|
|
using System.CommandLine;
|
|
|
|
using System.CommandLine.Invocation;
|
2022-09-29 05:10:49 +00:00
|
|
|
using System.CommandLine.NamingConventionBinder;
|
2022-09-26 21:58:33 +00:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-10-14 22:08:21 +00:00
|
|
|
using Wabbajack.CLI.Builder;
|
2022-09-26 21:58:33 +00:00
|
|
|
using Wabbajack.Downloaders.GameFile;
|
|
|
|
using Wabbajack.DTOs;
|
|
|
|
using Wabbajack.Paths.IO;
|
|
|
|
|
|
|
|
namespace Wabbajack.CLI.Verbs;
|
|
|
|
|
2022-10-14 22:08:21 +00:00
|
|
|
public class ListGames
|
2022-09-26 21:58:33 +00:00
|
|
|
{
|
|
|
|
private readonly ILogger<ListGames> _logger;
|
|
|
|
private readonly GameLocator _locator;
|
|
|
|
|
|
|
|
public ListGames(ILogger<ListGames> logger, GameLocator locator)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_locator = locator;
|
|
|
|
}
|
2022-10-01 01:35:36 +00:00
|
|
|
|
2022-10-14 22:08:21 +00:00
|
|
|
public static VerbDefinition Definition = new("list-games",
|
2022-10-01 01:35:36 +00:00
|
|
|
"Lists all games Wabbajack recognizes, and their installed versions/locations (if any)", Array.Empty<OptionDefinition>());
|
2022-09-26 21:58:33 +00:00
|
|
|
|
2022-10-07 20:53:55 +00:00
|
|
|
internal Task<int> Run(CancellationToken token)
|
2022-09-26 21:58:33 +00:00
|
|
|
{
|
|
|
|
foreach (var game in GameRegistry.Games.OrderBy(g => g.Value.HumanFriendlyGameName))
|
|
|
|
{
|
|
|
|
if (_locator.IsInstalled(game.Key))
|
|
|
|
{
|
|
|
|
var location = _locator.GameLocation(game.Key);
|
|
|
|
var mainFile = game.Value.MainExecutable!.Value.RelativeTo(location);
|
|
|
|
|
|
|
|
if (!mainFile.FileExists())
|
|
|
|
_logger.LogWarning("Main file {file} for {game} does not exist", mainFile, game.Key);
|
|
|
|
|
|
|
|
var versionInfo = FileVersionInfo.GetVersionInfo(mainFile.ToString());
|
|
|
|
|
|
|
|
_logger.LogInformation("[X] {Game} {Version} -> Path: {Path}", game.Value.HumanFriendlyGameName, versionInfo.ProductVersion ?? versionInfo.FileVersion, location);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_logger.LogInformation("[ ] {Game}", game.Value.HumanFriendlyGameName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-07 20:53:55 +00:00
|
|
|
return Task.FromResult(0);
|
2022-09-26 21:58:33 +00:00
|
|
|
}
|
|
|
|
}
|