From 0fc89f465abf5a8e462891f1ae85619b7a1c0c95 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Mon, 27 Jun 2011 01:28:04 -0500 Subject: [PATCH] Added -dir option to DepotDownloader for specifying an alternate install directory. --- DepotDownloader/ContentDownloader.cs | 36 +++++++++++++++------------- DepotDownloader/Program.cs | 6 +++-- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index bc36a625..b4456d78 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -13,23 +13,28 @@ namespace DepotDownloader { static class ContentDownloader { - const string DOWNLOAD_DIR = "depots"; + const string DEFAULT_DIR = "depots"; static Steam3Session steam3; - static bool CreateDirectories( int depotId, int depotVersion, out string downloadDir ) + static bool CreateDirectories( int depotId, int depotVersion, ref string installDir ) { - downloadDir = null; - try { - Directory.CreateDirectory( DOWNLOAD_DIR ); + if ( installDir == null || installDir.Equals( "" ) ) + { + Directory.CreateDirectory( DEFAULT_DIR ); - string depotPath = Path.Combine( DOWNLOAD_DIR, depotId.ToString() ); - Directory.CreateDirectory( depotPath ); + string depotPath = Path.Combine( DEFAULT_DIR, depotId.ToString() ); + Directory.CreateDirectory( depotPath ); - downloadDir = Path.Combine( depotPath, depotVersion.ToString() ); - Directory.CreateDirectory( downloadDir ); + installDir = Path.Combine( depotPath, depotVersion.ToString() ); + Directory.CreateDirectory( installDir ); + } + else + { + Directory.CreateDirectory( installDir ); + } } catch { @@ -39,12 +44,11 @@ namespace DepotDownloader return true; } - public static void Download( int depotId, int depotVersion, int cellId, string username, string password, bool onlyManifest, string[] fileList ) + public static void Download( int depotId, int depotVersion, int cellId, string username, string password, bool onlyManifest, string installDir, string[] fileList ) { - string downloadDir; - if ( !CreateDirectories( depotId, depotVersion, out downloadDir ) ) + if ( !CreateDirectories( depotId, depotVersion, ref installDir ) ) { - Console.WriteLine( "Error: Unable to create download directories!" ); + Console.WriteLine( "Error: Unable to create install directories!" ); return; } @@ -67,8 +71,8 @@ namespace DepotDownloader credentials = GetCredentials( ( uint )depotId, username, password ); } - string manifestFile = Path.Combine( downloadDir, "manifest.bin" ); - string txtManifest = Path.Combine( downloadDir, "manifest.txt" ); + string manifestFile = Path.Combine( installDir, "manifest.bin" ); + string txtManifest = Path.Combine( installDir, "manifest.txt" ); ContentServerClient csClient = new ContentServerClient(); @@ -128,7 +132,7 @@ namespace DepotDownloader { var dirEntry = manifest.Nodes[ x ]; - string downloadPath = Path.Combine( downloadDir, dirEntry.FullName ); + string downloadPath = Path.Combine( installDir, dirEntry.FullName ); if ( onlyManifest ) { diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 93e1e1c9..1ccd48cb 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -102,10 +102,11 @@ namespace DepotDownloader string username = GetStringParameter( args, "-username" ); string password = GetStringParameter( args, "-password" ); + string installDir = GetStringParameter( args, "-dir" ); if ( !bGameserver ) { - ContentDownloader.Download( depotId, depotVersion, cellId, username, password, !bDebot, files ); + ContentDownloader.Download( depotId, depotVersion, cellId, username, password, !bDebot, installDir, files ); } else { @@ -123,7 +124,7 @@ namespace DepotDownloader string depotName = CDRManager.GetDepotName( currentDepotId ); Console.WriteLine( "Downloading \"{0}\" version {1} ...", depotName, depotVersion ); - ContentDownloader.Download( currentDepotId, depotVersion, cellId, username, password, false, files ); + ContentDownloader.Download( currentDepotId, depotVersion, cellId, username, password, false, installDir, files ); } } } @@ -176,6 +177,7 @@ namespace DepotDownloader Console.WriteLine( "\t-cellid #\t\t\t- the CellID of the content server to download from." ); Console.WriteLine( "\t-username user\t\t\t- the username of the account to login to for restricted content." ); Console.WriteLine( "\t-password pass\t\t\t- the password of the account to login to for restricted content." ); + Console.WriteLine( "\t-dir installdir\t\t\t- the directory in which to place downloaded files." ); Console.WriteLine( "\t-filelist filename.txt\t\t- a list of files to download (from the manifest). Can optionally use regex to download only certain files.\n" ); } }