mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Can download steam files
This commit is contained in:
parent
3304b2a584
commit
94fe7f1e1d
@ -66,6 +66,7 @@ internal class Program
|
||||
services.AddSingleton<IVerb, MirrorFile>();
|
||||
services.AddSingleton<IVerb, SteamLogin>();
|
||||
services.AddSingleton<IVerb, SteamAppDumpInfo>();
|
||||
services.AddSingleton<IVerb, SteamDownloadFile>();
|
||||
|
||||
services.AddSingleton<IUserInterventionHandler, UserInterventionHandler>();
|
||||
}).Build();
|
||||
|
95
Wabbajack.CLI/Verbs/SteamDownloadFile.cs
Normal file
95
Wabbajack.CLI/Verbs/SteamDownloadFile.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FluentFTP.Helpers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SteamKit2;
|
||||
using Wabbajack.DTOs;
|
||||
using Wabbajack.DTOs.JsonConverters;
|
||||
using Wabbajack.Networking.Http.Interfaces;
|
||||
using Wabbajack.Networking.Steam;
|
||||
using Wabbajack.Paths;
|
||||
|
||||
namespace Wabbajack.CLI.Verbs;
|
||||
|
||||
public class SteamDownloadFile : IVerb
|
||||
{
|
||||
private readonly ILogger<SteamDownloadFile> _logger;
|
||||
private readonly Client _client;
|
||||
private readonly ITokenProvider<SteamLoginState> _token;
|
||||
private readonly DepotDownloader _downloader;
|
||||
private readonly DTOSerializer _dtos;
|
||||
private readonly Wabbajack.Networking.WabbajackClientApi.Client _wjClient;
|
||||
|
||||
public SteamDownloadFile(ILogger<SteamDownloadFile> logger, Client steamClient, ITokenProvider<SteamLoginState> token,
|
||||
DepotDownloader downloader, DTOSerializer dtos, Wabbajack.Networking.WabbajackClientApi.Client wjClient)
|
||||
{
|
||||
_logger = logger;
|
||||
_client = steamClient;
|
||||
_token = token;
|
||||
_downloader = downloader;
|
||||
_dtos = dtos;
|
||||
_wjClient = wjClient;
|
||||
}
|
||||
public Command MakeCommand()
|
||||
{
|
||||
var command = new Command("steam-download-file");
|
||||
command.Description = "Dumps information to the console about the given app";
|
||||
|
||||
command.Add(new Option<string>(new[] {"-g", "-game", "-gameName"}, "Wabbajack game name"));
|
||||
|
||||
command.Add(new Option<string>(new[] {"-v", "-version"}, "Version of the game to download for"));
|
||||
command.Add(new Option<string>(new[] {"-f", "-file"}, "File to download (relative path)"));
|
||||
command.Add(new Option<string>(new[] {"-o", "-output"}, "Output location"));
|
||||
command.Handler = CommandHandler.Create(Run);
|
||||
return command;
|
||||
}
|
||||
|
||||
private async Task<int> Run(string gameName, string version, string file, AbsolutePath output)
|
||||
{
|
||||
if (!GameRegistry.TryGetByFuzzyName(gameName, out var game))
|
||||
_logger.LogError("Can't find definition for {Game}", gameName);
|
||||
|
||||
await _client.Login();
|
||||
|
||||
var definition = await _wjClient.GetGameArchives(game.Game, version);
|
||||
var manifests = await _wjClient.GetSteamManifests(game.Game, version);
|
||||
|
||||
_logger.LogInformation("Found {Count} manifests, looking for file", manifests.Length);
|
||||
|
||||
SteamManifest? steamManifest = null;
|
||||
DepotManifest? depotManifest = null;
|
||||
DepotManifest.FileData? fileData = null;
|
||||
|
||||
var appId = (uint) game.SteamIDs.First();
|
||||
|
||||
foreach (var manifest in manifests)
|
||||
{
|
||||
steamManifest = manifest;
|
||||
depotManifest = await _client.GetAppManifest(appId, manifest.Depot, manifest.Manifest);
|
||||
fileData = depotManifest.Files!.FirstOrDefault(f => f.FileName == file);
|
||||
if (fileData != default)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fileData == default)
|
||||
{
|
||||
_logger.LogError("Cannot find {File} in any manifests", file);
|
||||
return 1;
|
||||
}
|
||||
|
||||
_logger.LogInformation("File has is {Size} and {ChunkCount} chunks", fileData.TotalSize.FileSizeToString(), fileData.Chunks.Count);
|
||||
|
||||
await _client.Download(appId, depotManifest!.DepotID, steamManifest!.Manifest, fileData, output);
|
||||
|
||||
_logger.LogInformation("File downloaded");
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -63,13 +63,7 @@ public class SteamAppDumpInfo : IVerb
|
||||
Console.WriteLine("App Depots: ");
|
||||
|
||||
Console.WriteLine(_dtos.Serialize(appData, true));
|
||||
|
||||
Console.WriteLine("Loading Manifests");
|
||||
var servers = await _client.LoadCDNServers();
|
||||
//var manifest = await _client.GetAppManifest();
|
||||
|
||||
var data = await _client.GetAppManifest(appId, 489831, 7089166303853251347);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
12
Wabbajack.DTOs/Game/SteamManifest.cs
Normal file
12
Wabbajack.DTOs/Game/SteamManifest.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Wabbajack.DTOs;
|
||||
|
||||
public class SteamManifest
|
||||
{
|
||||
[JsonPropertyName("Depot")]
|
||||
public uint Depot { get; set; }
|
||||
|
||||
[JsonPropertyName("Manifest")]
|
||||
public ulong Manifest { get; set; }
|
||||
}
|
@ -2,14 +2,18 @@ using System.Collections.Concurrent;
|
||||
using System.IO.Compression;
|
||||
using System.Security;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
using SteamKit2;
|
||||
using SteamKit2.CDN;
|
||||
using SteamKit2.Internal;
|
||||
using Wabbajack.DTOs.Interventions;
|
||||
using Wabbajack.DTOs.JsonConverters;
|
||||
using Wabbajack.Hashing.xxHash64;
|
||||
using Wabbajack.Networking.Http.Interfaces;
|
||||
using Wabbajack.Networking.Steam.DTOs;
|
||||
using Wabbajack.Networking.Steam.UserInterventions;
|
||||
using Wabbajack.Paths;
|
||||
using Wabbajack.Paths.IO;
|
||||
|
||||
namespace Wabbajack.Networking.Steam;
|
||||
|
||||
@ -398,10 +402,41 @@ public class Client : IDisposable
|
||||
|
||||
var result = await _steamApps.GetDepotDecryptionKey(depotId, appId);
|
||||
if (result.Result != EResult.OK)
|
||||
throw new SteamException($"Error gettding Depot Key for {depotId} {appId}", result.Result, EResult.Invalid);
|
||||
throw new SteamException($"Error getting Depot Key for {depotId} {appId}", result.Result, EResult.Invalid);
|
||||
|
||||
DepotKeys[depotId] = result.DepotKey;
|
||||
return result.DepotKey;
|
||||
}
|
||||
|
||||
public async Task Download(uint appId, uint depotId, ulong manifest, DepotManifest.FileData fileData, AbsolutePath output)
|
||||
{
|
||||
await LoadCDNServers();
|
||||
var client = _cdnServers.First();
|
||||
var depotKey = await GetDepotKey(depotId, appId);
|
||||
|
||||
await using var os = output.Open(FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
|
||||
foreach (var chunk in fileData.Chunks.OrderBy(c => c.Offset))
|
||||
{
|
||||
|
||||
var chunkId = chunk.ChunkID!.ToHex();
|
||||
|
||||
|
||||
var uri = new UriBuilder()
|
||||
{
|
||||
Host = client.Host,
|
||||
Port = client.Port,
|
||||
Scheme = client.Protocol.ToString(),
|
||||
Path = $"depot/{depotId}/chunk/{chunkId}"
|
||||
}.Uri;
|
||||
|
||||
var data = await _httpClient.GetByteArrayAsync(uri);
|
||||
var chunkData = new DepotChunk(chunk, data);
|
||||
chunkData.Process(depotKey);
|
||||
|
||||
await os.WriteAsync(chunkData.Data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wabbajack.DTOs\Wabbajack.DTOs.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Networking.Http.Interfaces\Wabbajack.Networking.Http.Interfaces.csproj" />
|
||||
<ProjectReference Include="..\Wabbajack.Paths.IO\Wabbajack.Paths.IO.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -340,4 +340,10 @@ public class Client
|
||||
{
|
||||
return (await _client.GetFromJsonAsync<ForcedRemoval[]>("https://raw.githubusercontent.com/wabbajack-tools/mod-lists/master/configs/forced_removal.json", _dtos.Options, token))!;
|
||||
}
|
||||
|
||||
public async Task<SteamManifest[]> GetSteamManifests(Game game, string version)
|
||||
{
|
||||
var url = $"https://raw.githubusercontent.com/wabbajack-tools/indexed-game-files/master/{game}/{version}_steam_manifests.json";
|
||||
return await _client.GetFromJsonAsync<SteamManifest[]>(url, _dtos.Options) ?? Array.Empty<SteamManifest>();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user