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); }); }); VirtualRoot.On <MineStartedEvent>("开始挖矿后启动1080ti小药丸", LogEnum.DevConsole, action: message => { 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(); Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName); foreach (var process in processes) { if (process.Id != currentProcess.Id) { NTMiner.Windows.TaskKill.Kill(process.Id); } } } } } base.OnStartup(e); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; // 通过群控升级挖矿端的时候升级器可能不存在所以需要下载,下载的时候需要用到下载器所以下载器需要提前注册 VirtualRoot.Window <ShowFileDownloaderCommand>(LogEnum.DevConsole, action: message => { UIThread.Execute(() => { FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete); }); }); VirtualRoot.Window <UpgradeCommand>(LogEnum.DevConsole, action: message => { AppStatic.Upgrade(message.FileName, message.Callback); }); if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => { UIThread.Execute(() => { Environment.Exit(0); }); })); } else { try { appMutex = new Mutex(true, s_appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { Logger.InfoDebugLine($"==================NTMiner.exe {NTMinerRoot.CurrentVersion.ToString()}=================="); if (!NTMiner.Windows.WMI.IsWmiEnabled) { DialogWindow.ShowDialog(message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。", title: "提醒", icon: "Icon_Error"); Shutdown(); Environment.Exit(0); } NTMinerOverClockUtil.ExtractResource(); VirtualRoot.SetIsMinerClient(true); NotiCenterWindowViewModel.IsHotKeyEnabled = true; Window splashWindow = _appViewFactory.CreateSplashWindow(); splashWindow.Show(); NotiCenterWindow.Instance.Show(); if (DevMode.IsDevMode) { HandlerIdsWindow window = new HandlerIdsWindow(); window.Show(); } if (!NTMiner.Windows.Role.IsAdministrator) { NotiCenterWindowViewModel.Instance.Manager .CreateMessage() .Warning("请以管理员身份运行。") .WithButton("点击以管理员身份运行", button => { Wpf.Util.RunAsAdministrator(); }) .Dismiss().WithButton("忽略", button => { }).Queue(); } VirtualRoot.On <StartingMineFailedEvent>("开始挖矿失败", LogEnum.DevConsole, action: message => { AppContext.Instance.MinerProfileVm.IsMining = false; Write.UserFail(message.Message); }); NTMinerRoot.Instance.Init(() => { _appViewFactory.Link(); if (NTMinerRoot.Instance.GpuSet.Count == 0) { NotiCenterWindowViewModel.Instance.Manager.ShowErrorMessage("没有矿卡或矿卡未驱动。"); } UIThread.Execute(() => { if (NTMinerRoot.GetIsNoUi() && NTMinerRegistry.GetIsAutoStart()) { MainWindow = NotiCenterWindow.Instance; NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage("已切换为无界面模式运行,可在选项页调整设置", "开源矿工"); } else { _appViewFactory.ShowMainWindow(isToggle: false); } AppContext.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false); splashWindow?.Close(); }); #region 处理显示主界面命令 VirtualRoot.Window <ShowMainWindowCommand>("处理显示主界面命令", LogEnum.DevConsole, action: message => { ShowMainWindow(message.IsToggle); }); #endregion Task.Factory.StartNew(() => { try { HttpServer.Start($"http://localhost:{Consts.MinerClientPort}"); NTMinerRoot.Instance.Start(); Daemon.DaemonUtil.RunNTMinerDaemon(); } catch (Exception ex) { Logger.ErrorDebugLine(ex); } }); }); Link(); } else { try { _appViewFactory.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerClient); } catch (Exception) { DialogWindow.ShowDialog(message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "提醒", icon: "Icon_Error"); Process currentProcess = Process.GetCurrentProcess(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } } base.OnStartup(e); }
protected override void OnStartup(StartupEventArgs e) { RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade)) { AppStatic.Upgrade(CommandLineArgs.Upgrade, () => { Environment.Exit(0); }); } else { try { appMutex = new Mutex(true, s_appPipName, out createdNew); } catch (Exception) { createdNew = false; } if (createdNew) { if (!NTMiner.Windows.WMI.IsWmiEnabled) { DialogWindow.ShowDialog(message: "开源矿工无法运行所需的组件,因为本机未开机WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。", title: "提醒", icon: "Icon_Error"); Shutdown(); Environment.Exit(0); } NTMinerOverClockUtil.ExtractResource(); AppStatic.SetIsMinerClient(true); NotiCenterWindowViewModel.IsHotKeyEnabled = true; SplashWindow splashWindow = new SplashWindow(); splashWindow.Show(); NotiCenterWindow.Instance.Show(); NTMinerRoot.Instance.Init(() => { NTMinerRoot.KernelDownloader = new KernelDownloader(); UIThread.Execute(() => { if (!NTMinerRegistry.GetIsNoUi() || !NTMinerRegistry.GetIsAutoStart()) { Views.MainWindow.ShowMainWindow(); } else { NotiCenterWindowViewModel.Instance.Manager.ShowSuccessMessage("已切换为无界面模式运行", "开源矿工"); } 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 => { UIThread.Execute(() => { MainWindow mainWindow = this.MainWindow as MainWindow; if (mainWindow == null) { AppContext.Enable(); Views.MainWindow.ShowMainWindow(); // 使状态栏显示显示最新状态 if (NTMinerRoot.Instance.IsMining) { var coinShare = NTMinerRoot.Instance.CoinShareSet.GetOrCreate(NTMinerRoot.Instance.CurrentMineContext.MainCoin.GetId()); VirtualRoot.Happened(new ShareChangedEvent(coinShare)); if (NTMinerRoot.Instance.CurrentMineContext is IDualMineContext dualMineContext) { coinShare = NTMinerRoot.Instance.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId()); VirtualRoot.Happened(new ShareChangedEvent(coinShare)); } AppContext.Instance.GpuSpeedVms.Refresh(); } } else { mainWindow.ShowThisWindow(message.IsToggle); } }); }); #endregion splashWindow?.Close(); Task.Factory.StartNew(() => { try { HttpServer.Start($"http://localhost:{WebApiConst.MinerClientPort}"); NTMinerRoot.Instance.Start(); } catch (Exception ex) { Logger.ErrorDebugLine(ex.Message, ex); } }); }); }); Link(); } else { try { AppHelper.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerClient); } catch (Exception) { DialogWindow.ShowDialog(message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。", title: "提醒", icon: "Icon_Error"); Process currentProcess = Process.GetCurrentProcess(); NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess); } } } base.OnStartup(e); }