2022-01-08 22:03:39 +00:00
|
|
|
using System;
|
|
|
|
using System.CommandLine;
|
|
|
|
using System.CommandLine.Invocation;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2022-01-09 01:19:08 +00:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using SteamKit2;
|
2022-01-08 22:03:39 +00:00
|
|
|
using Wabbajack.DTOs;
|
2022-01-09 01:19:08 +00:00
|
|
|
using Wabbajack.DTOs.JsonConverters;
|
2022-01-08 22:03:39 +00:00
|
|
|
using Wabbajack.Networking.Http.Interfaces;
|
|
|
|
using Wabbajack.Networking.Steam;
|
2022-01-09 01:19:08 +00:00
|
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
2022-01-08 22:03:39 +00:00
|
|
|
|
|
|
|
namespace Wabbajack.CLI.Verbs;
|
|
|
|
|
|
|
|
public class SteamAppDumpInfo : IVerb
|
|
|
|
{
|
|
|
|
private readonly ILogger<SteamAppDumpInfo> _logger;
|
|
|
|
private readonly Client _client;
|
|
|
|
private readonly ITokenProvider<SteamLoginState> _token;
|
|
|
|
private readonly DepotDownloader _downloader;
|
2022-01-09 01:19:08 +00:00
|
|
|
private readonly DTOSerializer _dtos;
|
2022-01-08 22:03:39 +00:00
|
|
|
|
|
|
|
public SteamAppDumpInfo(ILogger<SteamAppDumpInfo> logger, Client steamClient, ITokenProvider<SteamLoginState> token,
|
2022-01-09 01:19:08 +00:00
|
|
|
DepotDownloader downloader, DTOSerializer dtos)
|
2022-01-08 22:03:39 +00:00
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_client = steamClient;
|
|
|
|
_token = token;
|
|
|
|
_downloader = downloader;
|
2022-01-09 01:19:08 +00:00
|
|
|
_dtos = dtos;
|
2022-01-08 22:03:39 +00:00
|
|
|
}
|
|
|
|
public Command MakeCommand()
|
|
|
|
{
|
|
|
|
var command = new Command("steam-app-dump-info");
|
|
|
|
command.Description = "Dumps information to the console about the given app";
|
|
|
|
|
|
|
|
command.Add(new Option<string>(new[] {"-g", "-game", "-gameName"}, "Wabbajack game name"));
|
|
|
|
command.Handler = CommandHandler.Create(Run);
|
|
|
|
return command;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<int> Run(string gameName)
|
|
|
|
{
|
|
|
|
if (!GameRegistry.TryGetByFuzzyName(gameName, out var game))
|
|
|
|
{
|
|
|
|
_logger.LogError("Can't find game {GameName} in game registry", gameName);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
await _client.Login();
|
2022-01-09 01:19:08 +00:00
|
|
|
var appId = (uint) game.SteamIDs.First();
|
2022-01-08 22:03:39 +00:00
|
|
|
|
2022-01-09 01:19:08 +00:00
|
|
|
if (!await _downloader.AccountHasAccess(appId))
|
2022-01-08 22:03:39 +00:00
|
|
|
{
|
|
|
|
_logger.LogError("Your account does not have access to this Steam App");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-01-09 01:19:08 +00:00
|
|
|
var appData = await _downloader.GetAppInfo((uint)game.SteamIDs.First());
|
|
|
|
|
|
|
|
Console.WriteLine("App Depots: ");
|
|
|
|
|
|
|
|
Console.WriteLine(_dtos.Serialize(appData, true));
|
|
|
|
|
2022-01-08 22:03:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2022-01-09 01:19:08 +00:00
|
|
|
|
2022-01-08 22:03:39 +00:00
|
|
|
|
|
|
|
}
|