/// <summary>分析参数</summary> /// <param name="args"></param> /// <returns></returns> public static ScriptConfig Parse(String[] args) { var config = new ScriptConfig(); var pis = config.GetType().GetProperties(); foreach (var item in args) { // 无标记参数是源文件 if (item[0] != '/' && item[0] != '-') { //if (!String.IsNullOrEmpty(config.File)) throw new XException("重复的源文件参数{0}。", item); // 默认第一个源文件作为脚本文件 if (String.IsNullOrEmpty(config.File)) { config.File = item; } continue; } // 去掉前面的/或者- var flag = config.Set(item.Substring(1), pis); //if (!flag) throw new XException("不可识别的参数{0}。", item); } return(config); }
static void Main(String[] args) { var cfg = Config; // 分解参数 try { cfg = Config = ScriptConfig.Parse(args); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.Read(); return; } Script.Config = cfg; Host.Config = cfg; // 隐藏当前窗口 if (cfg.Hide) { var ip = Process.GetCurrentProcess().MainWindowHandle; if (ip != IntPtr.Zero) { ShowWindow(ip, 0); } } // 修改标题 Title = AssemblyX.Create(Assembly.GetExecutingAssembly()).Title; Console.Title = Title; if (cfg.Debug) { XTrace.Debug = true; } XTrace.UseConsole(); _CodeFile = true; if (args == null || args.Length == 0 || args[0] == "?" || args[0] == "/?") { _CodeFile = false; } // 是否卸载流程 if (args != null && "-uninstall".EqualIgnoreCase(args)) { RegHelper.Uninstall(true); return; } // 是否安装流程 var install = args != null && "-install".EqualIgnoreCase(args); #if !DEBUG // 检查并写入注册表 if (RegHelper.CheckVersion(install)) { // 发送到菜单 Task.Run(() => RegHelper.SetSendTo()); if (IsAdministrator()) { Task.Run(() => RegHelper.SetFileType()); } Task.Run(() => RegHelper.SetPath()); if (install) { Thread.Sleep(3000); } } if (install) { return; } #endif Task.Run(() => AutoUpdate()); //if (cfg.Debug) Task.Run(() => Build.Builder.All); if (!_CodeFile) { // 输出版权信息 ShowCopyright(); // 显示帮助菜单 ShowHelp(); ProcessUser(); } else { if (!cfg.NoLogo) { ShowCopyright(); } ProcessFile(); } }
static void Main(string[] args) { // 分解参数 try { Config = ScriptConfig.Parse(args); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.Read(); return; } Script.Config = Config; if (Config.Hide) { var ip = Process.GetCurrentProcess().MainWindowHandle; if (ip != IntPtr.Zero) { ShowWindow(ip, 0); } } Title = AssemblyX.Create(Assembly.GetExecutingAssembly()).Title; Console.Title = Title; if (Config.Debug) { XTrace.Debug = true; } XTrace.UseConsole(); _CodeFile = true; if (args == null || args.Length == 0 || args[0] == "?" || args[0] == "/?") { _CodeFile = false; } // 发送到菜单 ThreadPoolX.QueueUserWorkItem(s => SetSendTo()); ThreadPoolX.QueueUserWorkItem(s => SetFileType()); ThreadPoolX.QueueUserWorkItem(s => SetPath()); ThreadPoolX.QueueUserWorkItem(s => AutoUpdate()); if (!_CodeFile) { // 输出版权信息 ShowCopyright(); // 显示帮助菜单 ShowHelp(); ProcessUser(); } else { if (!Config.NoLogo) { ShowCopyright(); } ProcessFile(); } }