From 987b51e82d45a713b03bed73711f4c318b4d47cf Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 10 Sep 2013 10:10:48 -0400 Subject: [PATCH] Simplify arg handling. --- DepotDownloader/ContentDownloader.cs | 4 +- DepotDownloader/Program.cs | 65 ++++++++++------------------ 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 8e307abe..106b0b8c 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -14,8 +14,8 @@ namespace DepotDownloader static class ContentDownloader { private const string DEFAULT_DIR = "depots"; - public const uint INVALID_APP_ID = 0xFFFFFFFF; - private const uint INVALID_DEPOT_ID = 0xFFFFFFFF; + public const uint INVALID_APP_ID = uint.MaxValue; + public const uint INVALID_DEPOT_ID = uint.MaxValue; public static DownloadConfig Config = new DownloadConfig(); diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 3681ba1c..325bd367 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using SteamKit2; +using System.ComponentModel; namespace DepotDownloader { @@ -18,9 +19,9 @@ namespace DepotDownloader DebugLog.Enabled = false; - bool bDumpManifest = HasParameter( args, "-manifest" ); - uint appId = GetUIntParameter( args, "-app" ); - uint depotId = GetUIntParameter( args, "-depot" ); + bool bDumpManifest = HasParameter( args, "-manifest-only" ); + uint appId = GetParameter( args, "-app", ContentDownloader.INVALID_APP_ID ); + uint depotId = GetParameter( args, "-depot", ContentDownloader.INVALID_DEPOT_ID ); if ( appId == ContentDownloader.INVALID_APP_ID ) { @@ -30,19 +31,16 @@ namespace DepotDownloader ContentDownloader.Config.DownloadManifestOnly = bDumpManifest; - int cellId = GetIntParameter(args, "-cellid"); - + int cellId = GetParameter(args, "-cellid", -1); if (cellId == -1) { cellId = 0; } ContentDownloader.Config.CellID = cellId; + ContentDownloader.Config.BetaPassword = GetParameter(args, "-betapassword"); - int depotVersion = GetIntParameter( args, "-version" ); - ContentDownloader.Config.BetaPassword = GetStringParameter( args, "-betapassword" ); - - string fileList = GetStringParameter( args, "-filelist" ); + string fileList = GetParameter(args, "-filelist"); string[] files = null; if ( fileList != null ) @@ -78,11 +76,11 @@ namespace DepotDownloader } } - string username = GetStringParameter(args, "-username"); - string password = GetStringParameter(args, "-password"); - ContentDownloader.Config.InstallDirectory = GetStringParameter(args, "-dir"); + string username = GetParameter(args, "-username"); + string password = GetParameter(args, "-password"); + ContentDownloader.Config.InstallDirectory = GetParameter(args, "-dir"); ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms"); - string branch = GetStringParameter(args, "-branch") ?? GetStringParameter(args, "-beta") ?? "Public"; + string branch = GetParameter(args, "-branch") ?? GetParameter(args, "-beta") ?? "Public"; if (username != null && password == null) { @@ -109,40 +107,23 @@ namespace DepotDownloader { return IndexOfParam( args, param ) > -1; } - static int GetIntParameter( string[] args, string param ) - { - string strParam = GetStringParameter( args, param ); - if ( strParam == null ) - return -1; - - int intParam = -1; - if ( !int.TryParse( strParam, out intParam ) ) - return -1; - - return intParam; - } - static uint GetUIntParameter(string[] args, string param) + static T GetParameter(string[] args, string param, T defaultValue = default(T)) { - string strParam = GetStringParameter(args, param); + int index = IndexOfParam(args, param); - if (strParam == null) - return 0xFFFFFFFF; + if (index == -1 || index == (args.Length - 1)) + return defaultValue; - uint intParam = 0xFFFFFFFF; - if (!uint.TryParse(strParam, out intParam)) - return 0xFFFFFFFF; + string strParam = args[index + 1]; - return intParam; - } - static string GetStringParameter( string[] args, string param ) - { - int index = IndexOfParam( args, param ); - - if ( index == -1 || index == ( args.Length - 1 ) ) - return null; - - return args[ index + 1 ]; + var converter = TypeDescriptor.GetConverter(typeof(T)); + if( converter != null ) + { + return (T)converter.ConvertFromString(strParam); + } + + return default(T); } static void PrintUsage()