Browse Source

Add support for quoting parameters with spaces

tags/v1.0.0
NorbiPeti 3 years ago
parent
commit
b2eea0abb9
Signed by: NorbiPeti <szatmari.norbert.peter@gmail.com> GPG Key ID: DBA4C4549A927E56
1 changed files with 19 additions and 4 deletions
  1. +19
    -4
      TBConsole/TBConsoleMod.cs

+ 19
- 4
TBConsole/TBConsoleMod.cs 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]);


Loading…
Cancel
Save