From fd085848e60831a8582c24de8f30ad4528f9d490 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sat, 26 Mar 2011 03:45:34 +0100 Subject: unfinished console interface to NW4RTools added --- ConsoleApp/Main.cs | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 ConsoleApp/Main.cs (limited to 'ConsoleApp/Main.cs') diff --git a/ConsoleApp/Main.cs b/ConsoleApp/Main.cs new file mode 100644 index 0000000..322d277 --- /dev/null +++ b/ConsoleApp/Main.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; + +namespace ConsoleApp { + class MainClass { + private static Dictionary CommandLookup; + + private static void SetupCommands() { + CommandLookup = new Dictionary(); + + CommandLookup.Add("init", new InitCommand()); + CommandLookup.Add("list", new ListCommand()); + CommandLookup.Add("import-obj", new ImportObjCommand()); + CommandLookup.Add("export-obj", new ExportObjCommand()); + CommandLookup.Add("export-collada", new ExportColladaCommand()); + CommandLookup.Add("export-textures", new ExportTexturesCommand()); + } + + public static void Main(string[] args) { + Console.WriteLine("NW4RTools by Treeki"); + Console.WriteLine(); + + SetupCommands(); + + // process the command line + string cmd; + string[] cmdArgs; + + if (args.Length == 0) { + cmd = "help"; + cmdArgs = new string[0]; + } else { + cmd = args[0]; + cmdArgs = new string[args.Length - 1]; + + for (int i = 1; i < args.Length; i++) { + cmdArgs[i - 1] = args[i]; + } + } + + // handle Help if needed + if (cmd == "help") { + Help(cmdArgs); + return; + } + + // otherwise, pass it on + if (CommandLookup.ContainsKey(cmd)) { + CommandLookup[cmd].Execute(cmdArgs); + } else { + Console.WriteLine("Unknown command {0}. Try \"help\" for a list of usable commands", cmd); + } + } + + private static void Help(string[] args) { + if (args.Length == 0) { + Console.WriteLine("Available commands:"); + + foreach (var cmd in CommandLookup) { + Console.WriteLine("- {0}: {1}", cmd.Key, cmd.Value.Description); + } + + Console.WriteLine(); + Console.WriteLine("For additional info, try: help "); + + } else { + if (CommandLookup.ContainsKey(args[0])) { + Console.WriteLine("Help for {0}:", args[0]); + string[] helpArgs = new string[args.Length - 1]; + + for (int i = 1; i < args.Length; i++) { + helpArgs[i - 1] = args[i]; + } + + Console.WriteLine(CommandLookup[args[0]].GetHelp(helpArgs)); + + } else { + Console.WriteLine("Unknown command {0}. Try \"help\" for a list of usable commands", args[0]); + } + } + } + } +} + -- cgit v1.2.3