* Added a ModConfig, allowing you to define the main menu toggle keybind and the default window size (so far).
* Made the parsing of arguments more intelligent, should now behave as expected for null or empty arguments.
This commit is contained in:
sinaioutlander
2020-09-10 20:31:09 +10:00
parent a927b5ed21
commit 1d739a1936
6 changed files with 97 additions and 20 deletions

View File

@ -244,30 +244,41 @@ namespace Explorer
var input = m_argumentInput[i];
var type = m_arguments[i].ParameterType;
if (type == typeof(string))
// First, try parse the input and use that.
if (!string.IsNullOrEmpty(input))
{
parsedArgs.Add(input);
}
else
{
try
// strings can obviously just be used directly
if (type == typeof(string))
{
parsedArgs.Add(type.GetMethod("Parse", new Type[] { typeof(string) })
.Invoke(null, new object[] { input }));
parsedArgs.Add(input);
continue;
}
catch
else
{
if (m_arguments[i].HasDefaultValue)
// try to invoke the parse method and use that.
try
{
parsedArgs.Add(m_arguments[i].DefaultValue);
parsedArgs.Add(type.GetMethod("Parse", new Type[] { typeof(string) })
.Invoke(null, new object[] { input }));
continue;
}
else
catch
{
// Try add a null arg I guess
parsedArgs.Add(null);
MelonLogger.Log($"Argument #{i} '{m_arguments[i].Name}' ({type.Name}), could not parse input '{input}'.");
}
}
}
// Didn't use input, see if there is a default value.
if (m_arguments[i].HasDefaultValue)
{
parsedArgs.Add(m_arguments[i].DefaultValue);
continue;
}
// Try add a null arg I guess
parsedArgs.Add(null);
}
return parsedArgs.ToArray();