Merge pull request #62 from eroen/master

Be more friendly to scripts
pull/65/head
Ryan Kistner 6 years ago committed by GitHub
commit da88425eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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;
}
}

@ -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<int> 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<uint>( 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 )
@ -159,7 +196,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 );
}

Loading…
Cancel
Save