1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 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(@""); } } } |