Ejemplo n.º 1
0
        private void StartMiner(PriceEntryBase entry, bool isMinimizedToTray = false)
        {
            _nextRun = null;
            _nextRunFromTime = null;
            _currentRunning = entry;
            _startMining = DateTime.Now;
            _stoppedMining = null;

            _process = new Process();
            if (_donationMiningMode == MiningModeEnum.Donation)
            {
                if (!string.IsNullOrWhiteSpace(entry.DonationFolder))
                    _process.StartInfo.WorkingDirectory = entry.DonationFolder;
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.DonationFolder)
                    ? entry.DonationCommand
                    : string.Format(@"{0}\{1}", entry.DonationFolder, entry.DonationCommand);
                _process.StartInfo.Arguments = DetectNiceHashStratum(entry) + entry.DonationArguments;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(entry.Folder))
                    _process.StartInfo.WorkingDirectory = entry.Folder;
                _process.StartInfo.FileName = string.IsNullOrWhiteSpace(entry.Folder)
                    ? entry.Command
                    : string.Format(@"{0}\{1}", entry.Folder, entry.Command);
                _process.StartInfo.Arguments = DetectNiceHashStratum(entry) + entry.Arguments;
            }

            WriteConsole(
                string.Format("Starting {0} {1} with {2} {3}", _currentRunning.ServicePrint, _currentRunning.Name,
                    _process.StartInfo.FileName, _process.StartInfo.Arguments), true);

            if (!string.IsNullOrWhiteSpace(_process.StartInfo.WorkingDirectory) &&
                !Directory.Exists(_process.StartInfo.WorkingDirectory))
            {
                entry.DeadTime = DateTime.Now;
                string message = string.Format("Path '{0}' does not exist.", _process.StartInfo.WorkingDirectory);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }
            if (!string.IsNullOrWhiteSpace(_process.StartInfo.FileName) && !File.Exists(_process.StartInfo.FileName))
            {
                entry.DeadTime = DateTime.Now;
                string message = string.Format("File '{0}' does not exist.", _process.StartInfo.FileName);
                _process = null;
                WriteConsole(message, true);
                throw new ArgumentException(message);
            }

            if (entry.UseWindow)
            {
                _process.StartInfo.WindowStyle = (isMinimizedToTray && TrayMode == 2)
                    ? ProcessWindowStyle.Hidden
                    : ProcessWindowStyle.Minimized;
                _process.Start();

                Thread.Sleep(100);
                try
                {
                    ProcessUtil.SetWindowTitle(_process, string.Format("{0} {1} Miner", entry.ServicePrint, entry.Name));
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                }

                if (isMinimizedToTray && TrayMode == 1)
                    HideMinerWindow();
            }
            else
            {
                _process.StartInfo.RedirectStandardOutput = true;
                _process.StartInfo.RedirectStandardError = true;
                _process.EnableRaisingEvents = true;
                _process.StartInfo.CreateNoWindow = true;
                _process.StartInfo.UseShellExecute = false;

                _process.ErrorDataReceived += ProcessConsoleOutput;
                _process.OutputDataReceived += ProcessConsoleOutput;

                _process.Start();

                _process.BeginOutputReadLine();
                _process.BeginErrorReadLine();
            }

            ProcessPriorityClass processPriority;
            if (entry.Priority != "Normal" && entry.Priority != string.Empty
                && Enum.TryParse(entry.Priority, out processPriority))
            {
                // Defaults to Normal, other possible values are Idle, BelowNormal,
                // AboveNormal, High & RealTime. ccminer <3 RealTime
                // Note 1: Realtime by minercontrol is only possible when given administrator privileges to minercontrol
                // Note 2: --cpu-priority by ccminer overrides minercontrols priority
                // Note 3: When giving administrator privileges to minercontrol and setting the priority by minercontrol to
                // something DIFFERENT than what's used by --cpu-priority by ccminer, then your whole system locks up
                _process.PriorityClass = processPriority;
            }

            if (entry.Affinity > 0)
            {
                // Just like with start /affinity, you can use 1 for first core, 2 for second core, 4 for third core, etc
                _process.ProcessorAffinity = (IntPtr) entry.Affinity;
            }

            _startMining = DateTime.Now;
            _donationMiningMode = MiningMode;

            entry.UpdateStatus();

            LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationStart" : "Start");
        }