Пример #1
0
 public static void addRow(ref UIDataGridView GPUStatusTable, ref UIDataGridView GPUOverClockTable)
 {
     try
     {
         szzminer_overclock.AMD.NvmlHelper nvmlHelper        = new szzminer_overclock.AMD.NvmlHelper();
         List <szzminer_overclock.AMD.NvmlHelper.NvGpu> gpus = nvmlHelper.GetGpus();
         for (int i = 0; i < gpus.Count; i++)
         {
             GPUStatusTable.Rows.Add();
             GPUOverClockTable.Rows.Add();
             GPUStatusTable.Rows[i].Cells[2].Value = "0";
             GPUStatusTable.Rows[i].Cells[3].Value = "0";
             GPUStatusTable.Rows[i].Cells[4].Value = "0";
         }
     }
     catch
     {
     }
     try
     {
         AdlHelper adl = new AdlHelper();
         for (int i = 0; i < adl.ATIGpus.Count; i++)
         {
             GPUStatusTable.Rows.Add();
             GPUOverClockTable.Rows.Add();
         }
     }
     catch
     {
     }
 }
Пример #2
0
        public static void getGPU(ref UIDataGridView GPUStatusTable, ref int totalPower)
        {
            int GPUCount = 0;

            try
            {
                szzminer_overclock.AMD.NvmlHelper              nvmlHelper  = new szzminer_overclock.AMD.NvmlHelper();
                szzminer_overclock.AMD.NvapiHelper             nvapiHelper = new szzminer_overclock.AMD.NvapiHelper();
                List <szzminer_overclock.AMD.NvmlHelper.NvGpu> gpus        = nvmlHelper.GetGpus();
                uint coretemp = 0;
                uint memtemp  = 0;
                for (int i = 0; i < gpus.Count; i++)
                {
                    szzminer_overclock.AMD.OverClockRange overClockRange = nvapiHelper.GetClockRange(gpus[i].BusId);
                    GPUStatusTable.Rows[GPUCount].Cells[0].Value = gpus[i].BusId;
                    GPUStatusTable.Rows[GPUCount].Cells[1].Value = "NVIDIA " + gpus[i].Name + " " + gpus[i].TotalMemory / 1024 / 1000 / 1000 + "GB";
                    GPUStatusTable.Rows[GPUCount].Cells[5].Value = nvmlHelper.GetPowerUsage(i);
                    nvapiHelper.GetCoreTemperature(gpus[i].BusId, out coretemp);
                    nvapiHelper.GetMemTemperature(gpus[i].BusId, out memtemp);
                    GPUStatusTable.Rows[GPUCount].Cells[6].Value = coretemp.ToString() + "/" + memtemp.ToString();
                    GPUStatusTable.Rows[GPUCount].Cells[7].Value = nvmlHelper.GetFanSpeed(i);
                    GPUStatusTable.Rows[GPUCount].Cells[8].Value = nvmlHelper.GetCoreClock(i) + "Mhz";
                    GPUStatusTable.Rows[GPUCount].Cells[9].Value = nvmlHelper.GetMemoryClock(i) + "Mhz";
                    totalPower += Convert.ToInt32(GPUStatusTable.Rows[GPUCount].Cells[5].Value);
                    GPUCount++;
                }
            }
            catch
            {
                //WriteLog("没有发现N卡");
            }
            try
            {
                AdlHelper   adl = new AdlHelper();
                const ulong a = 1024 * 1024 * 1024;
                uint        power = 0, fan = 0;
                int         temp = 0;
                int         memtemp = 0;
                int         coreClock = 0, memoryClock = 0;
                for (int i = 0; i < adl.ATIGpus.Count; i++)
                {
                    adl.GetPowerFanTemp(adl.ATIGpus[i].BusNumber, out power, out fan, out temp, out memtemp);
                    adl.GetClockRange(adl.ATIGpus[i].BusNumber, out coreClock, out memoryClock);
                    GPUStatusTable.Rows[GPUCount].Cells[0].Value = adl.ATIGpus[i].BusNumber;
                    GPUStatusTable.Rows[GPUCount].Cells[1].Value = adl.ATIGpus[i].AdapterName + " " + ((adl.GetTotalMemory(adl.ATIGpus[i].AdapterIndex) + a - 1) / a).ToString() + "GB";;
                    GPUStatusTable.Rows[GPUCount].Cells[5].Value = power;
                    GPUStatusTable.Rows[GPUCount].Cells[6].Value = temp;
                    GPUStatusTable.Rows[GPUCount].Cells[7].Value = fan;
                    GPUStatusTable.Rows[GPUCount].Cells[8].Value = coreClock / 1000 + "Mhz";
                    GPUStatusTable.Rows[GPUCount].Cells[9].Value = memoryClock / 1000 + "Mhz";
                    totalPower += Convert.ToInt32(GPUStatusTable.Rows[GPUCount].Cells[5].Value);
                    GPUCount++;
                }
            }
            catch
            {
            }
        }
Пример #3
0
        public static void getOverclockGPU(ref UIDataGridView GPUOverClockTable)
        {
            int GPUCount = 0;

            try
            {
                szzminer_overclock.AMD.NvmlHelper              nvmlHelper  = new szzminer_overclock.AMD.NvmlHelper();
                szzminer_overclock.AMD.NvapiHelper             nvapiHelper = new szzminer_overclock.AMD.NvapiHelper();
                List <szzminer_overclock.AMD.NvmlHelper.NvGpu> gpus        = nvmlHelper.GetGpus();
                for (int i = 0; i < gpus.Count; i++)
                {
                    szzminer_overclock.AMD.OverClockRange overClockRange = nvapiHelper.GetClockRange(gpus[i].BusId);
                    GPUOverClockTable.Rows[GPUCount].Cells[0].Value = gpus[i].BusId;
                    GPUOverClockTable.Rows[GPUCount].Cells[1].Value = "NVIDIA " + gpus[i].Name + " " + gpus[i].TotalMemory / 1024 / 1000 / 1000 + "GB";
                    GPUOverClockTable.Rows[GPUCount].Cells[5].Value = "N/A";
                    GPUOverClockTable.Rows[GPUCount].Cells[7].Value = "N/A";
                    GPUCount++;
                }
            }
            catch
            {
                //WriteLog("没有发现N卡");
            }
            try
            {
                AdlHelper   adl = new AdlHelper();
                const ulong a   = 1024 * 1024 * 1024;
                for (int i = 0; i < adl.ATIGpus.Count; i++)
                {
                    uint power, fan;
                    int  temp;
                    int  coreClock, memoryClock;
                    adl.GetPowerFanTemp(adl.ATIGpus[i].BusNumber, out power, out fan, out temp);
                    adl.GetClockRange(adl.ATIGpus[i].BusNumber, out coreClock, out memoryClock);
                    GPUOverClockTable.Rows[GPUCount].Cells[0].Value = adl.ATIGpus[i].BusNumber;
                    GPUOverClockTable.Rows[GPUCount].Cells[1].Value = adl.ATIGpus[i].AdapterName + " " + ((adl.GetTotalMemory(adl.ATIGpus[i].AdapterIndex) + a - 1) / a).ToString() + "GB";;
                    GPUOverClockTable.Rows[GPUCount].Cells[2].Value = adl.ATIGpus[i].PowerDefault.ToString();
                    GPUOverClockTable.Rows[GPUCount].Cells[3].Value = adl.ATIGpus[i].TempLimitDefault.ToString();
                    GPUOverClockTable.Rows[GPUCount].Cells[4].Value = (adl.ATIGpus[i].coreClockSelf).ToString();
                    GPUOverClockTable.Rows[GPUCount].Cells[5].Value = adl.ATIGpus[i].CoreVolt;
                    GPUOverClockTable.Rows[GPUCount].Cells[6].Value = (adl.ATIGpus[i].memoryClockSelf / 1000).ToString();
                    GPUOverClockTable.Rows[GPUCount].Cells[7].Value = adl.ATIGpus[i].MemoryVolt;
                    GPUCount++;
                }
            }
            catch
            {
            }
        }
Пример #4
0
 public AMDOverClock(AdlHelper adlHelper)
 {
     _adlHelper = adlHelper;
 }
Пример #5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            // 之所以提前到这里是因为升级之前可能需要下载升级器,下载升级器时需要下载器
            VirtualRoot.AddCmdPath <ShowFileDownloaderCommand>(action: message => {
                FileDownloader.ShowWindow(message.DownloadFileUrl, message.FileTitle, message.DownloadComplete);
            }, location: this.GetType());
            VirtualRoot.AddCmdPath <UpgradeCommand>(action: message => {
                AppRoot.Upgrade(NTMinerAppType.MinerClient, message.FileName, message.Callback);
            }, location: this.GetType());
            VirtualRoot.AddCmdPath <MinerClientActionCommand>(action: message => {
                Task task = TaskEx.CompletedTask;
                try {
                    // 注意不要提前return,因为最后需要执行Environment.Exit(0)
                    switch (message.ActionType)
                    {
                    case MinerClientActionType.AtikmdagPatcher: {
                        AdlHelper adlHelper = new AdlHelper();
                        if (adlHelper.GpuCount != 0)
                        {
                            task = AtikmdagPatcher.AtikmdagPatcherUtil.Run();
                        }
                    }
                    break;

                    case MinerClientActionType.SwitchRadeonGpuOn: {
                        AdlHelper adlHelper = new AdlHelper();
                        if (adlHelper.GpuCount != 0)
                        {
                            task = SwitchRadeonGpu.SwitchRadeonGpu.Run(on: true);
                        }
                    }
                    break;

                    case MinerClientActionType.SwitchRadeonGpuOff: {
                        AdlHelper adlHelper = new AdlHelper();
                        task = SwitchRadeonGpu.SwitchRadeonGpu.Run(on: false);
                    }
                    break;

                    case MinerClientActionType.BlockWAU:
                        task = NTMiner.Windows.WindowsUtil.BlockWAU();
                        break;

                    default:
                        break;
                    }
                }
                catch {
                }
                task.ContinueWith(t => {
                    Environment.Exit(0);
                });
            }, location: this.GetType());
            if (!string.IsNullOrEmpty(CommandLineArgs.Upgrade))
            {
                VirtualRoot.Execute(new UpgradeCommand(CommandLineArgs.Upgrade, () => {
                    UIThread.Execute(() => () => { Environment.Exit(0); });
                }));
            }
            else if (!string.IsNullOrEmpty(CommandLineArgs.Action))
            {
                if (CommandLineArgs.Action.TryParse(out MinerClientActionType resourceType))
                {
                    VirtualRoot.Execute(new MinerClientActionCommand(resourceType));
                }
            }
            else
            {
                if (AppUtil.GetMutex(NTKeyword.MinerClientAppMutex))
                {
                    Logger.InfoDebugLine($"==================NTMiner.exe {EntryAssemblyInfo.CurrentVersionStr}==================");
                    // 在另一个UI线程运行欢迎界面以确保欢迎界面的响应不被耗时的主界面初始化过程阻塞
                    // 注意:必须确保SplashWindow没有用到任何其它界面用到的依赖对象
                    SplashWindow splashWindow = null;
                    SplashWindow.ShowWindowAsync(window => {
                        splashWindow = window;
                    });
                    NotiCenterWindow.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();
                    }
                    NTMinerContext.Instance.Init(() => {
                        _appViewFactory.Link();
                        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.Instance.ServerContext.CoinSet.Count == 0)
                        {
                            VirtualRoot.ThisLocalError(nameof(App), "访问阿里云失败,请尝试更换本机dns解决此问题。", toConsole: true);
                        }
                        UIThread.Execute(() => () => {
                            Window mainWindow  = null;
                            AppRoot.NotifyIcon = ExtendedNotifyIcon.Create("开源矿工", isMinerStudio: false);
                            if (NTMinerContext.Instance.MinerProfile.IsNoUi && NTMinerContext.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 WpfTimingEventProducer());
                        });
                        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);
                            }
                        });
                    });
                    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);
        }