protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { Vms.AppStatic.Upgrade(CommandLineArgs.Upgrade, () => { Environment.Exit(0); }); } else { try { appMutex = new Mutex(true, s_appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { Vms.AppStatic.IsMinerClient = true; SplashWindow splashWindow = new SplashWindow(); splashWindow.Show(); NTMinerRoot.KernelBrandId = Brand.BrandUtil.KernelBrandId; NotiCenterWindow.Instance.Show(); NTMinerRoot.AppName = "开源矿工挖矿客户端"; NTMinerRoot.Current.Init(() => { NTMinerRoot.KernelDownloader = new KernelDownloader(); UIThread.Execute(() => { MainWindow window = new MainWindow(); IMainWindow mainWindow = window; this.MainWindow = window; this.MainWindow.Show(); this.MainWindow.Activate(); System.Drawing.Icon icon = new System.Drawing.Icon(GetResourceStream(new Uri("pack://application:,,,/NTMiner;component/logo.ico")).Stream); AppHelper.NotifyIcon = ExtendedNotifyIcon.Create(icon, "挖矿端", isMinerStudio: false); #region 处理显示主界面命令 VirtualRoot.Window <ShowMainWindowCommand>("处理显示主界面命令", LogEnum.None, action: message => { Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow); }); #endregion splashWindow?.Close(); Task.Factory.StartNew(() => { try { HttpServer.Start($"http://localhost:{WebApiConst.MinerClientPort}"); NTMinerRoot.Current.Start(); } catch (Exception ex) { Logger.ErrorDebugLine(ex.Message, ex); } }); }); }); VirtualRoot.Window <CloseNTMinerCommand>("处理关闭NTMiner客户端命令", LogEnum.UserConsole, action: message => { UIThread.Execute(() => { if (MainWindow != null) { MainWindow.Close(); } Shutdown(); Environment.Exit(0); }); }); #region 周期确保守护进程在运行 Daemon.DaemonUtil.RunNTMinerDaemon(); VirtualRoot.On <Per20SecondEvent>("周期确保守护进程在运行", LogEnum.None, action: message => { Daemon.DaemonUtil.RunNTMinerDaemon(); }); #endregion VirtualRoot.On <MineStartedEvent>("开始挖矿后启动1080ti小药丸、挖矿开始后如果需要启动DevConsole则启动DevConsole", LogEnum.DevConsole, action: message => { // 启动DevConsole if (NTMinerRoot.IsUseDevConsole) { var mineContext = message.MineContext; string poolIp = mineContext.MainCoinPool.GetIp(); string consoleTitle = mineContext.MainCoinPool.Server; Daemon.DaemonUtil.RunDevConsoleAsync(poolIp, consoleTitle); } OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Start(); }); VirtualRoot.On <MineStopedEvent>("停止挖矿后停止1080ti小药丸", LogEnum.DevConsole, action: message => { OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop(); }); NTMinerOverClockUtil.ExtractResource(); } else { try { AppHelper.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerClient); } catch (Exception) { DialogWindow.ShowDialog(message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "alert", icon: "Icon_Error"); Process currentProcess = Process.GetCurrentProcess(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } } base.OnStartup(e); }
private void OnNTMinerRootInited() { NTMinerRoot.KernelDownloader = new KernelDownloader(); Execute.OnUIThread(() => { BootLog.Log("new MainWindow"); Window splashWindow = MainWindow; MainWindow window = new MainWindow(); IMainWindow mainWindow = window; this.MainWindow = window; this.MainWindow.Show(); this.MainWindow.Activate(); BootLog.Log("MainWindow showed"); notifyIcon = new ExtendedNotifyIcon("pack://application:,,,/NTMiner;component/logo.ico"); notifyIcon.Init(); #region 处理显示主界面命令 Global.Access <ShowMainWindowCommand>( Guid.Parse("01f3c467-f494-42b8-bcb5-848050df59f3"), "处理显示主界面命令", LogEnum.None, action: message => { Execute.OnUIThread(() => { Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow); AppHelper.MainWindowShowed(); }); }); #endregion #region 处理重启NTMiner命令 Global.Access <RestartNTMinerCommand>( Guid.Parse("d1712c1f-507c-496f-9da2-870cbd9fc57f"), "处理重启NTMiner命令", LogEnum.None, action: message => { List <string> args = CommandLineArgs.Args; if (message.IsWorkEdit) { if (CommandLineArgs.IsWorkEdit && CommandLineArgs.WorkId == message.MineWorkId) { Execute.OnUIThread(() => { Dispatcher.Invoke((ThreadStart)mainWindow.ShowThisWindow); }); return; } if (!CommandLineArgs.IsControlCenter) { args.Add("--controlCenter"); } } if (message.MineWorkId != Guid.Empty) { if (!CommandLineArgs.IsWorker) { args.Add("--workid=" + message.MineWorkId.ToString()); } else { for (int i = 0; i < args.Count; i++) { if (args[i].StartsWith("--workid=", StringComparison.OrdinalIgnoreCase)) { args[i] = "--workid=" + message.MineWorkId.ToString(); break; } } } } else { if (CommandLineArgs.IsWorker) { int workIdIndex = -1; for (int i = 0; i < args.Count; i++) { if (args[i].ToLower().Contains("--workid=")) { workIdIndex = i; break; } } if (workIdIndex != -1) { args.RemoveAt(workIdIndex); } } } NTMiner.Windows.Cmd.RunClose(ClientId.AppFileFullName, string.Join(" ", args)); Current.MainWindow.Close(); }); #endregion Task.Factory.StartNew(() => { AppHelper.RunPipeServer(this, _appPipName); }); try { NTMinerRoot.Current.Start(); } catch (Exception ex) { Global.Logger.Error(ex.Message, ex); } splashWindow?.Close(); if (NTMinerRoot.Current.MinerProfile.IsAutoStart || CommandLineArgs.IsAutoStart) { Global.DebugLine("自动开始挖矿倒计时", ConsoleColor.Yellow); Views.Ucs.AutoStartCountdown.ShowDialog(); } BootLog.SyncToDisk(); }); }