Ejemplo n.º 1
0
        private void ButtonBenchmark_Click(object sender, EventArgs e)
        {
            bool startMining = false;

            using (var benchmarkForm = new Form_Benchmark())
            {
                SetChildFormCenter(benchmarkForm);
                ApplicationStateManager.CurrentForm = ApplicationStateManager.CurrentFormState.Benchmark;
                benchmarkForm.ShowDialog();
                ApplicationStateManager.CurrentForm = ApplicationStateManager.CurrentFormState.Main;
                startMining = benchmarkForm.StartMiningOnFinish;
            }

            InitMainConfigGuiData();
            if (startMining)
            {
                ButtonStartMining_Click(null, null);
            }
        }
Ejemplo n.º 2
0
        private StartMiningReturnType StartMining(bool showWarnings)
        {
            if (textBoxBTCAddress.Text.Equals(""))
            {
                if (showWarnings)
                {
                    var result = MessageBox.Show(International.GetText("Form_Main_DemoModeMsg"),
                                                 International.GetText("Form_Main_DemoModeTitle"),
                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (result == DialogResult.Yes)
                    {
                        _demoMode             = true;
                        labelDemoMode.Visible = true;
                        labelDemoMode.Text    = International.GetText("Form_Main_DemoModeLabel");
                    }
                    else
                    {
                        return(StartMiningReturnType.IgnoreMsg);
                    }
                }
                else
                {
                    return(StartMiningReturnType.IgnoreMsg);

                    ;
                }
            }
            else if (!VerifyMiningAddress(true))
            {
                return(StartMiningReturnType.IgnoreMsg);
            }

            if (!NHSmaData.HasData)
            {
                if (showWarnings)
                {
                    MessageBox.Show(International.GetText("Form_Main_msgbox_NullNiceHashDataMsg"),
                                    International.GetText("Error_with_Exclamation"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(StartMiningReturnType.IgnoreMsg);
            }


            // Check if there are unbenchmakred algorithms
            var isBenchInit = true;

            foreach (var cdev in ComputeDeviceManager.Avaliable.AllAvaliableDevices)
            {
                if (cdev.Enabled)
                {
                    if (cdev.GetAlgorithmSettings().Where(algo => algo.Enabled).Any(algo => algo.BenchmarkSpeed == 0))
                    {
                        isBenchInit = false;
                    }
                }
            }
            // Check if the user has run benchmark first
            if (!isBenchInit)
            {
                var result = DialogResult.No;
                if (showWarnings)
                {
                    result = MessageBox.Show(International.GetText("EnabledUnbenchmarkedAlgorithmsWarning"),
                                             International.GetText("Warning_with_Exclamation"),
                                             MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                }
                if (result == DialogResult.Yes)
                {
                    _benchmarkForm = new Form_Benchmark(
                        BenchmarkPerformanceType.Standard,
                        true);
                    SetChildFormCenter(_benchmarkForm);
                    _benchmarkForm.ShowDialog();
                    _benchmarkForm = null;
                    InitMainConfigGuiData();
                }
                else if (result == DialogResult.No)
                {
                    // check devices without benchmarks
                    foreach (var cdev in ComputeDeviceManager.Avaliable.AllAvaliableDevices)
                    {
                        if (cdev.Enabled)
                        {
                            var enabled = cdev.GetAlgorithmSettings().Any(algo => algo.BenchmarkSpeed > 0);
                            cdev.Enabled = enabled;
                        }
                    }
                }
                else
                {
                    return(StartMiningReturnType.IgnoreMsg);
                }
            }

            textBoxBTCAddress.Enabled = false;
            textBoxWorkerName.Enabled = false;
            comboBoxLocation.Enabled  = false;
            buttonBenchmark.Enabled   = false;
            buttonStartMining.Enabled = false;
            buttonSettings.Enabled    = false;
            devicesListViewEnableControl1.IsMining = true;
            buttonStopMining.Enabled = true;

            // Disable profitable notification on start
            _isNotProfitable = false;

            ConfigManager.GeneralConfig.BitcoinAddress  = textBoxBTCAddress.Text.Trim();
            ConfigManager.GeneralConfig.WorkerName      = textBoxWorkerName.Text.Trim();
            ConfigManager.GeneralConfig.ServiceLocation = comboBoxLocation.SelectedIndex;

            InitFlowPanelStart();
            ClearRatesAll();

            var btcAdress = _demoMode ? Globals.DemoUser : textBoxBTCAddress.Text.Trim();
            var isMining  = MinersManager.StartInitialize(this, Globals.MiningLocation[comboBoxLocation.SelectedIndex],
                                                          textBoxWorkerName.Text.Trim(), btcAdress);

            if (!_demoMode)
            {
                ConfigManager.GeneralConfigFileCommit();
            }

            //_isSmaUpdated = true; // Always check profits on mining start
            //_smaMinerCheck.Interval = 100;
            //_smaMinerCheck.Start();
            _minerStatsCheck.Start();

            if (ConfigManager.GeneralConfig.RunScriptOnCUDA_GPU_Lost)
            {
                _computeDevicesCheckTimer          = new SystemTimer();
                _computeDevicesCheckTimer.Elapsed += ComputeDevicesCheckTimer_Tick;
                _computeDevicesCheckTimer.Interval = 60000;

                _computeDevicesCheckTimer.Start();
            }

            return(isMining ? StartMiningReturnType.StartMining : StartMiningReturnType.ShowNoMining);
        }
        private StartMiningReturnType StartMining(bool showWarnings)
        {
            if (textBoxBTCAddress.Text.Equals(""))
            {
                if (showWarnings)
                {
                    var result = MessageBox.Show(Tr("You have not entered a bitcoin address. NiceHash Miner Legacy will start mining in DEMO mode. In the DEMO mode, you can test run the miner and be able see how much you can earn using your computer. Would you like to continue in DEMO mode?\n\nDISCLAIMER: YOU WILL NOT EARN ANYTHING DURING DEMO MODE!"),
                                                 Tr("Start mining in DEMO mode?"),
                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (result == DialogResult.Yes)
                    {
                        _demoMode             = true;
                        labelDemoMode.Visible = true;
                        labelDemoMode.Text    = Tr("NiceHash Miner Legacy is running in DEMO mode!");
                    }
                    else
                    {
                        return(StartMiningReturnType.IgnoreMsg);
                    }
                }
                else
                {
                    return(StartMiningReturnType.IgnoreMsg);
                }
            }
            else if (!VerifyMiningAddress(true))
            {
                return(StartMiningReturnType.IgnoreMsg);
            }

            var hasData = NHSmaData.HasData;

            if (!showWarnings)
            {
                for (var i = 0; i < 10; i++)
                {
                    if (hasData)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                    hasData = NHSmaData.HasData;
                    Helpers.ConsolePrint("NICEHASH", $"After {i}s has data: {hasData}");
                }
            }

            if (!hasData)
            {
                Helpers.ConsolePrint("NICEHASH", "No data received within timeout");
                if (showWarnings)
                {
                    MessageBox.Show(Tr("Unable to get NiceHash profitability data. If you are connected to internet, try again later."),
                                    Tr("Error!"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(StartMiningReturnType.IgnoreMsg);
            }


            // Check if there are unbenchmakred algorithms
            var isBenchInit = true;

            foreach (var cdev in ComputeDeviceManager.Available.Devices)
            {
                if (cdev.Enabled)
                {
                    if (cdev.GetAlgorithmSettings().Where(algo => algo.Enabled).Any(algo => algo.BenchmarkSpeed == 0))
                    {
                        isBenchInit = false;
                    }
                }
            }
            // Check if the user has run benchmark first
            if (!isBenchInit)
            {
                var result = DialogResult.No;
                if (showWarnings)
                {
                    result = MessageBox.Show(Tr("There are unbenchmarked algorithms for selected enabled devices. Click Yes to benchmark and start mining, No to skip benchmark and continue mining, Cancel to abort"),
                                             Tr("Warning!"),
                                             MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                }
                if (result == DialogResult.Yes)
                {
                    _benchmarkForm = new Form_Benchmark(
                        BenchmarkPerformanceType.Standard,
                        true);
                    SetChildFormCenter(_benchmarkForm);
                    _benchmarkForm.ShowDialog();
                    _benchmarkForm = null;
                    InitMainConfigGuiData();
                }
                else if (result == DialogResult.No)
                {
                    // check devices without benchmarks
                    foreach (var cdev in ComputeDeviceManager.Available.Devices)
                    {
                        if (cdev.Enabled)
                        {
                            var enabled = cdev.GetAlgorithmSettings().Any(algo => algo.BenchmarkSpeed > 0);
                            cdev.Enabled = enabled;
                        }
                    }
                }
                else
                {
                    return(StartMiningReturnType.IgnoreMsg);
                }
            }

            textBoxBTCAddress.Enabled = false;
            textBoxWorkerName.Enabled = false;
            comboBoxLocation.Enabled  = false;
            buttonBenchmark.Enabled   = false;
            buttonStartMining.Enabled = false;
            buttonSettings.Enabled    = false;
            devicesListViewEnableControl1.IsMining = true;
            buttonStopMining.Enabled = true;

            // Disable profitable notification on start
            _isNotProfitable = false;

            ConfigManager.GeneralConfig.BitcoinAddress  = textBoxBTCAddress.Text.Trim();
            ConfigManager.GeneralConfig.WorkerName      = textBoxWorkerName.Text.Trim();
            ConfigManager.GeneralConfig.ServiceLocation = comboBoxLocation.SelectedIndex;

            InitFlowPanelStart();
            ClearRatesAll();

            var btcAdress = _demoMode ? Globals.DemoUser : textBoxBTCAddress.Text.Trim();
            var isMining  = MinersManager.StartInitialize(this, Globals.MiningLocation[comboBoxLocation.SelectedIndex],
                                                          textBoxWorkerName.Text.Trim(), btcAdress);

            if (!_demoMode)
            {
                ConfigManager.GeneralConfigFileCommit();
            }

            //_isSmaUpdated = true; // Always check profits on mining start
            //_smaMinerCheck.Interval = 100;
            //_smaMinerCheck.Start();
            _minerStatsCheck.Start();

            if (ConfigManager.GeneralConfig.RunScriptOnCUDA_GPU_Lost)
            {
                _computeDevicesCheckTimer          = new SystemTimer();
                _computeDevicesCheckTimer.Elapsed += ComputeDevicesCheckTimer_Tick;
                _computeDevicesCheckTimer.Interval = 60000;

                _computeDevicesCheckTimer.Start();
            }

            return(isMining ? StartMiningReturnType.StartMining : StartMiningReturnType.ShowNoMining);
        }
Ejemplo n.º 4
0
        private StartMiningReturnType StartMining(bool showWarnings)
        {
            if (textBoxBTCAddress.Text.Equals(""))
            {
                if (showWarnings)
                {
                    DialogResult result = MessageBox.Show(International.GetText("Form_Main_DemoModeMsg"),
                                                          International.GetText("Form_Main_DemoModeTitle"),
                                                          MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        DemoMode = true;
                        labelDemoMode.Visible = true;
                        labelDemoMode.Text    = International.GetText("Form_Main_DemoModeLabel");
                    }
                    else
                    {
                        return(StartMiningReturnType.IgnoreMsg);
                    }
                }
                else
                {
                    return(StartMiningReturnType.IgnoreMsg);;
                }
            }
            else if (!VerifyMiningAddress(true))
            {
                return(StartMiningReturnType.IgnoreMsg);
            }

            if (Globals.NiceHashData == null)
            {
                if (showWarnings)
                {
                    MessageBox.Show(International.GetText("Form_Main_msgbox_NullNiceHashDataMsg"),
                                    International.GetText("Error_with_Exclamation"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(StartMiningReturnType.IgnoreMsg);
            }


            // Check if there are unbenchmakred algorithms
            bool isBenchInit       = true;
            bool hasAnyAlgoEnabled = false;

            foreach (var cdev in ComputeDeviceManager.Avaliable.AllAvaliableDevices)
            {
                if (cdev.Enabled)
                {
                    foreach (var algo in cdev.GetAlgorithmSettings())
                    {
                        if (algo.Enabled == true)
                        {
                            hasAnyAlgoEnabled = true;
                            if (algo.BenchmarkSpeed == 0)
                            {
                                isBenchInit = false;
                                break;
                            }
                        }
                    }
                }
            }
            // Check if the user has run benchmark first
            if (!isBenchInit)
            {
                DialogResult result = DialogResult.No;
                if (showWarnings)
                {
                    result = MessageBox.Show(International.GetText("EnabledUnbenchmarkedAlgorithmsWarning"),
                                             International.GetText("Warning_with_Exclamation"),
                                             MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                }
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    BenchmarkForm = new Form_Benchmark(
                        BenchmarkPerformanceType.Standard,
                        true);
                    SetChildFormCenter(BenchmarkForm);
                    BenchmarkForm.ShowDialog();
                    BenchmarkForm = null;
                    InitMainConfigGUIData();
                }
                else if (result == System.Windows.Forms.DialogResult.No)
                {
                    // check devices without benchmarks
                    foreach (var cdev in ComputeDeviceManager.Avaliable.AllAvaliableDevices)
                    {
                        if (cdev.Enabled)
                        {
                            bool Enabled = false;
                            foreach (var algo in cdev.GetAlgorithmSettings())
                            {
                                if (algo.BenchmarkSpeed > 0)
                                {
                                    Enabled = true;
                                    break;
                                }
                            }
                            cdev.Enabled = Enabled;
                        }
                    }
                }
                else
                {
                    return(StartMiningReturnType.IgnoreMsg);
                }
            }

            textBoxBTCAddress.Enabled = false;
            textBoxWorkerName.Enabled = false;
            comboBoxLocation.Enabled  = false;
            buttonBenchmark.Enabled   = false;
            buttonStartMining.Enabled = false;
            buttonSettings.Enabled    = false;
            devicesListViewEnableControl1.IsMining = true;
            buttonStopMining.Enabled = true;

            // Disable profitable notification on start
            IsNotProfitable = false;

            ConfigManager.GeneralConfig.BitcoinAddress  = textBoxBTCAddress.Text.Trim();
            ConfigManager.GeneralConfig.WorkerName      = textBoxWorkerName.Text.Trim();
            ConfigManager.GeneralConfig.ServiceLocation = comboBoxLocation.SelectedIndex;

            InitFlowPanelStart();
            ClearRatesALL();

            var btcAdress = DemoMode ? Globals.DemoUser : textBoxBTCAddress.Text.Trim();
            var isMining  = MinersManager.StartInitialize(this, Globals.MiningLocation[comboBoxLocation.SelectedIndex], textBoxWorkerName.Text.Trim(), btcAdress);

            if (!DemoMode)
            {
                ConfigManager.GeneralConfigFileCommit();
            }

            isSMAUpdated           = true; // Always check profits on mining start
            SMAMinerCheck.Interval = 100;
            SMAMinerCheck.Start();
            MinerStatsCheck.Start();

            return(isMining ? StartMiningReturnType.StartMining : StartMiningReturnType.ShowNoMining);
        }