using System; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using SteamKit2; using System.ComponentModel; namespace DepotDownloader { class Program { static void Main( string[] args ) { if ( args.Length == 0 ) { PrintUsage(); return; } DebugLog.Enabled = false; ConfigStore.LoadFromFile(Path.Combine(Environment.CurrentDirectory, "DepotDownloader.config")); bool bDumpManifest = HasParameter( args, "-manifest-only" ); uint appId = GetParameter( args, "-app", ContentDownloader.INVALID_APP_ID ); uint depotId = GetParameter( args, "-depot", ContentDownloader.INVALID_DEPOT_ID ); ContentDownloader.Config.ManifestId = GetParameter( args, "-manifest", ContentDownloader.INVALID_MANIFEST_ID ); if ( appId == ContentDownloader.INVALID_APP_ID ) { Console.WriteLine( "Error: -app not specified!" ); return; } if (depotId == ContentDownloader.INVALID_DEPOT_ID && ContentDownloader.Config.ManifestId != ContentDownloader.INVALID_MANIFEST_ID) { Console.WriteLine("Error: -manifest requires -depot to be specified"); return; } ContentDownloader.Config.DownloadManifestOnly = bDumpManifest; int cellId = GetParameter(args, "-cellid", -1); if (cellId == -1) { cellId = 0; } ContentDownloader.Config.CellID = cellId; ContentDownloader.Config.BetaPassword = GetParameter(args, "-betapassword"); string fileList = GetParameter(args, "-filelist"); string[] files = null; if ( fileList != null ) { try { string fileListData = File.ReadAllText( fileList ); files = fileListData.Split( new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries ); ContentDownloader.Config.UsingFileList = true; ContentDownloader.Config.FilesToDownload = new List(); ContentDownloader.Config.FilesToDownloadRegex = new List(); foreach (var fileEntry in files) { try { Regex rgx = new Regex(fileEntry, RegexOptions.Compiled | RegexOptions.IgnoreCase); ContentDownloader.Config.FilesToDownloadRegex.Add(rgx); } catch { ContentDownloader.Config.FilesToDownload.Add(fileEntry); continue; } } Console.WriteLine( "Using filelist: '{0}'.", fileList ); } catch ( Exception ex ) { Console.WriteLine( "Warning: Unable to load filelist: {0}", ex.ToString() ); } } string username = GetParameter(args, "-username") ?? GetParameter(args, "-user"); string password = GetParameter(args, "-password") ?? GetParameter(args, "-pass"); ContentDownloader.Config.InstallDirectory = GetParameter(args, "-dir"); ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms"); ContentDownloader.Config.VerifyAll = HasParameter(args, "-verify-all") || HasParameter(args, "-verify_all") || HasParameter(args, "-validate"); ContentDownloader.Config.MaxServers = GetParameter(args, "-max-servers", 8); ContentDownloader.Config.MaxDownloads = GetParameter(args, "-max-downloads", 4); string branch = GetParameter(args, "-branch") ?? GetParameter(args, "-beta") ?? "Public"; var forceDepot = HasParameter(args, "-force-depot"); ContentDownloader.Config.MaxServers = Math.Max(ContentDownloader.Config.MaxServers, ContentDownloader.Config.MaxDownloads); if (username != null && password == null) { Console.Write("Enter account password for \"{0}\": ", username); password = Util.ReadPassword(); Console.WriteLine(); } else if (username == null) { Console.WriteLine("No username given. Using anonymous account with dedicated server subscription."); } ContentDownloader.InitializeSteam3(username, password); ContentDownloader.DownloadApp(appId, depotId, branch, forceDepot); ContentDownloader.ShutdownSteam3(); } static int IndexOfParam( string[] args, string param ) { for ( int x = 0 ; x < args.Length ; ++x ) { if ( args[ x ].Equals( param, StringComparison.OrdinalIgnoreCase ) ) return x; } return -1; } static bool HasParameter( string[] args, string param ) { return IndexOfParam( args, param ) > -1; } static T GetParameter(string[] args, string param, T defaultValue = default(T)) { int index = IndexOfParam(args, param); if (index == -1 || index == (args.Length - 1)) return defaultValue; string strParam = args[index + 1]; var converter = TypeDescriptor.GetConverter(typeof(T)); if( converter != null ) { return (T)converter.ConvertFromString(strParam); } return default(T); } static void PrintUsage() { Console.WriteLine( "\nUsage: depotdownloader [optional parameters]\n" ); Console.WriteLine( "Parameters:" ); Console.WriteLine("\t-app <#>\t\t\t\t- the AppID to download."); Console.WriteLine(); Console.WriteLine( "Optional Parameters:" ); Console.WriteLine( "\t-depot <#>\t\t\t- the DepotID to download." ); Console.WriteLine( "\t-cellid <#>\t\t\t- the overridden CellID of the content server to download from." ); Console.WriteLine( "\t-username \t\t\t- the username of the account to login to for restricted content." ); Console.WriteLine( "\t-password \t\t\t- the password of the account to login to for restricted content." ); Console.WriteLine( "\t-dir \t\t\t- the directory in which to place downloaded files." ); Console.WriteLine( "\t-filelist \t\t- a list of files to download (from the manifest). Can optionally use regex to download only certain files." ); Console.WriteLine( "\t-all-platforms\t\t\t- downloads all platform-specific depots when -app is used." ); Console.WriteLine( "\t-manifest-only\t\t\t- downloads a human readable manifest for any depots that would be downloaded." ); Console.WriteLine( "\t-beta \t\t\t\t- download from specified branch if available (default: Public)." ); Console.WriteLine( "\t-betapassword \t\t\t- branch password if applicable." ); Console.WriteLine( "\t-manifest \t\t\t- manifest id of content to download (requires -depot, default: current for branch)." ); Console.WriteLine( "\t-max-servers <#>\t\t\t- maximum number of content servers to use. (default: 8)." ); Console.WriteLine( "\t-max-downloads <#>\t\t\t- maximum number of chunks to download concurrently. (default: 4)." ); } } }