From 8fcfd837b08ce73fbe3cbaeba241cf43aa8acd73 Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Fri, 6 Nov 2020 00:59:18 -0700 Subject: [PATCH] Alternate -pubfile implementation using GetDetails --- DepotDownloader/ContentDownloader.cs | 38 +++++++++++++++++++++++++--- DepotDownloader/Steam3Session.cs | 30 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 6303a905..f1d6853c 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; +using System.Net.Http; using System.Text; using System.Text.RegularExpressions; using System.Threading; @@ -382,11 +383,42 @@ namespace DepotDownloader public static async Task DownloadPubfileAsync( uint appId, ulong publishedFileId ) { - var details = steam3.GetPubfileItemInfo( appId, publishedFileId ); + var details = steam3.GetPublishedFileDetails( appId, publishedFileId ); - if ( details?.manifest_id > 0 ) + if ( !string.IsNullOrEmpty( details?.file_url ) ) { - await DownloadAppAsync( appId, new List>() { Tuple.Create( appId, details.manifest_id ) }, DEFAULT_BRANCH, null, null, null, false, true ); + string installDir; + if ( !CreateDirectories( details.consumer_appid, (uint)details.revision_change_number, out installDir ) ) + { + Console.WriteLine( "Error: Unable to create install directories!" ); + return; + } + + var stagingDir = Path.Combine( installDir, STAGING_DIR ); + var fileStagingPath = Path.Combine( stagingDir, details.filename ); + var fileFinalPath = Path.Combine( installDir, details.filename ); + + Directory.CreateDirectory( Path.GetDirectoryName( fileFinalPath ) ); + Directory.CreateDirectory( Path.GetDirectoryName( fileStagingPath ) ); + + using ( var file = File.OpenWrite( fileStagingPath ) ) + using ( var client = new HttpClient() ) + { + Console.WriteLine( "Downloading {0}", details.filename ); + var responseStream = await client.GetStreamAsync( details.file_url ); + await responseStream.CopyToAsync( file ); + } + + if ( File.Exists( fileFinalPath ) ) + { + File.Delete( fileFinalPath ); + } + + File.Move( fileStagingPath, fileFinalPath ); + } + else if ( details?.hcontent_file > 0 ) + { + await DownloadAppAsync( appId, new List>() { Tuple.Create( appId, details.hcontent_file ) }, DEFAULT_BRANCH, null, null, null, false, true ); } else { diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 7f33b65e..64ff0912 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -443,6 +443,36 @@ namespace DepotDownloader return details; } + public PublishedFileDetails GetPublishedFileDetails(uint appId, PublishedFileID pubFile) + { + var pubFileRequest = new CPublishedFile_GetDetails_Request() { appid = appId }; + pubFileRequest.publishedfileids.Add( pubFile ); + + bool completed = false; + PublishedFileDetails details = null; + + Action cbMethod = callback => + { + completed = true; + if (callback.Result == EResult.OK) + { + var response = callback.GetDeserializedResponse(); + details = response.publishedfiledetails.FirstOrDefault(); + } + else + { + throw new Exception($"EResult {(int)callback.Result} ({callback.Result}) while retrieving file details for pubfile {pubFile}."); + } + }; + + WaitUntilCallback(() => + { + callbacks.Subscribe(steamPublishedFile.SendMessage(api => api.GetDetails(pubFileRequest)), cbMethod); + }, () => { return completed; }); + + return details; + } + void Connect() { bAborted = false;