using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace cforge { class Program { static void Main(string[] args) { Console.WriteLine(""); Console.WriteLine(@"----------------------------------------------------------------------------"); Console.WriteLine("cforge started"); Console.WriteLine("Build date: " + Resources.BuildTime); Console.WriteLine("Revision based: " + Resources.CurrentSVNRevision); Console.WriteLine(@"----------------------------------------------------------------------------"); Console.WriteLine(""); if (Helper.EasyAttachEnabled()) { Console.WriteLine("Easy attach enabled. Now attach with debugger, and then press Enter here!"); Console.ReadLine(); } if (args.Length == 1 && args[0].StartsWith("cforge:")) { // invokation via URL Handler: // format is // "cforge::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 newargs = new List(); String command = "--" + arg.Split(':')[0]; newargs.Add(command); if (arg.Split(':').Length > 1) { string s = System.Uri.UnescapeDataString(arg.Remove(0, arg.Split(':')[0].Length + 1)); s = System.Uri.UnescapeDataString(s); newargs.Add(s); } if(Helper.EasyAttachEnabled()) { Console.WriteLine("converting arguments from: "); foreach (String s in args) { Console.WriteLine(s); } Console.WriteLine("to: "); foreach (String s in newargs) { Console.WriteLine(s); } } args = newargs.ToArray(); } if (Helper.EasyAttachEnabled()) { Console.WriteLine("CWD: " + Directory.GetCurrentDirectory()); Console.WriteLine("User elevated: " + Helper.IsUserElevated()); } if (!Helper.CheckRegistryProtocol()) { Console.WriteLine(@"[WARNING] URL Handler is not registered. CFORGE: links will not work properly. Use Setup.bat to do this (at \CFORGE\ )"); } List liScripts = Helper.GetAllScripts(); bool bDebug = false; for (int i = 0; i < args.Length; i++) { switch (args[i]) { case "-d": bDebug = true; if (Helper.IsUserElevated()) Console.WriteLine("Running elevated"); break; // fallthrough intended case "-v": case "--version": Version version = Assembly.GetEntryAssembly().GetName().Version; Console.WriteLine("Version: " + version.ToString()); break; case "--setup": if (!Helper.IsUserElevated()) { Console.WriteLine("[INFO] Setup URL Handler and add tool to path. "); Helper.RunElevated("--setup"); } else { /// bootstrapper Helper.bootstrap(bDebug); Helper.RegisterProtocol(bDebug); Helper.AddToSystemPath(bDebug); } break; case "--license-info": Helper.ShowLicenseInfo(); break; /* fallthrough intended ! */ case "--help": case "-h": ShowUsage(); break; default: if (Helper.EasyAttachEnabled()) { Console.WriteLine("default case: " + args[i]); } // check if we have matching script: if (args[i].StartsWith("--")) { String command = args[i].Replace("--", ""); if (liScripts.Contains(command)) { // the rest of the command is passed as argument to the script string[] newargs = args.Skip(i + 1).ToArray(); Helper.ExecuteIPyScript(command, newargs, bDebug); // as we "used" all params... i = args.Length; } else { if (Helper.EasyAttachEnabled()) { Console.WriteLine("no matching script found: " + command); } ShowUsage(); } } break; } } if (args.Length == 0) ShowUsage(); Console.WriteLine(""); Console.WriteLine(@"----------------------------------------------------------------------------"); Console.WriteLine("cforge finished."); Console.WriteLine(@"----------------------------------------------------------------------------"); Console.WriteLine(""); Console.ReadLine(); } static void ShowUsage() { // pad right 32 for description ;-) Console.WriteLine(@"usage: cforge "); Console.WriteLine(@""); Console.WriteLine(@"internal commands:"); Console.WriteLine(@"-h/--help show this help"); Console.WriteLine(@"--setup register cforge url handler and add cforge to path"); Console.WriteLine(@"--license-info show license information"); Console.WriteLine(@"-v/--version show version information"); Console.WriteLine(@""); Console.WriteLine(@""); Console.WriteLine(@"external commands (scripts):"); Console.WriteLine(@"------------------------------"); // generic part List liCommands = Helper.GetAllScripts(); foreach (String command in liCommands) { Helper.ShowUsageIPyScript(command, false); } Console.WriteLine(@""); Console.WriteLine(@""); } } }