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.
pull/62/head
Eroen 6 years ago
parent ee53edc935
commit f1ff09bf20

@ -11,6 +11,11 @@ using System.Threading.Tasks;
namespace DepotDownloader namespace DepotDownloader
{ {
public class ContentDownloaderException : System.Exception
{
public ContentDownloaderException( String value ) : base( value ) {}
}
static class ContentDownloader static class ContentDownloader
{ {
public const uint INVALID_APP_ID = uint.MaxValue; public const uint INVALID_APP_ID = uint.MaxValue;
@ -402,8 +407,7 @@ namespace DepotDownloader
else else
{ {
string contentName = GetAppOrDepotName( INVALID_DEPOT_ID, appId ); string contentName = GetAppOrDepotName( INVALID_DEPOT_ID, appId );
Console.WriteLine( "App {0} ({1}) is not available from this account.", appId, contentName ); throw new ContentDownloaderException( String.Format( "App {0} ({1}) is not available from this account.", appId, contentName ) );
return;
} }
} }
@ -452,14 +456,11 @@ namespace DepotDownloader
} }
if ( depotIDs == null || ( depotIDs.Count == 0 && depotId == INVALID_DEPOT_ID ) ) if ( depotIDs == null || ( depotIDs.Count == 0 && depotId == INVALID_DEPOT_ID ) )
{ {
Console.WriteLine( "Couldn't find any depots to download for app {0}", appId ); throw new ContentDownloaderException( String.Format( "Couldn't find any depots to download for app {0}", appId ) );
return;
} }
else if ( depotIDs.Count == 0 ) else if ( depotIDs.Count == 0 )
{ {
Console.Write( "Depot {0} not listed for app {1}", depotId, appId ); throw new ContentDownloaderException( String.Format( "Depot {0} not listed for app {1}", depotId, appId ) );
Console.WriteLine();
return;
} }
} }
@ -481,6 +482,7 @@ namespace DepotDownloader
catch ( OperationCanceledException ) catch ( OperationCanceledException )
{ {
Console.WriteLine( "App {0} was not completely downloaded.", appId ); Console.WriteLine( "App {0} was not completely downloaded.", appId );
throw;
} }
} }

@ -10,15 +10,15 @@ namespace DepotDownloader
{ {
class Program class Program
{ {
static void Main( string[] args ) static int Main( string[] args )
=> MainAsync( args ).GetAwaiter().GetResult(); => MainAsync( args ).GetAwaiter().GetResult();
static async Task MainAsync( string[] args ) static async Task<int> MainAsync( string[] args )
{ {
if ( args.Length == 0 ) if ( args.Length == 0 )
{ {
PrintUsage(); PrintUsage();
return; return 1;
} }
DebugLog.Enabled = false; DebugLog.Enabled = false;
@ -92,10 +92,28 @@ namespace DepotDownloader
#region Pubfile Downloading #region Pubfile Downloading
if ( InitializeSteam( username, password ) ) if ( InitializeSteam( username, password ) )
{
try
{ {
await ContentDownloader.DownloadPubfileAsync( pubFile ).ConfigureAwait( false ); 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(); ContentDownloader.ShutdownSteam3();
} }
}
else
{
Console.WriteLine( "Error: InitializeSteam failed" );
return 1;
}
#endregion #endregion
} }
@ -112,14 +130,14 @@ namespace DepotDownloader
if ( ContentDownloader.Config.DownloadAllPlatforms && !String.IsNullOrEmpty( os ) ) if ( ContentDownloader.Config.DownloadAllPlatforms && !String.IsNullOrEmpty( os ) )
{ {
Console.WriteLine("Error: Cannot specify -os when -all-platforms is specified."); Console.WriteLine("Error: Cannot specify -os when -all-platforms is specified.");
return; return 1;
} }
uint appId = GetParameter<uint>( args, "-app", ContentDownloader.INVALID_APP_ID ); uint appId = GetParameter<uint>( args, "-app", ContentDownloader.INVALID_APP_ID );
if ( appId == ContentDownloader.INVALID_APP_ID ) if ( appId == ContentDownloader.INVALID_APP_ID )
{ {
Console.WriteLine( "Error: -app not specified!" ); Console.WriteLine( "Error: -app not specified!" );
return; return 1;
} }
uint depotId; uint depotId;
@ -138,18 +156,37 @@ namespace DepotDownloader
if ( depotId == ContentDownloader.INVALID_DEPOT_ID && manifestId != ContentDownloader.INVALID_MANIFEST_ID ) if ( depotId == ContentDownloader.INVALID_DEPOT_ID && manifestId != ContentDownloader.INVALID_MANIFEST_ID )
{ {
Console.WriteLine( "Error: -manifest requires -depot to be specified" ); Console.WriteLine( "Error: -manifest requires -depot to be specified" );
return; return 1;
} }
} }
if ( InitializeSteam( username, password ) ) if ( InitializeSteam( username, password ) )
{
try
{ {
await ContentDownloader.DownloadAppAsync( appId, depotId, manifestId, branch, os, isUGC ).ConfigureAwait( false ); 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(); ContentDownloader.ShutdownSteam3();
} }
}
else
{
Console.WriteLine( "Error: InitializeSteam failed" );
return 1;
}
#endregion #endregion
} }
return 0;
} }
static bool InitializeSteam( string username, string password ) static bool InitializeSteam( string username, string password )

Loading…
Cancel
Save