Ejemplo n.º 1
0
 static void Main(string[] args)
 {
     try {
         Console.Title = "NTMinerServices";
         bool mutexCreated;
         try {
             _sMutexApp = new Mutex(true, "NTMinerServicesMutex", out mutexCreated);
         }
         catch {
             mutexCreated = false;
         }
         if (mutexCreated)
         {
             if (!EnableInnerIp)
             {
                 NTMinerRegistry.SetAutoBoot("NTMinerServices", true);
             }
             Type thisType = typeof(HostRoot);
             NotifyIcon = ExtendedNotifyIcon.Create(new System.Drawing.Icon(thisType.Assembly.GetManifestResourceStream(thisType, "logo.ico")), "群控服务", isShowNotifyIcon: true);
             Run();
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e.Message, e);
     }
 }
Ejemplo n.º 2
0
 private void Init()
 {
     NTMinerRoot.Instance.Init(() => {
         _appViewFactory.Link();
         UIThread.Execute(() => () => {
             VirtualRoot.Execute(new ShowMinerClientsWindowCommand());
             AppContext.NotifyIcon = ExtendedNotifyIcon.Create("群控客户端", isMinerStudio: true);
         });
         #region 处理显示主界面命令
         VirtualRoot.AddCmdPath <ShowMainWindowCommand>(action: message => {
             VirtualRoot.Execute(new ShowMinerClientsWindowCommand());
         }, location: this.GetType());
         #endregion
         HttpServer.Start($"http://localhost:{NTKeyword.MinerStudioPort.ToString()}");
         Rdp.RemoteDesktop = MsRdpRemoteDesktop.OpenRemoteDesktop;
     });
 }
Ejemplo n.º 3
0
 private void Init()
 {
     NTMinerRoot.Instance.Init(() => {
         _appViewFactory.Link();
         UIThread.Execute(() => {
             VirtualRoot.Execute(new ShowChartsWindowCommand());
             AppContext.NotifyIcon = ExtendedNotifyIcon.Create("群控客户端", isMinerStudio: true);
         });
         #region 处理显示主界面命令
         VirtualRoot.Window <ShowMainWindowCommand>("处理显示主界面命令", LogEnum.DevConsole,
                                                    action: message => {
             VirtualRoot.Execute(new ShowChartsWindowCommand());
         });
         #endregion
         HttpServer.Start($"http://localhost:{Consts.MinerStudioPort}");
         AppContext.RemoteDesktop = MsRdpRemoteDesktop.OpenRemoteDesktop;
     });
 }
Ejemplo n.º 4
0
 static void Main(string[] args)
 {
     try {
         Console.Title = "NTMinerDaemon";
         bool mutexCreated;
         try {
             s_mutexApp = new Mutex(true, "NTMinerDaemonAppMutex", out mutexCreated);
         }
         catch {
             mutexCreated = false;
         }
         if (mutexCreated)
         {
             NTMinerRegistry.SetAutoBoot("NTMinerDaemon", true);
             Type thisType = typeof(HostRoot);
             NotifyIcon = ExtendedNotifyIcon.Create(new System.Drawing.Icon(thisType.Assembly.GetManifestResourceStream(thisType, "logo.ico")), "挖矿端守护进程", isShowNotifyIcon: DevMode.IsDebugMode);
             bool isAutoBoot = NTMinerRegistry.GetIsAutoBoot();
             if (isAutoBoot)
             {
                 string location = NTMinerRegistry.GetLocation();
                 if (!string.IsNullOrEmpty(location))
                 {
                     string arguments = NTMinerRegistry.GetArguments();
                     try {
                         Process.Start(location, arguments);
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e.Message, e);
                     }
                 }
             }
             Run();
         }
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e.Message, e);
     }
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 protected override void OnStartup(StartupEventArgs e)
 {
     RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
     // 通过群控升级挖矿端的时候升级器可能不存在所以需要下载,下载的时候需要用到下载器所以下载器需要提前注册
     VirtualRoot.BuildCmdPath <ShowFileDownloaderCommand>(action: message => {
         UIThread.Execute(() => {
             FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete);
         });
     });
     VirtualRoot.BuildCmdPath <UpgradeCommand>(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 {MainAssemblyInfo.CurrentVersion.ToString()}==================");
             NotiCenterWindowViewModel.IsHotKeyEnabled = true;
             SplashWindow splashWindow = null;
             // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞
             // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象
             SplashWindow.ShowWindowAsync(window => {
                 splashWindow = window;
             });
             //ConsoleWindow.Instance.Show();
             NotiCenterWindow.ShowWindow();
             if (!NTMiner.Windows.WMI.IsWmiEnabled)
             {
                 DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                                 message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。",
                                                 title: "提醒",
                                                 icon: "Icon_Error"));
                 Shutdown();
                 Environment.Exit(0);
             }
             if (!NTMiner.Windows.Role.IsAdministrator)
             {
                 NotiCenterWindowViewModel.Instance.Manager
                 .CreateMessage()
                 .Warning("请以管理员身份运行。")
                 .WithButton("点击以管理员身份运行", button => {
                     WpfUtil.RunAsAdministrator();
                 })
                 .Dismiss().WithButton("忽略", button => {
                 }).Queue();
             }
             NTMinerRoot.Instance.Init(() => {
                 _appViewFactory.Link();
                 if (VirtualRoot.IsLTWin10)
                 {
                     VirtualRoot.ThisLocalWarn(nameof(App), AppStatic.LowWinMessage, toConsole: true);
                 }
                 if (NTMinerRoot.Instance.GpuSet.Count == 0)
                 {
                     VirtualRoot.ThisLocalError(nameof(App), "没有矿卡或矿卡未驱动。", toConsole: true);
                 }
                 if (NTMinerRoot.Instance.ServerContext.CoinSet.Count == 0)
                 {
                     VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true);
                 }
                 UIThread.Execute(() => {
                     if (NTMinerRoot.Instance.MinerProfile.IsNoUi && NTMinerRoot.Instance.MinerProfile.IsAutoStart)
                     {
                         ConsoleWindow.Instance.Hide();
                         VirtualRoot.Out.ShowSuccess("已切换为无界面模式运行,可在选项页调整设置", "开源矿工");
                     }
                     else
                     {
                         // 预热视图模型
                         AppContext.Instance.VmsCtor();
                         _appViewFactory.ShowMainWindow(isToggle: false);
                     }
                     StartStopMineButtonViewModel.Instance.AutoStart();
                     AppContext.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false);
                     splashWindow?.Dispatcher.Invoke((Action) delegate() {
                         splashWindow?.Close();
                     });
                 });
                 Task.Factory.StartNew(() => {
                     if (NTMinerRoot.Instance.MinerProfile.IsAutoDisableWindowsFirewall)
                     {
                         Firewall.DisableFirewall();
                     }
                     if (!Firewall.IsMinerClientRuleExists())
                     {
                         Firewall.AddMinerClientRule();
                     }
                     try {
                         HttpServer.Start($"http://localhost:{NTKeyword.MinerClientPort.ToString()}");
                         Daemon.DaemonUtil.RunNTMinerDaemon();
                     }
                     catch (Exception ex) {
                         Logger.ErrorDebugLine(ex);
                     }
                     NTMinerRoot.Instance.CpuPackage.Start();
                 });
             });
             Link();
         }
         else
         {
             try {
                 _appViewFactory.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerClient);
             }
             catch (Exception) {
                 DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                                 message: "另一个NTMiner正在运行,请手动结束正在运行的NTMiner进程后再次尝试。",
                                                 title: "提醒",
                                                 icon: "Icon_Error"));
                 Process currentProcess = Process.GetCurrentProcess();
                 NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess);
             }
         }
     }
     base.OnStartup(e);
 }
Ejemplo n.º 7
0
 protected override void OnStartup(StartupEventArgs e)
 {
     BootLog.Log("App.OnStartup start");
     RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
     try {
         appMutex = new Mutex(true, _appPipName, out createdNew);
     }
     catch (Exception) {
         createdNew = false;
     }
     if (createdNew)
     {
         if (!NTMiner.Windows.Role.IsAdministrator)
         {
             AppHelper.RunAsAdministrator();
             return;
         }
         BootLog.Log("new SplashWindow");
         SplashWindow splashWindow = new SplashWindow();
         splashWindow.Show();
         NTMinerRoot.Inited = () => {
             NTMinerRoot.KernelDownloader = new KernelDownloader();
             Execute.OnUIThread(() => {
                 bool?result = true;
                 if (string.IsNullOrEmpty(Server.LoginName) || string.IsNullOrEmpty(Server.Password))
                 {
                     LoginWindow loginWindow = new LoginWindow();
                     splashWindow.Hide();
                     result = loginWindow.ShowDialog();
                 }
                 if (result.HasValue && result.Value)
                 {
                     BootLog.Log("new MainWindow");
                     ControlCenterWindow window = new ControlCenterWindow();
                     IMainWindow mainWindow     = window;
                     this.MainWindow            = window;
                     this.MainWindow.Show();
                     this.MainWindow.Activate();
                     BootLog.Log("MainWindow showed");
                     notifyIcon = new ExtendedNotifyIcon("pack://application:,,,/ControlCenterApp;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
                     Task.Factory.StartNew(() => {
                         AppHelper.RunPipeServer(this, _appPipName);
                     });
                 }
                 splashWindow?.Close();
                 BootLog.SyncToDisk();
             });
         };
     }
     else
     {
         try {
             AppHelper.ShowMainWindow(this, _appPipName);
         }
         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);
     BootLog.Log("App.OnStartup end");
     BootLog.SyncToDisk();
 }
Ejemplo n.º 8
0
 private void DoRun()
 {
     if (AppUtil.GetMutex(NTKeyword.MinerClientAppMutex))
     {
         NotiCenterWindow.ShowWindow();
         Logger.InfoDebugLine($"==================NTMiner.exe {EntryAssemblyInfo.CurrentVersionStr}==================");
         // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞
         // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象
         SplashWindow splashWindow = null;
         SplashWindow.ShowWindowAsync(window => {
             splashWindow = window;
         });
         if (!NTMiner.Windows.WMI.IsWmiEnabled)
         {
             DialogWindow.ShowHardDialog(new DialogWindowViewModel(
                                             message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。",
                                             title: "提醒",
                                             icon: "Icon_Error"));
             Shutdown();
             Environment.Exit(0);
         }
         if (!NTMiner.Windows.Role.IsAdministrator)
         {
             NotiCenterWindowViewModel.Instance.Manager
             .CreateMessage()
             .Warning("提示", "请以管理员身份运行。")
             .WithButton("点击以管理员身份运行", button => {
                 WpfUtil.RunAsAdministrator();
             })
             .Dismiss().WithButton("忽略", button => {
             }).Queue();
         }
         BuildPaths();
         NTMinerContext.Instance.Init(() => {
             _appViewFactory.BuildPaths();
             if (VirtualRoot.IsLTWin10)
             {
                 VirtualRoot.ThisLocalWarn(nameof(App), AppRoot.LowWinMessage, toConsole: true);
             }
             if (NTMinerContext.Instance.GpuSet.Count == 0)
             {
                 VirtualRoot.ThisLocalError(nameof(App), "没有矿卡或矿卡未驱动。", toConsole: true);
             }
             if (NTMinerContext.WorkType != WorkType.None && NTMinerContext.Instance.ServerContext.CoinSet.Count == 0)
             {
                 VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true);
             }
             UIThread.Execute(() => {
                 Window mainWindow  = null;
                 AppRoot.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false);
                 if (NTMinerRegistry.GetIsNoUi() && NTMinerRegistry.GetIsAutoStart())
                 {
                     ConsoleWindow.Instance.Hide();
                     VirtualRoot.Out.ShowSuccess("以无界面模式启动,可在选项页调整设置", header: "开源矿工");
                 }
                 else
                 {
                     _appViewFactory.ShowMainWindow(isToggle: false, out mainWindow);
                 }
                 // 主窗口显式后退出SplashWindow
                 splashWindow?.Dispatcher.Invoke((Action) delegate() {
                     splashWindow?.OkClose();
                 });
                 // 启动时Windows状态栏显式的是SplashWindow的任务栏图标,SplashWindow关闭后激活主窗口的Windows任务栏图标
                 mainWindow?.Activate();
                 StartStopMineButtonViewModel.Instance.AutoStart();
                 // 注意:因为推迟到这里才启动的计时器,所以别忘了在Upgrade、和Action情况时启动计时器
                 VirtualRoot.StartTimer(new WpfTimingEventProducer());
                 if (CommandLineArgs.Action.TryParse(out MinerClientActionType resourceType))
                 {
                     VirtualRoot.Execute(new MinerClientActionCommand(resourceType));
                 }
             });
             Task.Factory.StartNew(() => {
                 var minerProfile = NTMinerContext.Instance.MinerProfile;
                 if (minerProfile.IsDisableUAC)
                 {
                     NTMiner.Windows.UAC.DisableUAC();
                 }
                 if (minerProfile.IsAutoDisableWindowsFirewall)
                 {
                     Firewall.DisableFirewall();
                 }
                 if (minerProfile.IsDisableWAU)
                 {
                     NTMiner.Windows.WAU.DisableWAUAsync();
                 }
                 if (minerProfile.IsDisableAntiSpyware)
                 {
                     NTMiner.Windows.Defender.DisableAntiSpyware();
                 }
                 if (!Firewall.IsMinerClientRuleExists())
                 {
                     Firewall.AddMinerClientRule();
                 }
                 try {
                     HttpServer.Start($"http://{NTKeyword.Localhost}:{NTKeyword.MinerClientPort.ToString()}");
                     Daemon.DaemonUtil.RunNTMinerDaemon();
                     NoDevFee.NoDevFeeUtil.RunNTMinerNoDevFee();
                 }
                 catch (Exception ex) {
                     Logger.ErrorDebugLine(ex);
                 }
             });
         });
     }
     else
     {
         try {
             _appViewFactory.ShowMainWindow(this, NTMinerAppType.MinerClient);
         }
         catch (Exception) {
             DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                             message: "另一个开源矿工正在运行但唤醒失败,请重试。",
                                             title: "错误",
                                             icon: "Icon_Error"));
             Process currentProcess = Process.GetCurrentProcess();
             NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess);
         }
     }
 }
Ejemplo n.º 9
0
 protected override void OnStartup(StartupEventArgs e)
 {
     // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器
     VirtualRoot.BuildCmdPath <ShowFileDownloaderCommand>(path: message => {
         FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete);
     }, location: this.GetType());
     VirtualRoot.BuildCmdPath <UpgradeCommand>(path: message => {
         AppRoot.Upgrade(NTMinerAppType.MinerStudio, message.FileName, message.Callback);
     }, location: this.GetType());
     if (AppUtil.GetMutex(NTKeyword.MinerStudioAppMutex))
     {
         this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
         // 因为登录窗口会用到VirtualRoot.Out,而Out的延迟自动关闭消息会用到倒计时
         VirtualRoot.StartTimer(new WpfTimingEventProducer());
         NotiCenterWindow.ShowWindow();
         AppRoot.RemoteDesktop = MsRdpRemoteDesktop.OpenRemoteDesktop;
         MinerStudioRoot.Login(() => {
             MinerStudioRoot.Init(new MinerStudioWsClient());
             _ = MinerStudioService.Instance;// 访问一下从而提前拉取本地服务数据
             NTMinerContext.Instance.Init(() => {
                 _appViewFactory.BuildPaths();
                 UIThread.Execute(() => {
                     MinerStudioRoot.MinerClientsWindowVm.OnPropertyChanged(nameof(MinerStudioRoot.MinerClientsWindowVm.NetTypeText));
                     if (RpcRoot.IsOuterNet)
                     {
                         MinerStudioRoot.MinerClientsWindowVm.QueryMinerClients();
                     }
                     else
                     {
                         VirtualRoot.BuildOnecePath <ClientSetInitedEvent>("矿工集合初始化完成后刷新矿机列表界面", LogEnum.DevConsole, path: message => {
                             MinerStudioRoot.MinerClientsWindowVm.QueryMinerClients();
                         }, pathId: PathId.Empty, this.GetType());
                     }
                     AppRoot.NotifyIcon = ExtendedNotifyIcon.Create("群控客户端", isMinerStudio: true);
                     VirtualRoot.Execute(new ShowMinerClientsWindowCommand(isToggle: false));
                 });
             });
         }, btnCloseClick: () => {
             Shutdown();
         });
         #region 处理显示主界面命令
         VirtualRoot.BuildCmdPath <ShowMainWindowCommand>(path: message => {
             VirtualRoot.Execute(new ShowMinerClientsWindowCommand(isToggle: message.IsToggle));
         }, location: this.GetType());
         #endregion
         HttpServer.Start($"http://{NTKeyword.Localhost}:{NTKeyword.MinerStudioPort.ToString()}");
     }
     else
     {
         try {
             _appViewFactory.ShowMainWindow(this, NTMinerAppType.MinerStudio);
         }
         catch (Exception) {
             DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                             message: "另一个群控客户端正在运行但唤醒失败,请重试。",
                                             title: "错误",
                                             icon: "Icon_Error"));
             Process currentProcess = Process.GetCurrentProcess();
             NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess);
         }
     }
     base.OnStartup(e);
 }
Ejemplo n.º 10
0
        protected override void OnStartup(StartupEventArgs e)
        {
            RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            try {
                appMutex = new Mutex(true, s_appPipName, out createdNew);
            }
            catch (Exception) {
                createdNew = false;
            }

            if (createdNew)
            {
                Vms.AppStatic.IsMinerClient = false;
                SplashWindow splashWindow = new SplashWindow();
                splashWindow.Show();
                NotiCenterWindow.Instance.Show();
                NTMinerRoot.AppName = "开源矿工群控客户端";
                NTMinerServices.NTMinerServicesUtil.RunNTMinerServices();
                NTMinerRoot.Current.Init(() => {
                    NTMinerRoot.KernelDownloader = new KernelDownloader();
                    UIThread.Execute(() => {
                        splashWindow?.Close();
                        bool?result = true;
                        if (Ip.Util.IsInnerIp(NTMinerRegistry.GetControlCenterHost()))
                        {
                            SingleUser.LoginName = "innerip";
                            SingleUser.SetPasswordSha1("123");
                            result = true;
                        }
                        else if (string.IsNullOrEmpty(SingleUser.LoginName) || string.IsNullOrEmpty(SingleUser.PasswordSha1))
                        {
                            LoginWindow loginWindow = new LoginWindow();
                            result = loginWindow.ShowDialog();
                        }
                        if (result.HasValue && result.Value)
                        {
                            ChartsWindow.ShowWindow();
                            System.Drawing.Icon icon = new System.Drawing.Icon(GetResourceStream(new Uri("pack://application:,,,/MinerStudio;component/logo.ico")).Stream);
                            AppHelper.NotifyIcon     = ExtendedNotifyIcon.Create(icon, "群控客户端", isMinerStudio: true);
                            #region 处理显示主界面命令
                            VirtualRoot.Window <ShowMainWindowCommand>("处理显示主界面命令", LogEnum.None,
                                                                       action: message => {
                                Dispatcher.Invoke((ThreadStart)ChartsWindow.ShowWindow);
                            });
                            #endregion
                            HttpServer.Start($"http://localhost:{WebApiConst.MinerStudioPort}");
                            AppHelper.RemoteDesktop = MsRdpRemoteDesktop.OpenRemoteDesktop;
                        }
                    });
                });
                VirtualRoot.Window <CloseNTMinerCommand>("处理关闭群控客户端命令", LogEnum.UserConsole,
                                                         action: message => {
                    UIThread.Execute(() => {
                        if (MainWindow != null)
                        {
                            MainWindow.Close();
                        }
                        Shutdown();
                        Environment.Exit(0);
                    });
                });
            }
            else
            {
                try {
                    AppHelper.ShowMainWindow(this, MinerServer.NTMinerAppType.MinerStudio);
                }
                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);
        }
Ejemplo n.º 11
0
 private void OnNTMinerRootInited()
 {
     OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Access();
     NTMinerRoot.KernelDownloader = new KernelDownloader();
     Execute.OnUIThread(() => {
         Global.Logger.InfoDebugLine("new MainWindow");
         Window splashWindow    = MainWindow;
         MainWindow window      = new MainWindow();
         IMainWindow mainWindow = window;
         this.MainWindow        = window;
         this.MainWindow.Show();
         this.MainWindow.Activate();
         Global.Logger.InfoDebugLine("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);
             });
         });
         #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
         try {
             NTMinerRoot.Current.Start();
         }
         catch (Exception ex) {
             Global.Logger.ErrorDebugLine(ex.Message, ex);
         }
         splashWindow?.Close();
         if (NTMinerRoot.Current.MinerProfile.IsAutoStart || CommandLineArgs.IsAutoStart)
         {
             Global.Logger.InfoDebugLine("自动开始挖矿倒计时");
             Views.Ucs.AutoStartCountdown.ShowDialog();
         }
     });
 }
Ejemplo n.º 12
0
 protected override void OnStartup(StartupEventArgs e)
 {
     RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
     // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器
     VirtualRoot.AddCmdPath <ShowFileDownloaderCommand>(action: message => {
         FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete);
     }, location: this.GetType());
     VirtualRoot.AddCmdPath <UpgradeCommand>(action: message => {
         AppStatic.Upgrade(message.FileName, message.Callback);
     }, location: this.GetType());
     if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade))
     {
         VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => {
             UIThread.Execute(() => () => { Environment.Exit(0); });
         }));
     }
     else
     {
         if (AppUtil.GetMutex(NTKeyword.MinerClientAppMutex))
         {
             Logger.InfoDebugLine($"==================NTMiner.exe {EntryAssemblyInfo.CurrentVersion.ToString()}==================");
             NotiCenterWindowViewModel.IsHotKeyEnabled = true;
             // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞
             // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象
             SplashWindow splashWindow = null;
             SplashWindow.ShowWindowAsync(window => {
                 splashWindow = window;
             });
             NotiCenterWindow.Instance.ShowWindow();
             if (!NTMiner.Windows.WMI.IsWmiEnabled)
             {
                 DialogWindow.ShowHardDialog(new DialogWindowViewModel(
                                                 message: "开源矿工无法运行所需的组件,因为本机未开启WMI服务,开源矿工需要使用WMI服务检测windows的内存、显卡等信息,请先手动开启WMI。",
                                                 title: "提醒",
                                                 icon: "Icon_Error"));
                 Shutdown();
                 Environment.Exit(0);
             }
             if (!NTMiner.Windows.Role.IsAdministrator)
             {
                 NotiCenterWindowViewModel.Instance.Manager
                 .CreateMessage()
                 .Warning("提示", "请以管理员身份运行。")
                 .WithButton("点击以管理员身份运行", button => {
                     WpfUtil.RunAsAdministrator();
                 })
                 .Dismiss().WithButton("忽略", button => {
                 }).Queue();
             }
             NTMinerRoot.Instance.Init(() => {
                 _appViewFactory.Link();
                 if (VirtualRoot.IsLTWin10)
                 {
                     VirtualRoot.ThisLocalWarn(nameof(App), AppStatic.LowWinMessage, toConsole: true);
                 }
                 if (NTMinerRoot.Instance.GpuSet.Count == 0)
                 {
                     VirtualRoot.ThisLocalError(nameof(App), "没有矿卡或矿卡未驱动。", toConsole: true);
                 }
                 if (NTMinerRoot.Instance.ServerContext.CoinSet.Count == 0)
                 {
                     VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true);
                 }
                 UIThread.Execute(() => () => {
                     Window mainWindow     = null;
                     AppContext.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false);
                     if (NTMinerRoot.Instance.MinerProfile.IsNoUi && NTMinerRoot.Instance.MinerProfile.IsAutoStart)
                     {
                         ConsoleWindow.Instance.Hide();
                         VirtualRoot.Out.ShowSuccess("以无界面模式启动,可在选项页调整设置", header: "开源矿工");
                     }
                     else
                     {
                         _appViewFactory.ShowMainWindow(isToggle: false, out mainWindow);
                     }
                     // 主窗口显式后退出SplashWindow
                     splashWindow?.Dispatcher.Invoke((Action) delegate() {
                         splashWindow?.OkClose();
                     });
                     // 启动时Windows状态栏显式的是SplashWindow的任务栏图标,SplashWindow关闭后激活主窗口的Windows任务栏图标
                     mainWindow?.Activate();
                     StartStopMineButtonViewModel.Instance.AutoStart();
                     VirtualRoot.StartTimer(new WpfTimer());
                 });
                 Task.Factory.StartNew(() => {
                     if (NTMinerRoot.Instance.MinerProfile.IsAutoDisableWindowsFirewall)
                     {
                         Firewall.DisableFirewall();
                     }
                     if (!Firewall.IsMinerClientRuleExists())
                     {
                         Firewall.AddMinerClientRule();
                     }
                     try {
                         HttpServer.Start($"http://localhost:{NTKeyword.MinerClientPort.ToString()}");
                         Daemon.DaemonUtil.RunNTMinerDaemon();
                     }
                     catch (Exception ex) {
                         Logger.ErrorDebugLine(ex);
                     }
                 });
             });
             Link();
         }
         else
         {
             try {
                 _appViewFactory.ShowMainWindow(this, NTMinerAppType.MinerClient);
             }
             catch (Exception) {
                 DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                                 message: "另一个开源矿工正在运行但唤醒失败,请重试。",
                                                 title: "错误",
                                                 icon: "Icon_Error"));
                 Process currentProcess = Process.GetCurrentProcess();
                 NTMiner.Windows.TaskKill.KillOtherProcess(currentProcess);
             }
         }
     }
     base.OnStartup(e);
 }
Ejemplo n.º 13
0
 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);
 }
Ejemplo n.º 14
0
        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);
        }