Skip to content

Commit

Permalink
Multiple pubfile support
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Jul 17, 2021
1 parent 8f6fe83 commit 209d838
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
27 changes: 15 additions & 12 deletions DepotDownloader/ContentDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,21 +379,24 @@ public static void ShutdownSteam3()
steam3.Disconnect();
}

public static async Task DownloadPubfileAsync(uint appId, ulong publishedFileId)
public static async Task DownloadPubfileAsync(uint appId, ulong[] publishedFileIds)
{
var details = steam3.GetPublishedFileDetails(appId, publishedFileId);
var list = steam3.GetPublishedFileDetails(appId, publishedFileIds);

if (!string.IsNullOrEmpty(details?.file_url))
foreach (var details in list)
{
await DownloadWebFile(appId, details.filename, details.file_url);
}
else if (details?.hcontent_file > 0)
{
await DownloadAppAsync(appId, new List<(uint, ulong)> { (appId, details.hcontent_file) }, DEFAULT_BRANCH, null, null, null, false, true);
}
else
{
Console.WriteLine("Unable to locate manifest ID for published file {0}", publishedFileId);
if (!string.IsNullOrEmpty(details?.file_url))
{
await DownloadWebFile(appId, details.filename, details.file_url);
}
else if (details?.hcontent_file > 0)
{
await DownloadAppAsync(appId, new List<(uint, ulong)> { (appId, details.hcontent_file) }, DEFAULT_BRANCH, null, null, null, false, true);
}
else
{
Console.WriteLine("Unable to locate manifest ID for published file {0}", details?.publishedfileid);
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions DepotDownloader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static Task<int> Main(string[] args)
new Option<ulong[]>("--manifest", "Manifest id of content to download (requires --depot, default: current for branch)"),

new Option<ulong?>("--ugc", "The UGC ID to download"),
new Option<ulong?>("--pubfile", "The PublishedFileId to download (will automatically resolve to UGC id)"),
new Option<ulong[]>("--pubfile", "The PublishedFileId to download (will automatically resolve to UGC id)"),

new Option<string?>(new[] { "--branch", "--beta" }, "Download from specified branch if available"),
new Option<string?>(new[] { "--branch-password", "--betapassword" }, "Branch password if applicable"),
Expand Down Expand Up @@ -90,14 +90,14 @@ protected override void AddUsage(ICommand command)

public class InputModel
{
public InputModel(bool debug, uint app, uint[] depot, ulong[] manifest, ulong? ugc, ulong? pubfile, string? branch, string? branchPassword, string[] os, string[] arch, string[] language, bool lowViolence, string? username, string? password, bool rememberPassword, string directory, FileInfo? fileList, bool validate, bool manifestOnly, int? cellId, int maxServers, int maxDownloads, uint? loginId)
public InputModel(bool debug, uint app, uint[] depot, ulong[] manifest, ulong? ugc, ulong[] pubfile, string? branch, string? branchPassword, string[] os, string[] arch, string[] language, bool lowViolence, string? username, string? password, bool rememberPassword, DirectoryInfo? directory, FileInfo? fileList, bool validate, bool manifestOnly, int? cellId, int maxServers, int maxDownloads, uint? loginId)
{
Debug = debug;
AppId = app;
Depots = depot;
Manifests = manifest;
UgcId = ugc;
Pubfile = pubfile;
PublishedFileIds = pubfile;
Branch = EnsureNonEmpty(branch);
BranchPassword = EnsureNonEmpty(branchPassword);
OperatingSystems = os;
Expand Down Expand Up @@ -131,7 +131,7 @@ public InputModel(bool debug, uint app, uint[] depot, ulong[] manifest, ulong? u
public ulong[] Manifests { get; }

public ulong? UgcId { get; }
public ulong? Pubfile { get; }
public ulong[] PublishedFileIds { get; }

public string? Branch { get; }
public string? BranchPassword { get; }
Expand Down Expand Up @@ -223,9 +223,9 @@ public static async Task<int> DownloadAsync(InputModel input)
{
try
{
if (input.Pubfile != null)
if (input.PublishedFileIds.Any())
{
await ContentDownloader.DownloadPubfileAsync(input.AppId, input.Pubfile.Value).ConfigureAwait(false);
await ContentDownloader.DownloadPubfileAsync(input.AppId, input.PublishedFileIds).ConfigureAwait(false);
}
else if (input.UgcId != null)
{
Expand Down
10 changes: 5 additions & 5 deletions DepotDownloader/Steam3Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,25 +384,25 @@ public void CheckAppBetaPassword(uint appid, string password)
}, () => { return completed; });
}

public PublishedFileDetails GetPublishedFileDetails(uint appId, PublishedFileID pubFile)
public List<PublishedFileDetails> GetPublishedFileDetails(uint appId, ulong[] publishedFileIds)
{
var pubFileRequest = new CPublishedFile_GetDetails_Request { appid = appId };
pubFileRequest.publishedfileids.Add(pubFile);
pubFileRequest.publishedfileids.AddRange(publishedFileIds);

var completed = false;
PublishedFileDetails details = null;
List<PublishedFileDetails> details = null;

Action<SteamUnifiedMessages.ServiceMethodResponse> cbMethod = callback =>
{
completed = true;
if (callback.Result == EResult.OK)
{
var response = callback.GetDeserializedResponse<CPublishedFile_GetDetails_Response>();
details = response.publishedfiledetails.FirstOrDefault();
details = response.publishedfiledetails;
}
else
{
throw new Exception($"EResult {(int)callback.Result} ({callback.Result}) while retrieving file details for pubfile {pubFile}.");
throw new Exception($"EResult {(int)callback.Result} ({callback.Result}) while retrieving file details for pubfiles [{string.Join(", ", publishedFileIds)}].");
}
};

Expand Down

0 comments on commit 209d838

Please sign in to comment.