void UpdateCheck_Tick(object sender, EventArgs e) { Helpers.ConsolePrint("NICEHASH", "Version get"); string ver = NiceHashStats.GetVersion(textBoxBTCAddress.Text.Trim() + "." + textBoxWorkerName.Text.Trim()); if (ver == null) { return; } Version programVersion = new Version(Application.ProductVersion); Version onlineVersion = new Version(ver); int ret = programVersion.CompareTo(onlineVersion); if (ret < 0) { linkLabelVisitUs.Text = String.Format(International.GetText("Form_Main_new_version_released"), ver); VisitURL = Links.VisitURLNew + ver; } }
void UpdateCheck_Tick(object sender, EventArgs e) { Helpers.ConsolePrint("NICEHASH", "Version get"); string ver = NiceHashStats.GetVersion(textBox1.Text.Trim() + "." + textBox2.Text.Trim()); if (ver == null) { return; } Version programVersion = new Version(Application.ProductVersion); Version onlineVersion = new Version(ver); int ret = programVersion.CompareTo(onlineVersion); if (ret < 0) { linkLabel2.Text = "IMPORTANT! New version v" + ver + " has\r\nbeen released. Click here to download it."; VisitURL = "https://github.com/nicehash/NiceHashMiner/releases/tag/" + ver; } }
void SMACheck_Tick(object sender, EventArgs e) { string worker = textBox1.Text.Trim() + "." + textBox2.Text.Trim(); Helpers.ConsolePrint("NICEHASH", "SMA get"); NiceHashSMA[] t = NiceHashStats.GetAlgorithmRates(worker); for (int i = 0; i < 3; i++) { if (t != null) { NiceHashData = t; break; } Helpers.ConsolePrint("NICEHASH", "SMA get failed .. retrying"); System.Threading.Thread.Sleep(1000); t = NiceHashStats.GetAlgorithmRates(worker); } if (t == null && NiceHashData == null && ShowWarningNiceHashData) { ShowWarningNiceHashData = false; DialogResult dialogResult = MessageBox.Show("NiceHash Miner requires internet connection to run. " + "Please ensure that you are connected to the " + "internet before running NiceHash Miner. " + "Would you like to continue?", "Check internet connection", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { return; } else if (dialogResult == DialogResult.No) { System.Windows.Forms.Application.Exit(); } } }
void SMACheck_Tick(object sender, EventArgs e) { string worker = textBoxBTCAddress.Text.Trim() + "." + textBoxWorkerName.Text.Trim(); Helpers.ConsolePrint("NICEHASH", "SMA get"); Dictionary <AlgorithmType, NiceHashSMA> t = null; for (int i = 0; i < 5; i++) { t = NiceHashStats.GetAlgorithmRates(worker); if (t != null) { Globals.NiceHashData = t; break; } Helpers.ConsolePrint("NICEHASH", "SMA get failed .. retrying"); System.Threading.Thread.Sleep(1000); t = NiceHashStats.GetAlgorithmRates(worker); } if (t == null && Globals.NiceHashData == null && ShowWarningNiceHashData) { ShowWarningNiceHashData = false; DialogResult dialogResult = MessageBox.Show(International.GetText("Form_Main_msgbox_NoInternetMsg"), International.GetText("Form_Main_msgbox_NoInternetTitle"), MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (dialogResult == DialogResult.Yes) { return; } else if (dialogResult == DialogResult.No) { System.Windows.Forms.Application.Exit(); } } }
void BalanceCheck_Tick(object sender, EventArgs e) { if (VerifyMiningAddress()) { Helpers.ConsolePrint("NICEHASH", "Balance get"); double Balance = NiceHashStats.GetBalance(textBox1.Text.Trim(), textBox1.Text.Trim() + "." + textBox2.Text.Trim()); if (Balance > 0) { if (Config.ConfigData.AutoScaleBTCValues && Balance < 0.1) { toolStripStatusLabel7.Text = "mBTC"; toolStripStatusLabel6.Text = (Balance * 1000).ToString("F7", CultureInfo.InvariantCulture); } else { toolStripStatusLabel7.Text = "BTC"; toolStripStatusLabel6.Text = Balance.ToString("F8", CultureInfo.InvariantCulture); } toolStripStatusLabel3.Text = (Balance * BitcoinRate).ToString("F2", CultureInfo.InvariantCulture); } } }
private void ConnectionEstablishedCallback(object sender, EventArgs e) { // send credentials NiceHashStats.SetCredentials(textBoxBTCAddress.Text.Trim(), textBoxWorkerName.Text.Trim()); }
// This is a single shot _benchmarkTimer private void StartupTimer_Tick(object sender, EventArgs e) { _startupTimer.Stop(); _startupTimer = null; // Internals Init // TODO add loading step MinersSettingsManager.Init(); if (!Helpers.Is45NetOrHigher()) { MessageBox.Show(International.GetText("NET45_Not_Installed_msg"), International.GetText("Warning_with_Exclamation"), MessageBoxButtons.OK); Close(); return; } if (!Helpers.Is64BitOperatingSystem) { MessageBox.Show(International.GetText("Form_Main_x64_Support_Only"), International.GetText("Warning_with_Exclamation"), MessageBoxButtons.OK); Close(); return; } // 3rdparty miners check scope #1 { // check if setting set if (ConfigManager.GeneralConfig.Use3rdPartyMiners == Use3rdPartyMiners.NOT_SET) { // Show TOS Form tos = new Form_3rdParty_TOS(); tos.ShowDialog(this); } } // Query Avaliable ComputeDevices ComputeDeviceManager.Query.QueryDevices(_loadingScreen); _isDeviceDetectionInitialized = true; ///////////////////////////////////////////// /////// from here on we have our devices and Miners initialized ConfigManager.AfterDeviceQueryInitialization(); _loadingScreen.IncreaseLoadCounterAndMessage(International.GetText("Form_Main_loadtext_SaveConfig")); // All devices settup should be initialized in AllDevices devicesListViewEnableControl1.ResetComputeDevices(ComputeDeviceManager.Avaliable.AllAvaliableDevices); // set properties after devicesListViewEnableControl1.SaveToGeneralConfig = true; _loadingScreen.IncreaseLoadCounterAndMessage( International.GetText("Form_Main_loadtext_CheckLatestVersion")); _minerStatsCheck = new Timer(); _minerStatsCheck.Tick += MinerStatsCheck_Tick; _minerStatsCheck.Interval = ConfigManager.GeneralConfig.MinerAPIQueryInterval * 1000; //_smaMinerCheck = new Timer(); //_smaMinerCheck.Tick += SMAMinerCheck_Tick; //_smaMinerCheck.Interval = ConfigManager.GeneralConfig.SwitchMinSecondsFixed * 1000 + // R.Next(ConfigManager.GeneralConfig.SwitchMinSecondsDynamic * 1000); //if (ComputeDeviceManager.Group.ContainsAmdGpus) //{ // _smaMinerCheck.Interval = // (ConfigManager.GeneralConfig.SwitchMinSecondsAMD + // ConfigManager.GeneralConfig.SwitchMinSecondsFixed) * 1000 + // R.Next(ConfigManager.GeneralConfig.SwitchMinSecondsDynamic * 1000); //} _loadingScreen.IncreaseLoadCounterAndMessage(International.GetText("Form_Main_loadtext_GetNiceHashSMA")); // Init ws connection NiceHashStats.OnBalanceUpdate += BalanceCallback; NiceHashStats.OnSmaUpdate += SmaCallback; NiceHashStats.OnVersionUpdate += VersionUpdateCallback; NiceHashStats.OnConnectionLost += ConnectionLostCallback; NiceHashStats.OnConnectionEstablished += ConnectionEstablishedCallback; NiceHashStats.OnVersionBurn += VersionBurnCallback; NiceHashStats.StartConnection(Links.NhmSocketAddress); // increase timeout if (Globals.IsFirstNetworkCheckTimeout) { while (!Helpers.WebRequestTestGoogle() && Globals.FirstNetworkCheckTimeoutTries > 0) { --Globals.FirstNetworkCheckTimeoutTries; } } _loadingScreen.IncreaseLoadCounterAndMessage(International.GetText("Form_Main_loadtext_GetBTCRate")); _bitcoinExchangeCheck = new Timer(); _bitcoinExchangeCheck.Tick += BitcoinExchangeCheck_Tick; _bitcoinExchangeCheck.Interval = 1000 * 3601; // every 1 hour and 1 second _bitcoinExchangeCheck.Start(); BitcoinExchangeCheck_Tick(null, null); _loadingScreen.IncreaseLoadCounterAndMessage( International.GetText("Form_Main_loadtext_SetEnvironmentVariable")); Helpers.SetDefaultEnvironmentVariables(); _loadingScreen.IncreaseLoadCounterAndMessage( International.GetText("Form_Main_loadtext_SetWindowsErrorReporting")); Helpers.DisableWindowsErrorReporting(ConfigManager.GeneralConfig.DisableWindowsErrorReporting); _loadingScreen.IncreaseLoadCounter(); if (ConfigManager.GeneralConfig.NVIDIAP0State) { _loadingScreen.SetInfoMsg(International.GetText("Form_Main_loadtext_NVIDIAP0State")); Helpers.SetNvidiaP0State(); } _loadingScreen.FinishLoad(); var runVCRed = !MinersExistanceChecker.IsMinersBinsInit() && !ConfigManager.GeneralConfig.DownloadInit; // standard miners check scope { // check if download needed if (!MinersExistanceChecker.IsMinersBinsInit() && !ConfigManager.GeneralConfig.DownloadInit) { var downloadUnzipForm = new Form_Loading(new MinersDownloader(MinersDownloadManager.StandardDlSetup)); SetChildFormCenter(downloadUnzipForm); downloadUnzipForm.ShowDialog(); } // check if files are mising if (!MinersExistanceChecker.IsMinersBinsInit()) { var result = MessageBox.Show(International.GetText("Form_Main_bins_folder_files_missing"), International.GetText("Warning_with_Exclamation"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { ConfigManager.GeneralConfig.DownloadInit = false; ConfigManager.GeneralConfigFileCommit(); var pHandle = new Process { StartInfo = { FileName = Application.ExecutablePath } }; pHandle.Start(); Close(); return; } } else if (!ConfigManager.GeneralConfig.DownloadInit) { // all good ConfigManager.GeneralConfig.DownloadInit = true; ConfigManager.GeneralConfigFileCommit(); } } // 3rdparty miners check scope #2 { // check if download needed if (ConfigManager.GeneralConfig.Use3rdPartyMiners == Use3rdPartyMiners.YES) { if (!MinersExistanceChecker.IsMiners3rdPartyBinsInit() && !ConfigManager.GeneralConfig.DownloadInit3rdParty) { var download3rdPartyUnzipForm = new Form_Loading(new MinersDownloader(MinersDownloadManager.ThirdPartyDlSetup)); SetChildFormCenter(download3rdPartyUnzipForm); download3rdPartyUnzipForm.ShowDialog(); } // check if files are mising if (!MinersExistanceChecker.IsMiners3rdPartyBinsInit()) { var result = MessageBox.Show(International.GetText("Form_Main_bins_folder_files_missing"), International.GetText("Warning_with_Exclamation"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { ConfigManager.GeneralConfig.DownloadInit3rdParty = false; ConfigManager.GeneralConfigFileCommit(); var pHandle = new Process { StartInfo = { FileName = Application.ExecutablePath } }; pHandle.Start(); Close(); return; } } else if (!ConfigManager.GeneralConfig.DownloadInit3rdParty) { // all good ConfigManager.GeneralConfig.DownloadInit3rdParty = true; ConfigManager.GeneralConfigFileCommit(); } } } if (runVCRed) { Helpers.InstallVcRedist(); } if (ConfigManager.GeneralConfig.AutoStartMining) { // well this is started manually as we want it to start at runtime _isManuallyStarted = true; if (StartMining(true) != StartMiningReturnType.StartMining) { _isManuallyStarted = false; StopMining(); } } }
// This is a single shot _benchmarkTimer private void StartupTimer_Tick(object sender, EventArgs e) { _startupTimer.Stop(); _startupTimer = null; // Internals Init // TODO add loading step MinersSettingsManager.Init(); if (!Helpers.Is45NetOrHigher()) { MessageBox.Show(Tr("NiceHash Miner Legacy requires .NET Framework 4.5 or higher to work properly. Please install Microsoft .NET Framework 4.5"), Tr("Warning!"), MessageBoxButtons.OK); Close(); return; } if (!Helpers.Is64BitOperatingSystem) { MessageBox.Show(Tr("NiceHash Miner Legacy supports only x64 platforms. You will not be able to use NiceHash Miner Legacy with x86"), Tr("Warning!"), MessageBoxButtons.OK); Close(); return; } // 3rdparty miners check scope #1 { // check if setting set if (ConfigManager.GeneralConfig.Use3rdPartyMiners == Use3rdPartyMiners.NOT_SET) { // Show TOS Form tos = new Form_3rdParty_TOS(); tos.ShowDialog(this); } } // Query Available ComputeDevices ComputeDeviceManager.Query.QueryDevices(_loadingScreen); _isDeviceDetectionInitialized = true; ///////////////////////////////////////////// /////// from here on we have our devices and Miners initialized ConfigManager.AfterDeviceQueryInitialization(); _loadingScreen.IncreaseLoadCounterAndMessage(Tr("Saving config...")); // All devices settup should be initialized in AllDevices devicesListViewEnableControl1.ResetComputeDevices(ComputeDeviceManager.Available.Devices); // set properties after devicesListViewEnableControl1.SaveToGeneralConfig = true; _loadingScreen.IncreaseLoadCounterAndMessage( Tr("Checking for latest version...")); _minerStatsCheck = new Timer(); _minerStatsCheck.Tick += MinerStatsCheck_Tick; _minerStatsCheck.Interval = ConfigManager.GeneralConfig.MinerAPIQueryInterval * 1000; //_smaMinerCheck = new Timer(); //_smaMinerCheck.Tick += SMAMinerCheck_Tick; //_smaMinerCheck.Interval = ConfigManager.GeneralConfig.SwitchMinSecondsFixed * 1000 + // R.Next(ConfigManager.GeneralConfig.SwitchMinSecondsDynamic * 1000); //if (ComputeDeviceManager.Group.ContainsAmdGpus) //{ // _smaMinerCheck.Interval = // (ConfigManager.GeneralConfig.SwitchMinSecondsAMD + // ConfigManager.GeneralConfig.SwitchMinSecondsFixed) * 1000 + // R.Next(ConfigManager.GeneralConfig.SwitchMinSecondsDynamic * 1000); //} _loadingScreen.IncreaseLoadCounterAndMessage(Tr("Getting NiceHash SMA information...")); // Init ws connection NiceHashStats.OnBalanceUpdate += BalanceCallback; NiceHashStats.OnSmaUpdate += SmaCallback; NiceHashStats.OnVersionUpdate += VersionUpdateCallback; NiceHashStats.OnConnectionLost += ConnectionLostCallback; NiceHashStats.OnConnectionEstablished += ConnectionEstablishedCallback; NiceHashStats.OnVersionBurn += VersionBurnCallback; NiceHashStats.OnExchangeUpdate += ExchangeCallback; NiceHashStats.StartConnection(Links.NhmSocketAddress); // increase timeout if (Globals.IsFirstNetworkCheckTimeout) { while (!Helpers.WebRequestTestGoogle() && Globals.FirstNetworkCheckTimeoutTries > 0) { --Globals.FirstNetworkCheckTimeoutTries; } } _loadingScreen.IncreaseLoadCounterAndMessage(Tr("Getting Bitcoin exchange rate...")); //// Don't start timer if socket is giving data //if (ExchangeRateApi.ExchangesFiat == null) //{ // // Wait a bit and check again // Thread.Sleep(1000); // if (ExchangeRateApi.ExchangesFiat == null) // { // Helpers.ConsolePrint("NICEHASH", "No exchange from socket yet, getting manually"); // _bitcoinExchangeCheck = new Timer(); // _bitcoinExchangeCheck.Tick += BitcoinExchangeCheck_Tick; // _bitcoinExchangeCheck.Interval = 1000 * 3601; // every 1 hour and 1 second // _bitcoinExchangeCheck.Start(); // BitcoinExchangeCheck_Tick(null, null); // } //} _loadingScreen.IncreaseLoadCounterAndMessage( Tr("Setting environment variables...")); Helpers.SetDefaultEnvironmentVariables(); _loadingScreen.IncreaseLoadCounterAndMessage( Tr("Setting Windows error reporting...")); Helpers.DisableWindowsErrorReporting(ConfigManager.GeneralConfig.DisableWindowsErrorReporting); _loadingScreen.IncreaseLoadCounter(); if (ConfigManager.GeneralConfig.NVIDIAP0State) { _loadingScreen.SetInfoMsg(Tr("Changing all supported NVIDIA GPUs to P0 state...")); Helpers.SetNvidiaP0State(); } _loadingScreen.FinishLoad(); var runVCRed = !MinersExistanceChecker.IsMinersBinsInit() && !ConfigManager.GeneralConfig.DownloadInit; // standard miners check scope { // check if download needed if (!MinersExistanceChecker.IsMinersBinsInit() && !ConfigManager.GeneralConfig.DownloadInit) { var downloadUnzipForm = new Form_Loading(new MinersDownloader(MinersDownloadManager.StandardDlSetup)); SetChildFormCenter(downloadUnzipForm); downloadUnzipForm.ShowDialog(); } // check if files are mising if (!MinersExistanceChecker.IsMinersBinsInit()) { var result = MessageBox.Show(Tr("There are missing files from last Miners Initialization. Please make sure that your anti-virus is not blocking the application. NiceHash Miner Legacy might not work properly without missing files. Click Yes to reinitialize NiceHash Miner Legacy to try to fix this issue."), Tr("Warning!"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { ConfigManager.GeneralConfig.DownloadInit = false; ConfigManager.GeneralConfigFileCommit(); var pHandle = new Process { StartInfo = { FileName = Application.ExecutablePath } }; pHandle.Start(); Close(); return; } } else if (!ConfigManager.GeneralConfig.DownloadInit) { // all good ConfigManager.GeneralConfig.DownloadInit = true; ConfigManager.GeneralConfigFileCommit(); } } // 3rdparty miners check scope #2 { // check if download needed if (ConfigManager.GeneralConfig.Use3rdPartyMiners == Use3rdPartyMiners.YES) { if (!MinersExistanceChecker.IsMiners3rdPartyBinsInit() && !ConfigManager.GeneralConfig.DownloadInit3rdParty) { var download3rdPartyUnzipForm = new Form_Loading(new MinersDownloader(MinersDownloadManager.ThirdPartyDlSetup)); SetChildFormCenter(download3rdPartyUnzipForm); download3rdPartyUnzipForm.ShowDialog(); } // check if files are mising if (!MinersExistanceChecker.IsMiners3rdPartyBinsInit()) { var result = MessageBox.Show(Tr("There are missing files from last Miners Initialization. Please make sure that your anti-virus is not blocking the application. NiceHash Miner Legacy might not work properly without missing files. Click Yes to reinitialize NiceHash Miner Legacy to try to fix this issue."), Tr("Warning!"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { ConfigManager.GeneralConfig.DownloadInit3rdParty = false; ConfigManager.GeneralConfigFileCommit(); var pHandle = new Process { StartInfo = { FileName = Application.ExecutablePath } }; pHandle.Start(); Close(); return; } } else if (!ConfigManager.GeneralConfig.DownloadInit3rdParty) { // all good ConfigManager.GeneralConfig.DownloadInit3rdParty = true; ConfigManager.GeneralConfigFileCommit(); } } } if (runVCRed) { Helpers.InstallVcRedist(); } if (ConfigManager.GeneralConfig.AutoStartMining) { // well this is started manually as we want it to start at runtime _isManuallyStarted = true; if (StartMining(false) != StartMiningReturnType.StartMining) { _isManuallyStarted = false; StopMining(); } } }
// This is a single shot _benchmarkTimer private void StartupTimer_Tick(object sender, EventArgs e) { StartupTimer.Stop(); StartupTimer = null; // Internals Init // TODO add loading step MinersSettingsManager.Init(); if (!Helpers.Is45NetOrHigher()) { MessageBox.Show(International.GetText("NET45_Not_Installed_msg"), International.GetText("Warning_with_Exclamation"), MessageBoxButtons.OK); this.Close(); return; } if (!Helpers.Is64BitOperatingSystem) { MessageBox.Show(International.GetText("Form_Main_x64_Support_Only"), International.GetText("Warning_with_Exclamation"), MessageBoxButtons.OK); this.Close(); return; } // 3rdparty miners check scope #1 { // check if setting set if (ConfigManager.GeneralConfig.Use3rdPartyMiners == Use3rdPartyMiners.NOT_SET) { // Show TOS Form tos = new Form_3rdParty_TOS(); tos.ShowDialog(this); } } // Query Avaliable ComputeDevices ComputeDeviceManager.Query.QueryDevices(LoadingScreen); _isDeviceDetectionInitialized = true; ///////////////////////////////////////////// /////// from here on we have our devices and Miners initialized ConfigManager.AfterDeviceQueryInitialization(); LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("Form_Main_loadtext_SaveConfig")); // All devices settup should be initialized in AllDevices devicesListViewEnableControl1.ResetComputeDevices(ComputeDeviceManager.Avaliable.AllAvaliableDevices); // set properties after devicesListViewEnableControl1.SaveToGeneralConfig = true; LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("Form_Main_loadtext_CheckLatestVersion")); MinerStatsCheck = new Timer(); MinerStatsCheck.Tick += MinerStatsCheck_Tick; MinerStatsCheck.Interval = ConfigManager.GeneralConfig.MinerAPIQueryInterval * 1000; SMAMinerCheck = new Timer(); SMAMinerCheck.Tick += SMAMinerCheck_Tick; SMAMinerCheck.Interval = ConfigManager.GeneralConfig.SwitchMinSecondsFixed * 1000 + R.Next(ConfigManager.GeneralConfig.SwitchMinSecondsDynamic * 1000); if (ComputeDeviceManager.Group.ContainsAMD_GPUs) { SMAMinerCheck.Interval = (ConfigManager.GeneralConfig.SwitchMinSecondsAMD + ConfigManager.GeneralConfig.SwitchMinSecondsFixed) * 1000 + R.Next(ConfigManager.GeneralConfig.SwitchMinSecondsDynamic * 1000); } LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("Form_Main_loadtext_GetNiceHashSMA")); // Init ws connection NiceHashStats.OnBalanceUpdate += BalanceCallback; NiceHashStats.OnSMAUpdate += SMACallback; NiceHashStats.OnVersionUpdate += VersionUpdateCallback; NiceHashStats.OnConnectionLost += ConnectionLostCallback; NiceHashStats.OnConnectionEstablished += ConnectionEstablishedCallback; NiceHashStats.OnVersionBurn += VersionBurnCallback; NiceHashStats.StartConnection(Links.NHM_Socket_Address); // increase timeout if (Globals.IsFirstNetworkCheckTimeout) { while (!Helpers.WebRequestTestGoogle() && Globals.FirstNetworkCheckTimeoutTries > 0) { --Globals.FirstNetworkCheckTimeoutTries; } } LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("Form_Main_loadtext_GetBTCRate")); BitcoinExchangeCheck = new Timer(); BitcoinExchangeCheck.Tick += BitcoinExchangeCheck_Tick; BitcoinExchangeCheck.Interval = 1000 * 3601; // every 1 hour and 1 second BitcoinExchangeCheck.Start(); BitcoinExchangeCheck_Tick(null, null); LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("Form_Main_loadtext_SetEnvironmentVariable")); Helpers.SetDefaultEnvironmentVariables(); LoadingScreen.IncreaseLoadCounterAndMessage(International.GetText("Form_Main_loadtext_SetWindowsErrorReporting")); Helpers.DisableWindowsErrorReporting(ConfigManager.GeneralConfig.DisableWindowsErrorReporting); LoadingScreen.IncreaseLoadCounter(); if (ConfigManager.GeneralConfig.NVIDIAP0State) { LoadingScreen.SetInfoMsg(International.GetText("Form_Main_loadtext_NVIDIAP0State")); try { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "nvidiasetp0state.exe"; psi.Verb = "runas"; psi.UseShellExecute = true; psi.CreateNoWindow = true; Process p = Process.Start(psi); p.WaitForExit(); if (p.ExitCode != 0) { Helpers.ConsolePrint("NICEHASH", "nvidiasetp0state returned error code: " + p.ExitCode.ToString()); } else { Helpers.ConsolePrint("NICEHASH", "nvidiasetp0state all OK"); } } catch (Exception ex) { Helpers.ConsolePrint("NICEHASH", "nvidiasetp0state error: " + ex.Message); } } LoadingScreen.FinishLoad(); bool runVCRed = !MinersExistanceChecker.IsMinersBinsInit() && !ConfigManager.GeneralConfig.DownloadInit; // standard miners check scope { // check if download needed if (!MinersExistanceChecker.IsMinersBinsInit() && !ConfigManager.GeneralConfig.DownloadInit) { Form_Loading downloadUnzipForm = new Form_Loading(new MinersDownloader(MinersDownloadManager.StandardDlSetup)); SetChildFormCenter(downloadUnzipForm); downloadUnzipForm.ShowDialog(); } // check if files are mising if (!MinersExistanceChecker.IsMinersBinsInit()) { var result = MessageBox.Show(International.GetText("Form_Main_bins_folder_files_missing"), International.GetText("Warning_with_Exclamation"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { ConfigManager.GeneralConfig.DownloadInit = false; ConfigManager.GeneralConfigFileCommit(); Process PHandle = new Process(); PHandle.StartInfo.FileName = Application.ExecutablePath; PHandle.Start(); Close(); return; } } else if (!ConfigManager.GeneralConfig.DownloadInit) { // all good ConfigManager.GeneralConfig.DownloadInit = true; ConfigManager.GeneralConfigFileCommit(); } } // 3rdparty miners check scope #2 { // check if download needed if (ConfigManager.GeneralConfig.Use3rdPartyMiners == Use3rdPartyMiners.YES) { if (!MinersExistanceChecker.IsMiners3rdPartyBinsInit() && !ConfigManager.GeneralConfig.DownloadInit3rdParty) { Form_Loading download3rdPartyUnzipForm = new Form_Loading(new MinersDownloader(MinersDownloadManager.ThirdPartyDlSetup)); SetChildFormCenter(download3rdPartyUnzipForm); download3rdPartyUnzipForm.ShowDialog(); } // check if files are mising if (!MinersExistanceChecker.IsMiners3rdPartyBinsInit()) { var result = MessageBox.Show(International.GetText("Form_Main_bins_folder_files_missing"), International.GetText("Warning_with_Exclamation"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { ConfigManager.GeneralConfig.DownloadInit3rdParty = false; ConfigManager.GeneralConfigFileCommit(); Process PHandle = new Process(); PHandle.StartInfo.FileName = Application.ExecutablePath; PHandle.Start(); Close(); return; } } else if (!ConfigManager.GeneralConfig.DownloadInit3rdParty) { // all good ConfigManager.GeneralConfig.DownloadInit3rdParty = true; ConfigManager.GeneralConfigFileCommit(); } } } if (runVCRed) { Helpers.InstallVcRedist(); } // no bots please if (ConfigManager.GeneralConfigHwidLoadFromFile() && !ConfigManager.GeneralConfigHwidOK()) { var result = MessageBox.Show("NiceHash Miner Legacy has detected change of hardware ID. If you did not download and install NiceHash Miner Legacy, your computer may be compromised. In that case, we suggest you to install an antivirus program or reinstall your Windows.\r\n\r\nContinue with NiceHash Miner Legacy?", //International.GetText("Form_Main_msgbox_anti_botnet_msgbox"), International.GetText("Warning_with_Exclamation"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == System.Windows.Forms.DialogResult.No) { Close(); return; } else { // users agrees he installed it so commit changes ConfigManager.GeneralConfigFileCommit(); } } else { if (ConfigManager.GeneralConfig.AutoStartMining) { // well this is started manually as we want it to start at runtime IsManuallyStarted = true; if (StartMining(true) != StartMiningReturnType.StartMining) { IsManuallyStarted = false; StopMining(); } } } }
// TODO add check for any enabled algorithms public static (bool started, string failReason) StartAllAvailableDevices(bool isRpcCall = false) { var allDevs = AvailableDevices.Devices; var devicesToStart = allDevs.Where(dev => dev.State == DeviceState.Stopped); if (devicesToStart.Count() == 0) { return(false, "there are no new devices to start"); } // TODO for now no partial success so if one fails send back that everything fails var started = true; var failReason = ""; // TODO we have a BUG HERE if device enabled with all disabled algorithms var devicesToBenchmark = devicesToStart.Where(dev => dev.AllEnabledAlgorithmsWithoutBenchmarks() && dev.AnyAlgorithmEnabled()); var devicesToReBenchmark = devicesToStart.Where(dev => dev.HasEnabledAlgorithmsWithReBenchmark() && !devicesToBenchmark.Contains(dev)); foreach (var dev in devicesToBenchmark) { dev.State = DeviceState.Benchmarking; BenchmarkManager.StartBenchmarForDevice(dev, new BenchmarkStartSettings { StartMiningAfterBenchmark = true, BenchmarkPerformanceType = BenchmarkPerformanceType.Standard, BenchmarkOption = BenchmarkOption.ZeroOrReBenchOnly }); } foreach (var dev in devicesToReBenchmark) { dev.State = DeviceState.Benchmarking; BenchmarkManager.StartBenchmarForDevice(dev, new BenchmarkStartSettings { StartMiningAfterBenchmark = true, BenchmarkPerformanceType = BenchmarkPerformanceType.Standard, BenchmarkOption = BenchmarkOption.ReBecnhOnly }); } var devicesInErrorState = devicesToStart.Where(dev => !dev.AnyAlgorithmEnabled() || dev.AllEnabledAlgorithmsZeroPaying()).ToList(); var devicesInErrorStateUUIDs = devicesInErrorState.Select(dev => dev.Uuid); foreach (var dev in devicesInErrorState) { dev.State = DeviceState.Error; } // TODO check count var devicesToMine = devicesToStart.Where(dev => !dev.AllEnabledAlgorithmsWithoutBenchmarks() && !devicesInErrorStateUUIDs.Contains(dev.Uuid)).ToList(); foreach (var dev in devicesToMine) { dev.State = DeviceState.Mining; } UpdateDevicesToMine(); if (!isRpcCall) { NiceHashStats.StateChanged(); } RefreshDeviceListView?.Invoke(null, null); return(started, ""); }
public APIData GetSummary() { string resp; string aname = null; APIData ad = new APIData(); if (AlgoNameIs("ethereum")) { try { resp = NiceHashStats.GetNiceHashAPIData("http://127.0.0.1:" + Config.ConfigData.APIBindPortEthereumFrontEnd + "/stats", MinerDeviceName); if (resp == null) { return(null); } if (resp.Length < 800) { return(null); // response is too short } Eth <EthMiner> oo; oo = JsonConvert.DeserializeObject <Eth <EthMiner> >(resp); ad.Speed = 0; aname = "ethereum"; for (int i = 0; i < oo.miners.Length; i++) { if (!oo.miners[i].name.Equals(MinerDeviceName)) { continue; } if (oo.miners[i].timeout == true) { Helpers.ConsolePrint(MinerDeviceName, "Ethminer ERROR!"); return(null); } else if (oo.miners[i].warning == true) { Helpers.ConsolePrint(MinerDeviceName, "Ethminer WARNING!"); } ad.Speed = oo.miners[i].hashrate * 1000; break; } if (ad.Speed == 0) { return(null); } } catch (Exception e) { Helpers.ConsolePrint(MinerDeviceName, "GetSummary: " + e.Message); return(null); } } else { resp = GetAPIData(APIPort, "summary"); if (resp == null) { return(null); } try { string[] resps; if (!MinerDeviceName.Equals("AMD_OpenCL")) { resps = resp.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < resps.Length; i++) { string[] optval = resps[i].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (optval.Length != 2) { continue; } if (optval[0] == "ALGO") { aname = optval[1]; } else if (optval[0] == "KHS") { ad.Speed = double.Parse(optval[1], CultureInfo.InvariantCulture) * 1000; // HPS } } } else { // Checks if all the GPUs are Alive first string resp2 = GetAPIData(APIPort, "devs"); if (resp2 == null) { return(null); } string[] checkGPUStatus = resp2.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < checkGPUStatus.Length - 1; i++) { if (!checkGPUStatus[i].Contains("Status=Alive")) { Helpers.ConsolePrint(MinerDeviceName, "GPU " + i + ": Sick/Dead/NoStart/Initialising/Disabled/Rejecting/Unknown"); return(null); } } resps = resp.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (resps[1].Contains("SUMMARY")) { string[] data = resps[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // Get miner's current total speed string[] speed = data[4].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); // Get miner's current total MH double total_mh = Double.Parse(data[18].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries)[1], new CultureInfo("en-US")); ad.Speed = Double.Parse(speed[1]) * 1000; aname = SupportedAlgorithms[CurrentAlgo].MinerName; if (total_mh <= PreviousTotalMH) { Helpers.ConsolePrint(MinerDeviceName, "SGMiner might be stuck as no new hashes are being produced"); Helpers.ConsolePrint(MinerDeviceName, "Prev Total MH: " + PreviousTotalMH + " .. Current Total MH: " + total_mh); return(null); } PreviousTotalMH = total_mh; } else { ad.Speed = 0; } } } catch { return(null); } } FillAlgorithm(aname, ref ad); return(ad); }
private void DeviceStatusUpdate_Tick(object sender, EventArgs e) { NiceHashStats.SetDeviceStatus(ComputeDeviceManager.Avaliable.AllAvaliableDevices); }
public void AddRateInfo(string groupName, string deviceStringInfo, APIData iAPIData, double paying, List <String> devNames, bool isApiGetException) { string ApiGetExceptionString = isApiGetException ? "**" : ""; string speedString = Helpers.FormatDualSpeedOutput(iAPIData.Speed, iAPIData.SecondarySpeed) + iAPIData.AlgorithmName + ApiGetExceptionString; if (iAPIData.AlgorithmID == AlgorithmType.Equihash) { speedString = speedString.Replace("H/s", "Sols/s"); } string rateBTCString = FormatPayingOutput(paying); string rateCurrencyString = ExchangeRateAPI.ConvertToActiveCurrency(paying * Globals.BitcoinUSDRate).ToString("F2", CultureInfo.InvariantCulture) + String.Format(" {0}/", ExchangeRateAPI.ActiveDisplayCurrency) + International.GetText("Day"); ((GroupProfitControl)flowLayoutPanelRates.Controls[flowLayoutPanelRatesIndex++]) .UpdateProfitStats(groupName, deviceStringInfo, speedString, rateBTCString, rateCurrencyString); double Balance = NiceHashStats.GetBalance(textBoxBTCAddress.Text.Trim(), textBoxBTCAddress.Text.Trim() + "." + textBoxWorkerName.Text.Trim()); Dictionary <string, string> localDevNames = new Dictionary <string, string>(); localDevNames = new Dictionary <string, string>(); localDevNames["Devices"] = String.Join(",", devNames.ToArray()); localDevNames["BTCExRate"] = ExchangeRateAPI.ConvertToActiveCurrency(Globals.BitcoinUSDRate).ToString("F2", CultureInfo.InvariantCulture) + " " + ExchangeRateAPI.ActiveDisplayCurrency; localDevNames["BTCBalance"] = (Balance * 1000).ToString("F5", CultureInfo.InvariantCulture); bool found = false; int pos = 0; foreach (Dictionary <string, string> foundData in hashData) { if (foundData.ContainsKey("Devices")) { hashData[pos] = localDevNames; found = true; break; } pos++; } if (!found) { hashData.Add(localDevNames); } string[] devicesStrings = deviceStringInfo.Trim('{', ' ').Trim(' ', '}').Split(new string[] { ", " }, StringSplitOptions.None); Dictionary <string, string> localData = new Dictionary <string, string>(); localData = new Dictionary <string, string>(); localData["DeviceInfo"] = deviceStringInfo; localData["Speed"] = speedString; localData["RateBTC"] = rateBTCString; localData["RateCurrency"] = rateCurrencyString; localData["GroupName"] = groupName; found = false; pos = 0; foreach (Dictionary <string, string> foundData in hashData.ToArray()) { if (foundData.ContainsKey("GroupName")) { if (foundData["GroupName"] == groupName) { hashData[pos] = localData; found = true; break; } else { foreach (string deviceString in devicesStrings) { if (foundData["DeviceInfo"].Contains(deviceString)) { hashData.RemoveAt(pos); pos--; break; } } } } pos++; } if (!found) { hashData.Add(localData); } UpdateGlobalRate(); }