Fix Argument exception.

pull/583/head
Alstruit 10 months ago
parent 73329330d3
commit 78e6141e97
No known key found for this signature in database
GPG Key ID: 4F57E6793C946CEC

@ -413,31 +413,76 @@ namespace DepotDownloader
static List<T> GetParameterList<T>(string[] args, string param) static List<T> GetParameterList<T>(string[] args, string param)
{ {
var list = new List<T>(); var list = new List<T>();
var index = IndexOfParam(args, param);
if (index == -1 || index == (args.Length - 1)) var converter = TypeDescriptor.GetConverter(typeof(T));
if (converter == null)
{
Console.WriteLine($"Warning: No type converter available for type {typeof(T)}");
return list; return list;
}
index++; int index = 0;
while (index < args.Length) while (index < args.Length)
{ {
var strParam = args[index]; // Find the next occurrence of the parameter
if (args[index].Equals(param, StringComparison.OrdinalIgnoreCase))
{
index++; // Move to the value(s) after the parameter
if (strParam[0] == '-') break; // Process values following the parameter
while (index < args.Length && !args[index].StartsWith("-"))
{
var strParam = args[index];
var converter = TypeDescriptor.GetConverter(typeof(T)); // Handle space-separated values within a single argument
if (converter != null) if (strParam.Contains(" "))
{
var values = strParam.Split(' ', StringSplitOptions.RemoveEmptyEntries);
foreach (var val in values)
{
try
{
var convertedValue = converter.ConvertFromString(val);
if (convertedValue != null)
{
list.Add((T)convertedValue);
}
}
catch (Exception ex)
{ {
list.Add((T)converter.ConvertFromString(strParam)); Console.WriteLine($"Warning: Unable to convert value '{val}' to type {typeof(T)}. Exception: {ex.Message}");
}
}
}
else
{
try
{
var convertedValue = converter.ConvertFromString(strParam);
if (convertedValue != null)
{
list.Add((T)convertedValue);
}
}
catch (Exception ex)
{
Console.WriteLine($"Warning: Unable to convert value '{strParam}' to type {typeof(T)}. Exception: {ex.Message}");
}
} }
index++; index++;
} }
}
else
{
index++;
}
}
return list; return list;
} }
static void PrintUsage() static void PrintUsage()
{ {
// Do not use tabs to align parameters here because tab size may differ // Do not use tabs to align parameters here because tab size may differ

Loading…
Cancel
Save