Simplify arg handling.

pull/8/head
Nicholas Hastings 12 years ago
parent 36c961bc01
commit 987b51e82d

@ -14,8 +14,8 @@ namespace DepotDownloader
static class ContentDownloader static class ContentDownloader
{ {
private const string DEFAULT_DIR = "depots"; private const string DEFAULT_DIR = "depots";
public const uint INVALID_APP_ID = 0xFFFFFFFF; public const uint INVALID_APP_ID = uint.MaxValue;
private const uint INVALID_DEPOT_ID = 0xFFFFFFFF; public const uint INVALID_DEPOT_ID = uint.MaxValue;
public static DownloadConfig Config = new DownloadConfig(); public static DownloadConfig Config = new DownloadConfig();

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using SteamKit2; using SteamKit2;
using System.ComponentModel;
namespace DepotDownloader namespace DepotDownloader
{ {
@ -18,9 +19,9 @@ namespace DepotDownloader
DebugLog.Enabled = false; DebugLog.Enabled = false;
bool bDumpManifest = HasParameter( args, "-manifest" ); bool bDumpManifest = HasParameter( args, "-manifest-only" );
uint appId = GetUIntParameter( args, "-app" ); uint appId = GetParameter<uint>( args, "-app", ContentDownloader.INVALID_APP_ID );
uint depotId = GetUIntParameter( args, "-depot" ); uint depotId = GetParameter<uint>( args, "-depot", ContentDownloader.INVALID_DEPOT_ID );
if ( appId == ContentDownloader.INVALID_APP_ID ) if ( appId == ContentDownloader.INVALID_APP_ID )
{ {
@ -30,19 +31,16 @@ namespace DepotDownloader
ContentDownloader.Config.DownloadManifestOnly = bDumpManifest; ContentDownloader.Config.DownloadManifestOnly = bDumpManifest;
int cellId = GetIntParameter(args, "-cellid"); int cellId = GetParameter<int>(args, "-cellid", -1);
if (cellId == -1) if (cellId == -1)
{ {
cellId = 0; cellId = 0;
} }
ContentDownloader.Config.CellID = cellId; ContentDownloader.Config.CellID = cellId;
ContentDownloader.Config.BetaPassword = GetParameter<string>(args, "-betapassword");
int depotVersion = GetIntParameter( args, "-version" ); string fileList = GetParameter<string>(args, "-filelist");
ContentDownloader.Config.BetaPassword = GetStringParameter( args, "-betapassword" );
string fileList = GetStringParameter( args, "-filelist" );
string[] files = null; string[] files = null;
if ( fileList != null ) if ( fileList != null )
@ -78,11 +76,11 @@ namespace DepotDownloader
} }
} }
string username = GetStringParameter(args, "-username"); string username = GetParameter<string>(args, "-username");
string password = GetStringParameter(args, "-password"); string password = GetParameter<string>(args, "-password");
ContentDownloader.Config.InstallDirectory = GetStringParameter(args, "-dir"); ContentDownloader.Config.InstallDirectory = GetParameter<string>(args, "-dir");
ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms"); ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms");
string branch = GetStringParameter(args, "-branch") ?? GetStringParameter(args, "-beta") ?? "Public"; string branch = GetParameter<string>(args, "-branch") ?? GetParameter<string>(args, "-beta") ?? "Public";
if (username != null && password == null) if (username != null && password == null)
{ {
@ -109,40 +107,23 @@ namespace DepotDownloader
{ {
return IndexOfParam( args, param ) > -1; return IndexOfParam( args, param ) > -1;
} }
static int GetIntParameter( string[] args, string param )
{
string strParam = GetStringParameter( args, param );
if ( strParam == null ) static T GetParameter<T>(string[] args, string param, T defaultValue = default(T))
return -1;
int intParam = -1;
if ( !int.TryParse( strParam, out intParam ) )
return -1;
return intParam;
}
static uint GetUIntParameter(string[] args, string param)
{ {
string strParam = GetStringParameter(args, param); int index = IndexOfParam(args, param);
if (strParam == null) if (index == -1 || index == (args.Length - 1))
return 0xFFFFFFFF; return defaultValue;
uint intParam = 0xFFFFFFFF; string strParam = args[index + 1];
if (!uint.TryParse(strParam, out intParam))
return 0xFFFFFFFF;
return intParam; var converter = TypeDescriptor.GetConverter(typeof(T));
} if( converter != null )
static string GetStringParameter( string[] args, string param )
{ {
int index = IndexOfParam( args, param ); return (T)converter.ConvertFromString(strParam);
}
if ( index == -1 || index == ( args.Length - 1 ) )
return null;
return args[ index + 1 ]; return default(T);
} }
static void PrintUsage() static void PrintUsage()

Loading…
Cancel
Save