--- a +++ b/trunk/cforge/cforge/Program.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace cforge +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("cforge\r\n"); + + if (args.Length == 1 && args[0].StartsWith("cforge:")) + { + // invokation via URL Handler: + // format is + // "cforge:<command>:additionalargs_or_path_or_whatever + // now we can remove the start + // split for the first ":" and the rest is like the normal commandline + String arg = args[0].Remove(0, "cforge:".Length); + List<string> newargs = new List<string>(); + + String command = arg.Split(':')[0]; + newargs.Add(command); + string s = System.Uri.UnescapeDataString(arg.Remove(0, command.Length + 1)); + s = System.Uri.UnescapeDataString(s); + newargs.Add(s); + + args = newargs.ToArray(); + } + + if(!Helper.CheckRegistryProtocol()) + { + Console.WriteLine(@"[WARNING] URL Handler is not registered. CFORGE: links will not work properly. Use RegisterURLHandler.bat to do this (at <CODESYS Installation folder>\CFORGE\ )"); + } + + List<String> liScripts = Helper.GetAllScripts(); + + for (int i = 0; i < args.Length; i++) + { + switch (args[i]) + { + case "--register-url-handler": + Helper.RegisterProtocol(); + break; + + case "--list-scripts": + + Console.WriteLine("List all scripts: "); + foreach (String item in liScripts) + { + Console.WriteLine(" -" + item); + } + break; + + /* fallthrough intended ! */ + case "--help": + case "-h": + ShowUsage(); + break; + + default: + // check if we have matching script: + if(liScripts.Contains(args[i])) + { + // the rest of the command is passed as argument to the script + string[] newargs = new List<string>(args).GetRange(i, args.Length - i - 1).ToArray(); + Helper.ExecuteIPyScript(args[i], newargs); + } + break; + } + } + } + + static void ShowUsage() + { + Console.WriteLine(@"usage: cforge <command> [options]"); + Console.WriteLine(@""); + Console.WriteLine(@"commands:"); + Console.WriteLine(@"-h/--help: show this help"); + Console.WriteLine(@"--register-url-handler register cforge url handler in windows registry"); + Console.WriteLine(@"--list-scripts list all available scripts (ironpython subcommands)"); + + // generic part + + Console.WriteLine(@""); + + } + + } +}