From ee53edc935e0a75a88972feb6b8490755cfa2224 Mon Sep 17 00:00:00 2001 From: Eroen Date: Thu, 26 Sep 2019 16:39:37 +0200 Subject: [PATCH 1/2] Allow reading passwords from redirected input This is beneficial for scripts that don't want to expose the password in the command line arguments. --- DepotDownloader/Program.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 71496a3d..f67c99a9 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -159,7 +159,15 @@ namespace DepotDownloader do { Console.Write( "Enter account password for \"{0}\": ", username ); - password = Util.ReadPassword(); + if ( Console.IsInputRedirected ) + { + password = Console.ReadLine(); + } + else + { + // Avoid console echoing of password + password = Util.ReadPassword(); + } Console.WriteLine(); } while ( String.Empty == password ); } From f1ff09bf209926cf47c499f28690de307e955c84 Mon Sep 17 00:00:00 2001 From: Eroen Date: Sun, 29 Sep 2019 14:14:48 +0200 Subject: [PATCH 2/2] Exit with error code on errors When run by a script, the script needs to know if the requested operation was succesful. This patch makes sure error codes are returned for a number of unhandled error conditions. --- DepotDownloader/ContentDownloader.cs | 16 ++++---- DepotDownloader/Program.cs | 57 +++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 7cb3e014..fc4c8ae4 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -11,6 +11,11 @@ using System.Threading.Tasks; namespace DepotDownloader { + public class ContentDownloaderException : System.Exception + { + public ContentDownloaderException( String value ) : base( value ) {} + } + static class ContentDownloader { public const uint INVALID_APP_ID = uint.MaxValue; @@ -402,8 +407,7 @@ namespace DepotDownloader else { string contentName = GetAppOrDepotName( INVALID_DEPOT_ID, appId ); - Console.WriteLine( "App {0} ({1}) is not available from this account.", appId, contentName ); - return; + throw new ContentDownloaderException( String.Format( "App {0} ({1}) is not available from this account.", appId, contentName ) ); } } @@ -452,14 +456,11 @@ namespace DepotDownloader } if ( depotIDs == null || ( depotIDs.Count == 0 && depotId == INVALID_DEPOT_ID ) ) { - Console.WriteLine( "Couldn't find any depots to download for app {0}", appId ); - return; + throw new ContentDownloaderException( String.Format( "Couldn't find any depots to download for app {0}", appId ) ); } else if ( depotIDs.Count == 0 ) { - Console.Write( "Depot {0} not listed for app {1}", depotId, appId ); - Console.WriteLine(); - return; + throw new ContentDownloaderException( String.Format( "Depot {0} not listed for app {1}", depotId, appId ) ); } } @@ -481,6 +482,7 @@ namespace DepotDownloader catch ( OperationCanceledException ) { Console.WriteLine( "App {0} was not completely downloaded.", appId ); + throw; } } diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index f67c99a9..2126ebad 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -10,15 +10,15 @@ namespace DepotDownloader { class Program { - static void Main( string[] args ) + static int Main( string[] args ) => MainAsync( args ).GetAwaiter().GetResult(); - static async Task MainAsync( string[] args ) + static async Task MainAsync( string[] args ) { if ( args.Length == 0 ) { PrintUsage(); - return; + return 1; } DebugLog.Enabled = false; @@ -93,8 +93,26 @@ namespace DepotDownloader if ( InitializeSteam( username, password ) ) { - await ContentDownloader.DownloadPubfileAsync( pubFile ).ConfigureAwait( false ); - ContentDownloader.ShutdownSteam3(); + try + { + await ContentDownloader.DownloadPubfileAsync( pubFile ).ConfigureAwait( false ); + } + catch ( Exception ex ) when ( + ex is ContentDownloaderException + || ex is OperationCanceledException ) + { + Console.WriteLine( ex.Message ); + return 1; + } + finally + { + ContentDownloader.ShutdownSteam3(); + } + } + else + { + Console.WriteLine( "Error: InitializeSteam failed" ); + return 1; } #endregion @@ -112,14 +130,14 @@ namespace DepotDownloader if ( ContentDownloader.Config.DownloadAllPlatforms && !String.IsNullOrEmpty( os ) ) { Console.WriteLine("Error: Cannot specify -os when -all-platforms is specified."); - return; + return 1; } uint appId = GetParameter( args, "-app", ContentDownloader.INVALID_APP_ID ); if ( appId == ContentDownloader.INVALID_APP_ID ) { Console.WriteLine( "Error: -app not specified!" ); - return; + return 1; } uint depotId; @@ -138,18 +156,37 @@ namespace DepotDownloader if ( depotId == ContentDownloader.INVALID_DEPOT_ID && manifestId != ContentDownloader.INVALID_MANIFEST_ID ) { Console.WriteLine( "Error: -manifest requires -depot to be specified" ); - return; + return 1; } } if ( InitializeSteam( username, password ) ) { - await ContentDownloader.DownloadAppAsync( appId, depotId, manifestId, branch, os, isUGC ).ConfigureAwait( false ); - ContentDownloader.ShutdownSteam3(); + try + { + await ContentDownloader.DownloadAppAsync( appId, depotId, manifestId, branch, os, isUGC ).ConfigureAwait( false ); + } + catch ( Exception ex ) when ( + ex is ContentDownloaderException + || ex is OperationCanceledException ) + { + Console.WriteLine( ex.Message ); + return 1; + } + finally + { + ContentDownloader.ShutdownSteam3(); + } + } + else + { + Console.WriteLine( "Error: InitializeSteam failed" ); + return 1; } #endregion } + return 0; } static bool InitializeSteam( string username, string password )