Add support for quoting parameters with spaces

This commit is contained in:
Norbi Peti 2021-05-13 01:12:03 +02:00
parent 056a581f60
commit b2eea0abb9
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -1,6 +1,6 @@
using System;
using System.IO;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using IllusionPlugin;
@ -28,8 +28,23 @@ namespace TBConsole
if (_logHandler == null)
Debug.unityLogger.logHandler = _logHandler = new UnityLogHandler(Debug.unityLogger.logHandler);
var logTask = _logHandler.CollectLogMessages();
var cmdparts = command.Split(' ');
switch (cmdparts.Length)
bool inString = false;
var cmdparts = new List<string>();
command = command.Trim();
int lastIndex = 0;
for (int i = 0; i <= command.Length; i++)
{
if (i < command.Length && command[i] == '"') inString = !inString;
else if (!inString && (i == command.Length || command[i] == ' '))
{
cmdparts.Add(command.Substring(lastIndex, i - lastIndex).Trim('"'));
lastIndex = i + 1;
}
}
//Console.WriteLine("Command parts: " + cmdparts.Aggregate((a, b) => a + ", " + b));
switch (cmdparts.Count)
{
case 1:
ExistingCommands.Call(cmdparts[0]);