diff --git a/DepotDownloader/CDRManager.cs b/DepotDownloader/CDRManager.cs index e5704318..1ab3655a 100644 --- a/DepotDownloader/CDRManager.cs +++ b/DepotDownloader/CDRManager.cs @@ -42,7 +42,7 @@ namespace DepotDownloader break; } - catch ( Exception ex ) + catch ( Exception ) { Console.WriteLine( "Warning: Unable to download CDR from config server {0}", configServer ); } diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 21a0ab39..e0ffc339 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -7,6 +7,7 @@ using System.Net; using System.IO; using System.IO.Compression; using System.Diagnostics; +using System.Text.RegularExpressions; namespace DepotDownloader { @@ -16,9 +17,36 @@ namespace DepotDownloader static Steam3Session steam3; - public static void Download( int depotId, int depotVersion, int cellId, string username, string password ) + static bool CreateDirectories( int depotId, int depotVersion, out string downloadDir ) { - Directory.CreateDirectory( DOWNLOAD_DIR ); + downloadDir = null; + + try + { + Directory.CreateDirectory( DOWNLOAD_DIR ); + + string depotPath = Path.Combine( DOWNLOAD_DIR, depotId.ToString() ); + Directory.CreateDirectory( depotPath ); + + downloadDir = Path.Combine( depotPath, depotVersion.ToString() ); + Directory.CreateDirectory( downloadDir ); + } + catch + { + return false; + } + + return true; + } + + public static void Download( int depotId, int depotVersion, int cellId, string username, string password, bool onlyManifest, string[] fileList ) + { + string downloadDir; + if ( !CreateDirectories( depotId, depotVersion, out downloadDir ) ) + { + Console.WriteLine( "Error: Unable to create download directories!" ); + return; + } Console.Write( "Finding content servers..." ); IPEndPoint contentServer = GetStorageServer( depotId, depotVersion, cellId ); @@ -39,13 +67,8 @@ namespace DepotDownloader credentials = GetCredentials( ( uint )depotId, username, password ); } - string depotPath = Path.Combine( DOWNLOAD_DIR, depotId.ToString() ); - Directory.CreateDirectory( depotPath ); - - string downloadDir = Path.Combine( depotPath, depotVersion.ToString() ); - Directory.CreateDirectory( downloadDir ); - - string manifestFile = Path.Combine( downloadDir, string.Format( "manifest.bin", depotId, depotVersion ) ); + string manifestFile = Path.Combine( downloadDir, "manifest.bin" ); + string txtManifest = Path.Combine( downloadDir, "manifest.txt" ); ContentServerClient csClient = new ContentServerClient(); @@ -73,12 +96,76 @@ namespace DepotDownloader Manifest manifest = new Manifest( manifestData ); - for ( int x = 0; x < manifest.DirEntries.Count; ++x ) + if ( onlyManifest ) + File.Delete( txtManifest ); + + StringBuilder manifestBuilder = new StringBuilder(); + List rgxList = new List(); + + if ( fileList != null ) + { + foreach ( string fileListentry in fileList ) + { + try + { + Regex rgx = new Regex( fileListentry, RegexOptions.Compiled | RegexOptions.IgnoreCase ); + rgxList.Add( rgx ); + } + catch { continue; } + } + } + + for ( int x = 0 ; x < manifest.DirEntries.Count ; ++x ) { Manifest.DirectoryEntry dirEntry = manifest.DirEntries[ x ]; string downloadPath = Path.Combine( downloadDir, dirEntry.FullName ); + if ( onlyManifest ) + { + if ( dirEntry.FileID == -1 ) + continue; + + manifestBuilder.Append( string.Format( "{0}\n", dirEntry.FullName ) ); + continue; + } + + if ( fileList != null ) + { + bool bMatched = false; + + foreach ( string fileListEntry in fileList ) + { + if ( fileListEntry.Equals( dirEntry.FullName, StringComparison.OrdinalIgnoreCase ) ) + { + bMatched = true; + break; + } + } + + if ( !bMatched ) + { + foreach ( Regex rgx in rgxList ) + { + Match m = rgx.Match( dirEntry.FullName ); + + if ( m.Success ) + { + bMatched = true; + break; + } + } + } + + if ( !bMatched ) + continue; + + string path = Path.GetDirectoryName( downloadPath ); + + if ( !Directory.Exists( path ) ) + Directory.CreateDirectory( path ); + } + if ( dirEntry.FileID == -1 ) { if ( !Directory.Exists( downloadPath ) ) @@ -127,6 +214,9 @@ namespace DepotDownloader File.WriteAllBytes( downloadPath, file.Data ); } + if ( onlyManifest ) + File.WriteAllText( txtManifest, manifestBuilder.ToString() ); + csClient.CloseStorage( storageId ); csClient.ExitStorageMode(); diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index a565d931..5dac93a8 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using SteamKit2; +using System.IO; namespace DepotDownloader { @@ -22,7 +23,21 @@ namespace DepotDownloader ServerCache.Build(); CDRManager.Update(); + bool bDebot = true; + int depotId = GetIntParameter( args, "-depot" ); + if ( depotId == -1 ) + { + depotId = GetIntParameter( args, "-manifest" ); + bDebot = false; + + if ( depotId == -1 ) + { + Console.WriteLine( "Error: -depot or -manifest not specified!" ); + return; + } + } + int depotVersion = GetIntParameter( args, "-version" ); if ( depotVersion == -1 ) @@ -60,10 +75,28 @@ namespace DepotDownloader "You can specify the CellID using the -cellid parameter" ); } + string fileList = GetStringParameter( args, "-filelist" ); + string[] files = null; + + if ( fileList != null ) + { + try + { + string fileListData = File.ReadAllText( fileList ); + files = fileListData.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries ); + + Console.WriteLine( "Using filelist: '{0}'.", fileList ); + } + catch ( Exception ex ) + { + Console.WriteLine( "Warning: Unable to load filelist: {0}", ex.ToString() ); + } + } + string username = GetStringParameter( args, "-username" ); string password = GetStringParameter( args, "-password" ); - ContentDownloader.Download( depotId, depotVersion, cellId, username, password ); + ContentDownloader.Download( depotId, depotVersion, cellId, username, password, !bDebot, files ); } @@ -101,16 +134,19 @@ namespace DepotDownloader static void PrintUsage() { - Console.WriteLine( "\nUse: depotdownloader \n" ); + Console.WriteLine( "\nUse: depotdownloader [optional parameters]\n" ); Console.WriteLine( "Parameters:" ); 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-version [# or \"latest\"]\t- the version of the depot to download.\n" ); Console.WriteLine( "Optional Parameters:" ); 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.\n" ); + Console.WriteLine( "\t-password pass\t\t\t- the password of the account to login to for restricted content." ); + 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" ); } } }