diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index d70b356..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "version": "0.2.0", - "configurations": [ - - { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/RecrownedAthenaeum.Tools/bin/Debug/netcoreapp2.1/RecrownedAthenaeum.Tools.dll", - "args": [], - "cwd": "${workspaceFolder}/RecrownedAthenaeum.Tools", - // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index fe38c82..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/RecrownedAthenaeum.Tools/RecrownedAthenaeum.Tools.csproj" - ], - "problemMatcher": "$tsc" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/RecrownedAthenaeum.Tools/RecrownedAthenaeum.Tools.csproj" - ], - "problemMatcher": "$tsc" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/RecrownedAthenaeum.Tools/RecrownedAthenaeum.Tools.csproj" - ], - "problemMatcher": "$tsc" - } - ] -} \ No newline at end of file diff --git a/RecrownedGTK.Tests/RecrownedGTK.Tests.csproj b/RecrownedGTK.Tests/RecrownedGTK.Tests.csproj index 0bac341..224d02d 100644 --- a/RecrownedGTK.Tests/RecrownedGTK.Tests.csproj +++ b/RecrownedGTK.Tests/RecrownedGTK.Tests.csproj @@ -2,6 +2,7 @@ net48 + portable false diff --git a/RecrownedGTK.Tools.Tests/.vscode/launch.json b/RecrownedGTK.Tools.Tests/.vscode/launch.json deleted file mode 100644 index 1074ace..0000000 --- a/RecrownedGTK.Tools.Tests/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/RecrownedGTK.Tools.Tests.dll", - "args": [], - "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/RecrownedGTK.Tools.Tests/.vscode/tasks.json b/RecrownedGTK.Tools.Tests/.vscode/tasks.json deleted file mode 100644 index b832770..0000000 --- a/RecrownedGTK.Tools.Tests/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/RecrownedGTK.Tools.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/RecrownedGTK.Tools.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/RecrownedGTK.Tools.Tests.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/RecrownedGTK.Tools.Tests/CommandProcessor/CommandEngineTest.cs b/RecrownedGTK.Tools.Tests/CommandProcessor/CommandEngineTest.cs index d4d4c50..fd227f6 100644 --- a/RecrownedGTK.Tools.Tests/CommandProcessor/CommandEngineTest.cs +++ b/RecrownedGTK.Tools.Tests/CommandProcessor/CommandEngineTest.cs @@ -44,15 +44,14 @@ namespace RecrownedGTK.Tools.Tests.CommandProcessor this.commandArguments = engineCommandArguments; } - public override void Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments) + public override bool Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments) { if (arguments != null && arguments[0] != null) { userOutput.Output(arguments[0] + " argument"); } else { userOutput.Output(userInput.GetInput() + " input"); } - - + return true; } } diff --git a/RecrownedGTK.Tools.Tests/CommandProcessor/EngineCommandTest.cs b/RecrownedGTK.Tools.Tests/CommandProcessor/EngineCommandTest.cs index 056c790..2577010 100644 --- a/RecrownedGTK.Tools.Tests/CommandProcessor/EngineCommandTest.cs +++ b/RecrownedGTK.Tools.Tests/CommandProcessor/EngineCommandTest.cs @@ -43,15 +43,14 @@ namespace RecrownedGTK.Tools.Tests.CommandProcessor { this.commandArguments = engineCommandArguments; } - public override void Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments) + public override bool Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments) { if (arguments != null && arguments[0] != null) { userOutput.Output(arguments[0] + " argument"); } else { userOutput.Output(userInput.GetInput() + " input"); } - - + return true; } } diff --git a/RecrownedGTK.Tools.Tests/RecrownedGTK.Tools.Tests.csproj b/RecrownedGTK.Tools.Tests/RecrownedGTK.Tools.Tests.csproj index 73a5205..9ab6617 100644 --- a/RecrownedGTK.Tools.Tests/RecrownedGTK.Tools.Tests.csproj +++ b/RecrownedGTK.Tools.Tests/RecrownedGTK.Tools.Tests.csproj @@ -2,7 +2,7 @@ net48 - + portable false diff --git a/RecrownedGTK.Tools/.vscode/launch.json b/RecrownedGTK.Tools/.vscode/launch.json index 50e2494..79efaf5 100644 --- a/RecrownedGTK.Tools/.vscode/launch.json +++ b/RecrownedGTK.Tools/.vscode/launch.json @@ -5,23 +5,14 @@ "version": "0.2.0", "configurations": [ { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/RecrownedGTK.Tools.dll", - "args": [], - "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", + "name": "Debug R.Tools", "request": "attach", - "processId": "${command:pickProcess}" + "type": "mono", + "address": "localhost", + "port": 55555, + "preLaunchTask": "launch debug server", + "postDebugTask": "stop debug server" + } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/RecrownedGTK.Tools/.vscode/settings.json similarity index 100% rename from .vscode/settings.json rename to RecrownedGTK.Tools/.vscode/settings.json diff --git a/RecrownedGTK.Tools/.vscode/tasks.json b/RecrownedGTK.Tools/.vscode/tasks.json index abc3f1d..f225c3a 100644 --- a/RecrownedGTK.Tools/.vscode/tasks.json +++ b/RecrownedGTK.Tools/.vscode/tasks.json @@ -1,42 +1,31 @@ { + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", + "type": "shell", "command": "dotnet", - "type": "process", "args": [ - "build", - "${workspaceFolder}/RecrownedGTK.Tools.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" + "build" ], - "problemMatcher": "$msCompile" + "problemMatcher": [] }, { - "label": "publish", - "command": "dotnet", + "dependsOn": ["build"], + "label": "launch debug server", "type": "process", - "args": [ - "publish", - "${workspaceFolder}/RecrownedGTK.Tools.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" + "command": "powershell", + "problemMatcher": [], + "args": ["-ExecutionPolicy", "Bypass", "-File", "./start_process.ps1"] }, { - "label": "watch", - "command": "dotnet", + "label": "stop debug server", "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/RecrownedGTK.Tools.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" + "command": "powershell", + "problemMatcher": [], + "args": ["-ExecutionPolicy", "Bypass", "-File", "./end_process.ps1"] } ] } \ No newline at end of file diff --git a/RecrownedGTK.Tools/CommandProcessor/CommandEngine.cs b/RecrownedGTK.Tools/CommandProcessor/CommandEngine.cs index 464b2b8..773d71a 100644 --- a/RecrownedGTK.Tools/CommandProcessor/CommandEngine.cs +++ b/RecrownedGTK.Tools/CommandProcessor/CommandEngine.cs @@ -18,17 +18,9 @@ namespace RecrownedGTK.Tools.CommandProcessor { while (running) { - output.WrappedOutput("\nAwaiting command."); + output.WriteLine("Awaiting command."); string command = input.GetInput(); - try - { - Process(input, output, command); - - } - catch (ArgumentException ae) - { - output.WrappedOutput("Error: " + ae.Message); - } + Process(input, output, command); } } @@ -39,11 +31,13 @@ namespace RecrownedGTK.Tools.CommandProcessor } string command = commandAndArguments; string[] arguments = null; - + if (!ContainsCommand(command)) { + userOutput.Write("Unable to find command. Type \"help\" for more information."); + return; + } if (commandAndArguments.Contains(" ")) { command = command.Remove(command.IndexOf(' ')); - if (!ContainsCommand(command)) throw new ArgumentException("Command not found."); string[] argumentsSplit = commandAndArguments.Substring(command.Length + 1).Split(' '); List argumentsList = new List(); @@ -59,7 +53,7 @@ namespace RecrownedGTK.Tools.CommandProcessor i++; if (i >= argumentsSplit.Length) { - throw new ArgumentException("Argument is missing terminating \'\"\'"); + userOutput.Write("Argument is missing terminating \'\"\'"); } } while (!argumentsSplit[i].Contains("\"")); @@ -74,8 +68,9 @@ namespace RecrownedGTK.Tools.CommandProcessor } arguments = argumentsList.ToArray(); } - if (!ContainsCommand(command)) throw new ArgumentException("Command not found. Type \"help\" for a list of commands."); - GetCommand(command).Run(userInput, userOutput, arguments); + if (!GetCommand(command).Run(userInput, userOutput, arguments)) { + userOutput.Write("Command {0} was not used correctly. Please refer to \"help\" for more information."); + } } /// diff --git a/RecrownedGTK.Tools/CommandProcessor/Commands/ClearConsoleCommand.cs b/RecrownedGTK.Tools/CommandProcessor/Commands/ClearConsoleCommand.cs index a868697..1c8a2f4 100644 --- a/RecrownedGTK.Tools/CommandProcessor/Commands/ClearConsoleCommand.cs +++ b/RecrownedGTK.Tools/CommandProcessor/Commands/ClearConsoleCommand.cs @@ -4,14 +4,14 @@ namespace RecrownedGTK.Tools.CommandProcessor.Commands { public class ClearConsoleCommand : EngineCommand { - public ClearConsoleCommand() : base("clear") + public ClearConsoleCommand() : base("Clears the console.", "clear") { - help = "Clears the console."; } - public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null) + public override bool Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null) { userOutput.ClearOutput(); + return true; } } } diff --git a/RecrownedGTK.Tools/CommandProcessor/Commands/HelpCommand.cs b/RecrownedGTK.Tools/CommandProcessor/Commands/HelpCommand.cs index c3f0d0d..3936cbd 100644 --- a/RecrownedGTK.Tools/CommandProcessor/Commands/HelpCommand.cs +++ b/RecrownedGTK.Tools/CommandProcessor/Commands/HelpCommand.cs @@ -6,49 +6,49 @@ namespace RecrownedGTK.Tools.CommandProcessor.Commands { CommandEngine commandEngine; - public HelpCommand(CommandEngine commandEngine) : base("help") + public HelpCommand(CommandEngine commandEngine) : base("help [command] [arg]", "help") { this.commandEngine = commandEngine; - help = "help [command] [arg]"; } - public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments) + public override bool Run(IUserInput userInput, IUserOutput userOutput, string[] arguments) { if (arguments != null) { if (commandEngine.ContainsCommand(arguments[0])) { - if (arguments.Length < 2) userOutput.WrappedOutput(commandEngine.GetCommand(arguments[0]).Help(null)); + if (arguments.Length < 2) userOutput.WriteLine(commandEngine.GetCommand(arguments[0]).Help(null)); for (int i = 1; i < arguments.Length; i++) { - userOutput.WrappedOutput(commandEngine.GetCommand(arguments[0]).Help(arguments[i])); + userOutput.WriteLine(commandEngine.GetCommand(arguments[0]).Help(arguments[i])); } } else { - throw new ArgumentException(arguments[0] + " not a command. Type \"help\" for a list of commands."); + return false; } } else { - userOutput.WrappedOutput("Tools for RecrownedGTK library. Possible commands are as follows:\n"); + userOutput.WriteLine("Tools for RecrownedGTK library. Possible commands are as follows:\n"); foreach (EngineCommand engineCommand in commandEngine.commands) { for (int i = 0; i < engineCommand.InvokeStrings.Length; i++) { - userOutput.WrappedOutput(engineCommand.InvokeStrings[i]); + userOutput.Write(engineCommand.InvokeStrings[i]); if (i + 1 < engineCommand.InvokeStrings.Length) { - userOutput.WrappedOutput(", "); + userOutput.Write(", "); } } - userOutput.WrappedOutput(" : "); - userOutput.WrappedOutput(engineCommand.Help().Replace("\n", "\n\t")); - userOutput.WrappedOutput("\n"); - userOutput.Output("--------"); + userOutput.Write(": "); + userOutput.Write(engineCommand.Help()); + userOutput.Write("\n"); + userOutput.WriteLine("--------"); } } + return true; } } } diff --git a/RecrownedGTK.Tools/CommandProcessor/Commands/StopCommand.cs b/RecrownedGTK.Tools/CommandProcessor/Commands/StopCommand.cs index 6cadc89..0397bb6 100644 --- a/RecrownedGTK.Tools/CommandProcessor/Commands/StopCommand.cs +++ b/RecrownedGTK.Tools/CommandProcessor/Commands/StopCommand.cs @@ -4,15 +4,15 @@ { CommandEngine commandEngine; - public StopCommand(CommandEngine commandEngine) : base("quit", "stop", "q", "exit") + public StopCommand(CommandEngine commandEngine) : base("Exits the tool.", "quit", "stop", "q", "exit") { this.commandEngine = commandEngine; - help = "Exits the tool."; } - public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null) + public override bool Run(IUserInput userInput, IUserOutput userOutput, string[] arguments = null) { commandEngine.running = false; + return true; } } } diff --git a/RecrownedGTK.Tools/CommandProcessor/EngineCommand.cs b/RecrownedGTK.Tools/CommandProcessor/EngineCommand.cs index 7d861a9..03f1450 100644 --- a/RecrownedGTK.Tools/CommandProcessor/EngineCommand.cs +++ b/RecrownedGTK.Tools/CommandProcessor/EngineCommand.cs @@ -18,8 +18,8 @@ namespace RecrownedGTK.Tools.CommandProcessor /// /// Arguments that this command should accept and take into account. /// - protected EngineCommandArgument[] commandArguments; - protected string help; + protected EngineCommandArgument[] arguments; + protected readonly string help; public EngineCommand(string help, params string[] invokeStrings) { @@ -56,10 +56,13 @@ namespace RecrownedGTK.Tools.CommandProcessor } /// - /// Runs the command. + /// Runs the engine command. /// - /// arguments to be used. Each string should be the argument input. May be null. - public abstract void Run(IUserInput userInput = null, IUserOutput userOutput = null, params string[] arguments); + /// The user input object. + /// The user output object. + /// The arguments. + /// True if the command executed successfully, otherwise false to display a help message. + public abstract bool Run(IUserInput userInput, IUserOutput userOutput, params string[] arguments); /// /// Check if given argument is viable for command. @@ -78,11 +81,11 @@ namespace RecrownedGTK.Tools.CommandProcessor /// null if not viable or the if viable. public EngineCommandArgument EngineCommandArgumentOf(string argument) { - for (int i = 0; i < commandArguments.Length; i++) + for (int i = 0; i < arguments.Length; i++) { - if (commandArguments[i].invokeString == argument) + if (arguments[i].invokeString == argument) { - return commandArguments[i]; + return arguments[i]; } } return null; @@ -147,7 +150,7 @@ namespace RecrownedGTK.Tools.CommandProcessor /// The string for the help. public string Help(string argument = null) { - if (argument != null && commandArguments != null) + if (argument != null && arguments != null) { if (Validate(argument)) { @@ -165,25 +168,24 @@ namespace RecrownedGTK.Tools.CommandProcessor { StringBuilder helpBuilder = new StringBuilder(); helpBuilder.Append(help); - if (commandArguments != null) + if (arguments != null) { helpBuilder.AppendLine(); helpBuilder.Append("Possible arguments: "); - for (int i = 0; i < commandArguments.Length; i++) + for (int i = 0; i < arguments.Length; i++) { - helpBuilder.Append(commandArguments[i].invokeString); - if (commandArguments[i].required) helpBuilder.Append('*'); - if (i == commandArguments.Length - 2) + helpBuilder.Append(arguments[i].invokeString); + if (arguments[i].required) helpBuilder.Append('*'); + if (i == arguments.Length - 2) { helpBuilder.Append(", and "); } - else if (i < commandArguments.Length - 2) + else if (i < arguments.Length - 2) { helpBuilder.Append(", "); } } - helpBuilder.Append('.'); - helpBuilder.AppendLine(" (* are required arguments.)"); + helpBuilder.Append(". (* are required arguments.)"); } return helpBuilder.ToString(); } diff --git a/RecrownedGTK.Tools/CommandProcessor/IUserOutput.cs b/RecrownedGTK.Tools/CommandProcessor/IUserOutput.cs index 55dbfa7..de37f7d 100644 --- a/RecrownedGTK.Tools/CommandProcessor/IUserOutput.cs +++ b/RecrownedGTK.Tools/CommandProcessor/IUserOutput.cs @@ -1,8 +1,8 @@ namespace RecrownedGTK.Tools.CommandProcessor { public interface IUserOutput { - void Output(string output); - void WrappedOutput(string output); + void WriteLine(string output); + void Write(string output); void ClearOutput(); } } \ No newline at end of file diff --git a/RecrownedGTK.Tools/ConsoleInterface/ConsoleProgram.cs b/RecrownedGTK.Tools/ConsoleInterface/ConsoleProgram.cs index 2ad1daa..3218475 100644 --- a/RecrownedGTK.Tools/ConsoleInterface/ConsoleProgram.cs +++ b/RecrownedGTK.Tools/ConsoleInterface/ConsoleProgram.cs @@ -17,12 +17,12 @@ namespace RecrownedGTK.Tools.ConsoleInterface } private class ConsoleOutput : IUserOutput { - public void Output(string output) { - Console.WriteLine(output); + public void WriteLine(string output) { + Console.WriteLine(ConsoleUtilities.WrapMessageToConsoleWidth(output)); } - public void WrappedOutput(string output) { - ConsoleUtilities.WrapMessageToConsoleWidth(output); + public void Write(string output) { + Console.Write(ConsoleUtilities.WrapMessageToConsoleWidth(output)); } public void ClearOutput() { diff --git a/RecrownedGTK.Tools/ConsoleInterface/ConsoleUtilities.cs b/RecrownedGTK.Tools/ConsoleInterface/ConsoleUtilities.cs index 3f0191b..63de190 100644 --- a/RecrownedGTK.Tools/ConsoleInterface/ConsoleUtilities.cs +++ b/RecrownedGTK.Tools/ConsoleInterface/ConsoleUtilities.cs @@ -12,7 +12,7 @@ namespace RecrownedGTK.Tools.ConsoleInterface int currentLineSize = 0; for (int i = 0; i < words.Length; i++) { - if (currentLineSize + words[i].Length >= Console.BufferWidth - Console.CursorLeft -1) + if (currentLineSize + words[i].Length > Console.BufferWidth - Console.CursorLeft) { currentLineSize = 0; stringBuilder.AppendLine(); @@ -32,7 +32,6 @@ namespace RecrownedGTK.Tools.ConsoleInterface stringBuilder.Append(' '); } } - stringBuilder.AppendLine(); return stringBuilder.ToString(); } } diff --git a/RecrownedGTK.Tools/NinePatchTools/NinePatchCommand.cs b/RecrownedGTK.Tools/NinePatchTools/NinePatchCommand.cs index 8829660..262dc7d 100644 --- a/RecrownedGTK.Tools/NinePatchTools/NinePatchCommand.cs +++ b/RecrownedGTK.Tools/NinePatchTools/NinePatchCommand.cs @@ -9,32 +9,30 @@ namespace RecrownedGTK.Tools.NinePatchTools public class NinePatchCommand : EngineCommand { - public NinePatchCommand() : base("9p", "ninepatch", "9patch") + public NinePatchCommand() : base("Generates a 9 patch file for a given image.", "9p", "ninepatch", "9patch") { - help = "Generates a 9 patch file for a given image."; + arguments = new EngineCommandArgument[6]; - commandArguments = new EngineCommandArgument[6]; - - commandArguments[0] = new EngineCommandArgument("-i", "defines the path to the texture to be used for the nine patch.", true); - commandArguments[1] = new EngineCommandArgument("-o", "defines path of output file."); - commandArguments[2] = new EngineCommandArgument("-l", "left patch.", true); - commandArguments[3] = new EngineCommandArgument("-r", "right patch.", true); - commandArguments[4] = new EngineCommandArgument("-t", "top patch.", true); - commandArguments[5] = new EngineCommandArgument("-b", "bottom patch.", true); + arguments[0] = new EngineCommandArgument("-i", "defines the path to the texture to be used for the nine patch.", true); + arguments[1] = new EngineCommandArgument("-o", "defines path of output file."); + arguments[2] = new EngineCommandArgument("-l", "left patch.", true); + arguments[3] = new EngineCommandArgument("-r", "right patch.", true); + arguments[4] = new EngineCommandArgument("-t", "top patch.", true); + arguments[5] = new EngineCommandArgument("-b", "bottom patch.", true); } - public override void Run(IUserInput userInput = null, IUserOutput userOutput = null, string[] arguments = null) + public override bool Run(IUserInput userInput = null, IUserOutput userOutput = null, string[] arguments = null) { if (arguments == null) throw new ArgumentException("Missing arguments. Type \"help 9p\" for more information."); int leftBound = 0, rightBound = 0, topBound = 0, bottomBound = 0; string imagePath, outPath; - if (IndexOfArgument("-i", arguments) + 1 >= arguments.Length) throw new ArgumentException("Missing -i path after argument."); + if (IndexOfArgument("-i", arguments) + 1 >= arguments.Length) userOutput.WriteLine("Missing -i path after argument."); imagePath = arguments[IndexOfArgument("-i", arguments) + 1]; - if (!File.Exists(imagePath)) throw new ArgumentException("Input file does not exist at " + imagePath + "."); + if (!File.Exists(imagePath)) userOutput.WriteLine("Input file does not exist at " + imagePath + "."); - if (HasArgument(commandArguments[1], arguments)) + if (HasArgument(base.arguments[1], arguments)) { - if (IndexOfArgument("-o", arguments) + 1 >= arguments.Length) throw new ArgumentException("Missing -o path after argument."); + if (IndexOfArgument("-o", arguments) + 1 >= arguments.Length) userOutput.WriteLine("Missing -o path after argument."); outPath = arguments[IndexOfArgument("-o", arguments) + 1]; } else { @@ -51,8 +49,10 @@ namespace RecrownedGTK.Tools.NinePatchTools File.Move(imagePath, modifiedPath); File.WriteAllText(outPath + ".9p", serialized); - userOutput.WrappedOutput("Done. Written to \"" + outPath + "\" with values: left = " + leftBound + " right = " + rightBound + " top = " + topBound + " bottom = " + bottomBound); - userOutput.WrappedOutput("Image renamed to: " + Path.GetFileName(modifiedPath)); + userOutput.WriteLine("Done. Written to \"" + outPath + "\" with values: left = " + leftBound + " right = " + rightBound + " top = " + topBound + " bottom = " + bottomBound); + userOutput.WriteLine("Image renamed to: " + Path.GetFileName(modifiedPath)); + + return true; } } } diff --git a/RecrownedGTK.Tools/RecrownedGTK.Tools.csproj b/RecrownedGTK.Tools/RecrownedGTK.Tools.csproj index 574672a..2f09f86 100644 --- a/RecrownedGTK.Tools/RecrownedGTK.Tools.csproj +++ b/RecrownedGTK.Tools/RecrownedGTK.Tools.csproj @@ -7,6 +7,7 @@ RecrownedGTK.Tools RecrownedGTK.Tools + portable diff --git a/RecrownedGTK.Tools/TextureAtlasTools/TexturePacker.cs b/RecrownedGTK.Tools/TextureAtlasTools/TexturePacker.cs index 4c04fa5..01138eb 100644 --- a/RecrownedGTK.Tools/TextureAtlasTools/TexturePacker.cs +++ b/RecrownedGTK.Tools/TextureAtlasTools/TexturePacker.cs @@ -53,7 +53,7 @@ namespace RecrownedGTK.Tools.TextureAtlas SupportedExtensions extension; if (Enum.TryParse(Path.GetExtension(paths[pathID]).ToLower().Substring(1), out extension)) { - userOutput.WrappedOutput("Reading texture data for: " + paths[pathID]); + userOutput.WriteLine("Reading texture data for: " + paths[pathID]); ImageHandler image = new ImageHandler(paths[pathID]); imageHandlers.Add(image); minAreaRequired += image.Area; @@ -65,7 +65,7 @@ namespace RecrownedGTK.Tools.TextureAtlas else if (Path.GetExtension(paths[pathID]).ToLower() == ".9p") { if (ninePatchDictionary == null) ninePatchDictionary = new Dictionary(); - userOutput.WrappedOutput("Reading ninepatch data for: " + paths[pathID]); + userOutput.WriteLine("Reading ninepatch data for: " + paths[pathID]); string serialized = File.ReadAllText(paths[pathID]); NinePatchInfo npData = JsonConvert.DeserializeObject(serialized); ninePatchDictionary.Add(npData.name, npData); diff --git a/RecrownedGTK.Tools/TextureAtlasTools/TexturePackerCommand.cs b/RecrownedGTK.Tools/TextureAtlasTools/TexturePackerCommand.cs index 03972c4..fc3a9b1 100644 --- a/RecrownedGTK.Tools/TextureAtlasTools/TexturePackerCommand.cs +++ b/RecrownedGTK.Tools/TextureAtlasTools/TexturePackerCommand.cs @@ -9,10 +9,9 @@ namespace RecrownedGTK.Tools.TextureAtlasTools { private const int DMP = 9; private const int DSP = 6; - public TexturePackerCommand() : base("texturepacker") + public TexturePackerCommand() : base("Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties. Images with the associated \".9p\" files will automatically be defined in the resulting .tatlas file, but can be overwritten by use of the \"-9p\" argument.", "texturepacker") { - help = "Packs a given directory composed of png and jpg files into an atlas. Can also add 9patch properties. Images with the associated \".9p\" files will automatically be defined in the resulting .tatlas file, but can be overwritten by use of the \"-9p\" argument."; - commandArguments = new[] { + arguments = new[] { new EngineCommandArgument("-interactive", "runs in interactive mode. Ninepatches must still be defined with arguments or previously defined with associated \".9p\" files. Other arguments will be ignored."), new EngineCommandArgument("-i", "for input directory containing the textures.", true), new EngineCommandArgument("-o", "Path for output files. Points to non-existent file. Will create texture and definitions file with name.", true), @@ -23,7 +22,7 @@ namespace RecrownedGTK.Tools.TextureAtlasTools }; } - public override void Run(IUserInput userInput, IUserOutput userOutput, string[] arguments) + public override bool Run(IUserInput userInput, IUserOutput userOutput, string[] arguments) { TexturePacker texturePacker = null; @@ -36,30 +35,30 @@ namespace RecrownedGTK.Tools.TextureAtlasTools if (HasArgument("-interactive", arguments)) { string input; - userOutput.WrappedOutput("Texture packer interactive mode triggered. Type \"q\" at any time to exit."); - userOutput.WrappedOutput("Please enter path of folder containing the textures to be packed."); + userOutput.WriteLine("Texture packer interactive mode triggered. Type \"q\" at any time to exit."); + userOutput.WriteLine("Please enter path of folder containing the textures to be packed."); input = userInput.GetInput(); - if (input == "q") return; + if (input == "q") return true; path = input.Replace("\"", ""); - userOutput.WrappedOutput("Please enter output path of file name."); + userOutput.WriteLine("Please enter output path of file name."); input = userInput.GetInput(); - if (input == "q") return; + if (input == "q") return true; output = input.Replace("\"", ""); do { - userOutput.WrappedOutput("Please enter a valid starting power of two for the lengths of the resulting texture atlas. Leave blank for default of " + sp + "."); + userOutput.WriteLine("Please enter a valid starting power of two for the lengths of the resulting texture atlas. Leave blank for default of " + sp + "."); input = userInput.GetInput(); - if (input == "q") return; + if (input == "q") return true; if (input.Length == 0) break; } while (!int.TryParse(input, out sp)); do { - userOutput.WrappedOutput("Please enter a valid maximum power by two of the lengths of the resulting texture atlas. Leave blank for default of " + mp + "."); + userOutput.WriteLine("Please enter a valid maximum power by two of the lengths of the resulting texture atlas. Leave blank for default of " + mp + "."); input = userInput.GetInput(); - if (input == "q") return; + if (input == "q") return true; if (input.Length == 0) break; } while (!int.TryParse(input, out mp)); @@ -67,7 +66,10 @@ namespace RecrownedGTK.Tools.TextureAtlasTools else { int indexOfInputArg = IndexOfArgument("-i", arguments); - if (indexOfInputArg + 1 >= arguments.Length) throw new ArgumentException("-i is not followed by input path."); + if (indexOfInputArg + 1 >= arguments.Length) { + userOutput.WriteLine("-i is not followed by input path."); + return true; + } path = arguments[1 + IndexOfArgument("-i", arguments)]; if (HasArgument("-mp", arguments)) { @@ -78,28 +80,33 @@ namespace RecrownedGTK.Tools.TextureAtlasTools int.TryParse(arguments[IndexOfArgument("-sp", arguments) + 1], out sp); } int indexOfOutputArg = IndexOfArgument("-o", arguments); - if (indexOfOutputArg + 1 >= arguments.Length) throw new ArgumentException("-o is not followed by input path."); + if (indexOfOutputArg + 1 >= arguments.Length) { + userOutput.WriteLine("-o is not followed by input path."); + } output = arguments[IndexOfArgument("-o", arguments) + 1]; if (HasArgument("-dau", arguments)) dau = true; } texturePacker = new TexturePacker(userOutput, path, mp, sp); - userOutput.WrappedOutput("Calculated minimum texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + " with a total of " + texturePacker.TexturesFound + " textures."); + userOutput.WriteLine("Calculated minimum texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + " with a total of " + texturePacker.TexturesFound + " textures."); try { texturePacker.Build(!dau); } - catch (InvalidOperationException e) + catch (InvalidOperationException) { - throw new ArgumentException(e.Message); + return false; } for (int i = 0; i < arguments.Length; i++) { if (arguments[i] == "-9p") { - if (i + 1 >= arguments.Length) throw new ArgumentException("-9p is not followed by proper specifiers for a 9Patch (format: \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch.)"); + if (i + 1 >= arguments.Length) { + userOutput.WriteLine("-9p is not followed by proper specifiers for a 9Patch (format: \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch.)"); + return true; + } string[] nPatchArgs = arguments[i + 1].Split(','); try { @@ -107,12 +114,14 @@ namespace RecrownedGTK.Tools.TextureAtlasTools } catch (FormatException) { - throw new ArgumentException("-9p argument parameters must be in the format \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch."); + userOutput.WriteLine("-9p argument parameters must be in the format \"-9p textureName,a,b,c,d\" where a, b, c, and d are integers definining the border regions for the 9patch."); } } } texturePacker.Save(Path.GetDirectoryName(output), Path.GetFileName(output)); - userOutput.Output("Complete. Final texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + "."); + userOutput.WriteLine("Complete. Final texture size: " + texturePacker.TextureLength + "x" + texturePacker.TextureLength + "."); + + return true; } } } diff --git a/RecrownedGTK.Tools/end_process.ps1 b/RecrownedGTK.Tools/end_process.ps1 new file mode 100644 index 0000000..69739ad --- /dev/null +++ b/RecrownedGTK.Tools/end_process.ps1 @@ -0,0 +1,8 @@ +if (Test-Path ./pid.temp) { + $sID = Get-Item -Path ./pid.temp | Get-Content -Tail 1 + if (Get-Process -Id $sID -ErrorAction SilentlyContinue) { + Stop-Process -Id $sID + } + Remove-Item "./pid.temp" +} + diff --git a/RecrownedGTK.Tools/start_process.ps1 b/RecrownedGTK.Tools/start_process.ps1 new file mode 100644 index 0000000..aba6723 --- /dev/null +++ b/RecrownedGTK.Tools/start_process.ps1 @@ -0,0 +1,6 @@ +write-Output "Attempting to start Paper test server." +$SID = Start-Process "C:\Program Files\Mono\bin\mono" -ArgumentList "--debug", "--debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:55555", "bin/Debug/net48/RecrownedGTK.Tools.exe" -PassThru +$SID = $SID.Id +write-Output "Process started. PID is: $SID" + +$SID | Out-File -FilePath "pid.temp" \ No newline at end of file diff --git a/RecrownedGTK.sln b/RecrownedGTK.sln deleted file mode 100644 index 6fc142e..0000000 --- a/RecrownedGTK.sln +++ /dev/null @@ -1,76 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 -MinimumVisualStudioVersion = 15.0.26124.0 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecrownedGTK", "RecrownedGTK\RecrownedGTK.csproj", "{5B004034-614D-4A12-A614-7E884B4E4F9B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecrownedGTK.Tools", "RecrownedGTK.Tools\RecrownedGTK.Tools.csproj", "{95B7A776-DA73-48E6-B431-02AFD304F24A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecrownedGTK.Tests", "RecrownedGTK.Tests\RecrownedGTK.Tests.csproj", "{B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecrownedGTK.Tools.Tests", "RecrownedGTK.Tools.Tests\RecrownedGTK.Tools.Tests.csproj", "{00A6755D-A2E4-4B65-97CF-762851A9D651}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|x64.ActiveCfg = Debug|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|x64.Build.0 = Debug|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|x86.ActiveCfg = Debug|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Debug|x86.Build.0 = Debug|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|Any CPU.Build.0 = Release|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|x64.ActiveCfg = Release|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|x64.Build.0 = Release|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|x86.ActiveCfg = Release|Any CPU - {5B004034-614D-4A12-A614-7E884B4E4F9B}.Release|x86.Build.0 = Release|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|x64.ActiveCfg = Debug|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|x64.Build.0 = Debug|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|x86.ActiveCfg = Debug|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Debug|x86.Build.0 = Debug|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|Any CPU.Build.0 = Release|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|x64.ActiveCfg = Release|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|x64.Build.0 = Release|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|x86.ActiveCfg = Release|Any CPU - {95B7A776-DA73-48E6-B431-02AFD304F24A}.Release|x86.Build.0 = Release|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|x64.ActiveCfg = Debug|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|x64.Build.0 = Debug|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|x86.ActiveCfg = Debug|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Debug|x86.Build.0 = Debug|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|Any CPU.Build.0 = Release|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|x64.ActiveCfg = Release|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|x64.Build.0 = Release|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|x86.ActiveCfg = Release|Any CPU - {B2E2AB4D-B70D-427B-90D9-5D4F2C8E937F}.Release|x86.Build.0 = Release|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|Any CPU.Build.0 = Debug|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|x64.ActiveCfg = Debug|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|x64.Build.0 = Debug|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|x86.ActiveCfg = Debug|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Debug|x86.Build.0 = Debug|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|Any CPU.ActiveCfg = Release|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|Any CPU.Build.0 = Release|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|x64.ActiveCfg = Release|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|x64.Build.0 = Release|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|x86.ActiveCfg = Release|Any CPU - {00A6755D-A2E4-4B65-97CF-762851A9D651}.Release|x86.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/RecrownedGTK/RecrownedGTK.csproj b/RecrownedGTK/RecrownedGTK.csproj index 3645316..7c81d69 100644 --- a/RecrownedGTK/RecrownedGTK.csproj +++ b/RecrownedGTK/RecrownedGTK.csproj @@ -1,6 +1,7 @@ net48 + portable