Skip to content

Commit

Permalink
Exit with error code on errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eroen committed Sep 29, 2019
1 parent f818ba8 commit 8fa7594
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
7 changes: 4 additions & 3 deletions DepotDownloader/ContentDownloader.cs
Expand Up @@ -403,7 +403,7 @@ public static async Task DownloadAppAsync( uint appId, uint depotId, ulong manif
{
string contentName = GetAppOrDepotName( INVALID_DEPOT_ID, appId );
Console.WriteLine( "App {0} ({1}) is not available from this account.", appId, contentName );
return;
throw new Exception(String.Format("App {0} ({1}) is not available from this account.", appId, contentName));
}
}

Expand Down Expand Up @@ -453,13 +453,13 @@ public static async Task DownloadAppAsync( uint appId, uint depotId, ulong manif
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 Exception(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 Exception(String.Format( "Depot {0} not listed for app {1}", depotId, appId ));
}
}

Expand All @@ -481,6 +481,7 @@ public static async Task DownloadAppAsync( uint appId, uint depotId, ulong manif
catch ( OperationCanceledException )
{
Console.WriteLine( "App {0} was not completely downloaded.", appId );
throw;
}
}

Expand Down
43 changes: 33 additions & 10 deletions DepotDownloader/Program.cs
Expand Up @@ -11,14 +11,14 @@ namespace DepotDownloader
class Program
{
static void Main( string[] args )
=> MainAsync( args ).GetAwaiter().GetResult();
=> System.Environment.Exit( 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;
Expand Down Expand Up @@ -93,8 +93,19 @@ static async Task MainAsync( string[] args )

if ( InitializeSteam( username, password ) )
{
await ContentDownloader.DownloadPubfileAsync( pubFile ).ConfigureAwait( false );
ContentDownloader.ShutdownSteam3();
try
{
await ContentDownloader.DownloadPubfileAsync( pubFile ).ConfigureAwait( false );
}
finally
{
ContentDownloader.ShutdownSteam3();
}
}
else
{
Console.WriteLine( "Error: InitializeSteam failed" );
return 1;
}

#endregion
Expand All @@ -112,14 +123,14 @@ static async Task MainAsync( string[] args )
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;
Expand All @@ -138,18 +149,30 @@ static async Task MainAsync( string[] args )
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 );
}
finally
{
ContentDownloader.ShutdownSteam3();
}
}
else
{
Console.WriteLine( "Error: InitializeSteam failed" );
return 1;
}

#endregion
}
return 0;
}

static bool InitializeSteam( string username, string password )
Expand Down

0 comments on commit 8fa7594

Please sign in to comment.