예제 #1
0
        private void MinerActions_Click(object sender, EventArgs e)
        {
            string strError = string.Empty;
            dgvMiners.EndEdit();

            try
            {
                PictureBox pic = sender as PictureBox;
                settings = settingsCall.GetSettings(ref strError);

                if (!string.IsNullOrEmpty(strError))
                    UserMessage.ShowMessage(this, UserMessage.MessageType.Error, "An error occurred while trying to get the settings data: Error: " + strError);
                else
                {
                    if (pic.Name == picMoveDownMiner.Name || pic.Name == picMoveUpMiner.Name || pic.Name == picRemoveMiner.Name || pic.Name == picEditMiner.Name)
                    {
                        if (dgvMiners.SelectedRows.Count <= 0)
                            UserMessage.ShowMessage(this, UserMessage.MessageType.Warning, "Please select a miner.");
                        else
                        {
                            if (pic.Name == picMoveDownMiner.Name)
                            {
                                var row = dgvMiners.SelectedRows[0];
                                int index = dgvMiners.SelectedRows[0].Index;
                                Miner miner = row.Cells[1].Value.ToString() == "GPU" ? Miner.GPU : Miner.CPU;
                                GpuMinerData gpuMiner = settings.GpuMiners.SingleOrDefault(x => x.MinerGUID == Guid.Parse(row.Cells[0].Value.ToString()));
                                CpuMinerData cpuMiner = settings.CpuMiners.SingleOrDefault(x => x.MinerGUID == Guid.Parse(row.Cells[0].Value.ToString()));

                                if (!SelectedRowCanMove(index, "DOWN"))
                                    return;

                                dgvMiners.Rows.Remove(row);
                                dgvMiners.Rows.Insert(index + 1, row);

                                if (miner == Miner.GPU)
                                {
                                    settings.GpuMiners.Remove(gpuMiner);
                                    settings.GpuMiners.Insert(index + 1, gpuMiner);
                                }
                                else if (miner == Miner.CPU)
                                {
                                    settings.CpuMiners.Remove(cpuMiner);
                                    settings.CpuMiners.Insert(index + 1, cpuMiner);
                                }

                                if (!string.IsNullOrEmpty(strError))
                                {
                                    UserMessage.ShowMessage(this, UserMessage.MessageType.Error, "An error ocurred while trying to save the data. Error: " + strError);
                                    dgvMiners.Rows.Insert(index, row); //Reinsert the old row back at the original index because an error occurred during save

                                    if (miner == Miner.GPU)
                                        settings.GpuMiners.Insert(index, gpuMiner);
                                    else
                                        settings.CpuMiners.Insert(index, cpuMiner);

                                    SetSelectedRow(index);
                                }
                                else
                                {
                                    SetSelectedRow(index + 1);
                                    settingsCall.SeriliazeSettings(settings);
                                }
                            }
                            else if (pic.Name == picMoveUpMiner.Name)
                            {
                                var row = dgvMiners.SelectedRows[0];
                                int index = dgvMiners.SelectedRows[0].Index;

                                if (!SelectedRowCanMove(index, "UP"))
                                    return;

                                dgvMiners.Rows.Remove(row);
                                dgvMiners.Rows.Insert(index - 1, row);

                                //SaveMinerSettings(ref strError);
                                if (!string.IsNullOrEmpty(strError))
                                {
                                    UserMessage.ShowMessage(this, UserMessage.MessageType.Error, "An error ocurred while trying to save the data. Error: " + strError);
                                    dgvMiners.Rows.Insert(index, row); //Reinsert the old row back at the original index because an error occurred during save
                                    SetSelectedRow(index);
                                }
                                else
                                {
                                    SetSelectedRow(index - 1);
                                }
                            }
                            else if (pic.Name == picEditMiner.Name)
                            {
                                frmMiner miner = null;

                                if (dgvMiners.SelectedRows[0].Cells[1].Value.ToString() == "GPU")
                                    miner = new frmMiner(frmMiner.Type.Edit, frmMiner.Miner.GPU, Guid.Parse(dgvMiners.SelectedRows[0].Cells[0].Value.ToString()));
                                else if (dgvMiners.SelectedRows[0].Cells[1].Value.ToString() == "CPU")
                                    miner = new frmMiner(frmMiner.Type.Edit, frmMiner.Miner.CPU, Guid.Parse(dgvMiners.SelectedRows[0].Cells[0].Value.ToString()));

                                miner.ShowDialog();
                            }
                            else if (pic.Name == picRemoveMiner.Name)
                            {
                                if (MessageBox.Show("Are you sure you want to remove that miner?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                                {
                                    if (dgvMiners.SelectedRows[0].Cells[1].Value.ToString() == "GPU")
                                        settings.GpuMiners.RemoveAll(x => x.MinerGUID == Guid.Parse(dgvMiners.SelectedRows[0].Cells[0].Value.ToString()));
                                    else if (dgvMiners.SelectedRows[0].Cells[1].Value.ToString() == "CPU")
                                        settings.CpuMiners.RemoveAll(x => x.MinerGUID == Guid.Parse(dgvMiners.SelectedRows[0].Cells[0].Value.ToString()));
                                    dgvMiners.Rows.Remove(dgvMiners.SelectedRows[0]);
                                    settingsCall.SeriliazeSettings(settings);
                                }
                            }
                        }
                    }
                    else if (pic.Name == picRefreshMiners.Name)
                    {
                        AddMinersToDataGridViews(true);
                        UserMessage.ShowMessage(this, UserMessage.MessageType.Success, "Miner list successfully refreshed!");
                    }
                    else if (pic.Name == picAddMiner.Name)
                    {
                        frmMiner miner = new frmMiner(frmMiner.Type.Add, frmMiner.Miner.GPU);
                        miner.ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                UserMessage.ShowMessage(this, UserMessage.MessageType.Error, "There was an error while trying to manipulate the miners: Error: " + ex.Message);
            }
        }
예제 #2
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            string strError = string.Empty;

            ScheduleTask.CreateNewTask();
            //ScheduleTask.RunTask();

            //Initialize Calls and data
            settingsCall = new SettingCall();
            settings = new Settings();
            devices = new DevicesCall();
            comp = new Computer();
            miner = new MinerCall();

            if (miner.IsMinersRunning())
                if (MessageBox.Show("CUDA Administrator detected that there are CPU or GPU miners already running. Do you want to shutdown these miners now?",
                    "Miners Running", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    miner.ShutdownMiners();

            bool isNewVersion = settingsCall.IsNewVersionAvailable(ref strError);
            if (!string.IsNullOrEmpty(strError))
            {
                UserMessage.ShowMessage(this, UserMessage.MessageType.Error, "There was an error while trying to check for the latest version of CUDA Administrator. Error: " + strError);
                strError = string.Empty;
            }
            else
            {
                if (isNewVersion)
                    if (MessageBox.Show("A new version of CUDA Administrator is available. Would you like to go to the subreddit?", "Verion Check", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        Process.Start("http://www.reddit.com/r/CudaAdministrator");
            }

            this.Icon = settingsCall.GetApplicationIcon();

            comp.Open();
            comp.CPUEnabled = true;

            //Set UI data
            AddMinersToDataGridViews();

            //Setup everything required to run CUDA Admin
            settingsCall.CreateFolders(ref strError);
            if (!string.IsNullOrEmpty(strError))
            {
                MessageBox.Show(strError, "Folder Creation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(Environment.ExitCode);
            }

            if (!File.Exists(FileManager.CudaMinerPath + "cudaminer.exe") || !File.Exists(FileManager.CudaMinerPath + "pthreadVC2.dll") || !(File.Exists(FileManager.CudaMinerPath + "cudart64_55.dll") || File.Exists(FileManager.CudaMinerPath + "cudart32_55.dll")))
                UserMessage.ShowMessage(this, UserMessage.MessageType.Warning, "GPU Miner disabled. Either it or some/all of it's dependencies couldn't be located");
            if (!File.Exists(FileManager.CpuMinerPath + "minerd.exe") || !File.Exists(FileManager.CpuMinerPath + "libwinpthread-1.dll") || !(File.Exists(FileManager.CpuMinerPath + "libcurl.dll") || File.Exists(FileManager.CpuMinerPath + "libcurl-4.dll")))
                UserMessage.ShowMessage(this, UserMessage.MessageType.Warning, "CPU Miner disabled. Either it or some/all of it's dependencies couldn't be located");

            settings = settingsCall.GetSettings(ref strError);
            if (!string.IsNullOrEmpty(strError))
                UserMessage.ShowMessage(this, UserMessage.MessageType.Error, "An error occurred while trying to get the settings data. Error: " + strError);

            string[] args = Environment.GetCommandLineArgs();
            if (args.Contains("--autorun"))
                btnMinerAutomation.PerformClick();
        }