From 43632c4095d7650709f80291e179f7eeae1198a8 Mon Sep 17 00:00:00 2001 From: Asher Baker Date: Fri, 3 Jun 2011 00:00:21 +0700 Subject: [PATCH] Added (bad and incomplete) support for specifying a game name instead of a depot id. --- DepotDownloader/CDRManager.cs | 57 ++++++++++++++++++++++++++++++++--- DepotDownloader/Program.cs | 48 +++++++++++++++++++++++------ 2 files changed, 92 insertions(+), 13 deletions(-) diff --git a/DepotDownloader/CDRManager.cs b/DepotDownloader/CDRManager.cs index 1ab3655a..099e13a5 100644 --- a/DepotDownloader/CDRManager.cs +++ b/DepotDownloader/CDRManager.cs @@ -58,22 +58,71 @@ namespace DepotDownloader Console.WriteLine( " Done!" ); } - public static int GetLatestDepotVersion( int depotId ) + static Blob GetAppBlob( int appID ) { Blob appsBlob = cdrBlob[ CDRFields.eFieldApplicationsRecord ].GetChildBlob(); foreach ( var blobField in appsBlob.Fields ) { Blob appBlob = blobField.GetChildBlob(); - int appId = appBlob[ CDRAppRecordFields.eFieldAppId ].GetInt32Data(); + int currentAppID = appBlob[ CDRAppRecordFields.eFieldAppId ].GetInt32Data(); - if ( depotId != appId ) + if ( appID != currentAppID ) continue; + return appBlob; + } + + return null; + } + + public static string GetDepotName( int depotId ) + { + Blob appBlob = GetAppBlob( depotId ); + + if ( appBlob == null ) + { + return null; + } + else + { + return appBlob[ CDRAppRecordFields.eFieldName ].GetStringData(); + } + } + + public static int GetLatestDepotVersion( int depotId ) + { + Blob appBlob = GetAppBlob( depotId ); + + if ( appBlob == null ) + { + return -1; + } else { return appBlob[ CDRAppRecordFields.eFieldCurrentVersionId ].GetInt32Data(); } + } + + public static List GetDepotIDsForGameserver( string gameName ) + { + List appIDs = new List(); + + Blob serverAppInfoBlob = GetAppBlob( 4 ); + Blob serverAppInfo = serverAppInfoBlob[ CDRAppRecordFields.eFieldFilesystemsRecord ].GetChildBlob(); + + foreach ( var blobField in serverAppInfo.Fields ) + { + Blob filesystemBlob = blobField.GetChildBlob(); + string mountName = filesystemBlob[CDRAppFilesystemFields.eFieldMountName].GetStringData(); + + if ( gameName.Equals( mountName, StringComparison.OrdinalIgnoreCase ) || + gameName.Equals( mountName + "-win32", StringComparison.OrdinalIgnoreCase ) || + gameName.Equals( mountName + "-linux", StringComparison.OrdinalIgnoreCase ) ) + { + appIDs.Add( filesystemBlob[ CDRAppFilesystemFields.eFieldAppId ].GetInt32Data() ); + } + } - return -1; + return appIDs; } static byte[] GetCdr() diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 5dac93a8..93e1e1c9 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -24,23 +24,30 @@ namespace DepotDownloader CDRManager.Update(); bool bDebot = true; + bool bGameserver = true; - int depotId = GetIntParameter( args, "-depot" ); - if ( depotId == -1 ) + int depotId = -1; + string gameName = GetStringParameter( args, "-game" ); + if ( gameName == null ) { - depotId = GetIntParameter( args, "-manifest" ); - bDebot = false; - + depotId = GetIntParameter( args, "-depot" ); + bGameserver = false; if ( depotId == -1 ) { - Console.WriteLine( "Error: -depot or -manifest not specified!" ); - return; + depotId = GetIntParameter( args, "-manifest" ); + bDebot = false; + + if ( depotId == -1 ) + { + Console.WriteLine( "Error: -game, -depot or -manifest not specified!" ); + return; + } } } int depotVersion = GetIntParameter( args, "-version" ); - if ( depotVersion == -1 ) + if ( !bGameserver && depotVersion == -1 ) { int latestVer = CDRManager.GetLatestDepotVersion( depotId ); @@ -96,8 +103,29 @@ namespace DepotDownloader string username = GetStringParameter( args, "-username" ); string password = GetStringParameter( args, "-password" ); - ContentDownloader.Download( depotId, depotVersion, cellId, username, password, !bDebot, files ); + if ( !bGameserver ) + { + ContentDownloader.Download( depotId, depotVersion, cellId, username, password, !bDebot, files ); + } + else + { + List depotIDs = CDRManager.GetDepotIDsForGameserver( gameName ); + foreach ( int currentDepotId in depotIDs ) + { + depotVersion = CDRManager.GetLatestDepotVersion( currentDepotId ); + if ( depotVersion == -1 ) + { + Console.WriteLine( "Error: Unable to find DepotID {0} in the CDR!", currentDepotId ); + return; + } + + string depotName = CDRManager.GetDepotName( currentDepotId ); + Console.WriteLine( "Downloading \"{0}\" version {1} ...", depotName, depotVersion ); + + ContentDownloader.Download( currentDepotId, depotVersion, cellId, username, password, false, files ); + } + } } static int IndexOfParam( string[] args, string param ) @@ -140,6 +168,8 @@ namespace DepotDownloader Console.WriteLine( "\t-depot #\t\t\t- the DepotID to download." ); Console.WriteLine( "\t OR" ); Console.WriteLine( "\t-manifest #\t\t\t- downloads a human readable manifest for the depot." ); + Console.WriteLine( "\t OR" ); + Console.WriteLine( "\t-game #\t\t\t- the HLDSUpdateTool game server to download." ); Console.WriteLine( "\t-version [# or \"latest\"]\t- the version of the depot to download.\n" ); Console.WriteLine( "Optional Parameters:" );