コード例 #1
0
        public static void InstallMiner(MinerBackend minerBackend, string destinationFolder)
        {
            //support Windows and OS X for now, we'll go for Linux in the future
            if (OSVersionPlatform.GetConcretePlatform() == PlatformID.Unix)
            {
                throw new NotImplementedException();
            }

            string minerUrl = GetMinerDownloadUrl(minerBackend);

            if (!String.IsNullOrEmpty(minerUrl))
            {
                string minerDownloadFile = Path.Combine(Path.GetTempPath(), "miner.zip");
                File.Delete(minerDownloadFile);

                new WebClient().DownloadFile(new Uri(minerUrl), minerDownloadFile);
                try
                {
                    Unzipper.UnzipFileToFolder(minerDownloadFile, destinationFolder);
                }
                finally
                {
                    File.Delete(minerDownloadFile);
                }
            }
        }
コード例 #2
0
ファイル: Installer.cs プロジェクト: hrvojevujcec/MultiMiner
        public static void InstallMiner(MinerBackend minerBackend, string destinationFolder)
        {
            //support Windows and OS X for now, we'll go for Linux in the future
            if (OSVersionPlatform.GetConcretePlatform() == PlatformID.Unix)
                throw new NotImplementedException();

            string minerUrl = GetMinerDownloadUrl(minerBackend);

            if (!String.IsNullOrEmpty(minerUrl))
            {
                string minerDownloadFile = Path.Combine(Path.GetTempPath(), "miner.zip");
                File.Delete(minerDownloadFile);

                new WebClient().DownloadFile(new Uri(minerUrl), minerDownloadFile);
                try
                {
                    //first delete the folder contents. this became necessary with cgminer 3.8.0 because
                    //ck stopped shipping cgminer-nogpu.exe, which would leave an old executable behind
                    //and gum up the works later (running an older exe to find the installed version)
                    DeleteFolderContents(destinationFolder);

                    Unzipper.UnzipFileToFolder(minerDownloadFile, destinationFolder);
                }
                finally
                {
                    File.Delete(minerDownloadFile);
                }
            }
        }
コード例 #3
0
ファイル: Installer.cs プロジェクト: nwfella/MultiMiner
        public static string GetInstalledMinerVersion(MinerBackend minerBackend, string executablePath)
        {
            string version = String.Empty;

            ProcessStartInfo startInfo = new ProcessStartInfo(executablePath, "--version");

            startInfo.UseShellExecute = false;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.CreateNoWindow = true;
            startInfo.RedirectStandardOutput = true;

            startInfo.Arguments = startInfo.Arguments + " --disable-gpu";

            if (minerBackend == MinerBackend.Cgminer)
            {
                //otherwise it still requires OpenCL.dll - not an issue with bfgminer
                if (OSVersionPlatform.GetConcretePlatform() == PlatformID.Unix)
                    startInfo.FileName = startInfo.FileName + "-nogpu";
                else
                    startInfo.FileName = executablePath.Replace("cgminer.exe", "cgminer-nogpu.exe");
            }

            Process process = Process.Start(startInfo);

            string processOutput = process.StandardOutput.ReadToEnd();

            string pattern = String.Format(@"^.+ (.+\..+){0}", Environment.NewLine);
            Match match = Regex.Match(processOutput, pattern);
            if (match.Success)
                version = match.Groups[1].Value;

            return version;
        }
コード例 #4
0
ファイル: MinerPath.cs プロジェクト: Capkeeper/MultiMiner
        public static string GetMinerName(MinerBackend minerBackend)
        {
            string minerName = CgminerName;

            if (minerBackend == MinerBackend.Bfgminer)
                minerName = BfgminerName;

            return minerName;
        }
コード例 #5
0
ファイル: WizardForm.cs プロジェクト: Capkeeper/MultiMiner
        private MinerBackend GetSelectedMinerBackend()
        {
            MinerBackend minerBackend = MinerBackend.Cgminer;

            if (minerComboBox.SelectedIndex == 1)
            {
                minerBackend = MinerBackend.Bfgminer;
            }
            return(minerBackend);
        }
コード例 #6
0
ファイル: MinerPath.cs プロジェクト: Capkeeper/MultiMiner
        public static string GetMinerName(MinerBackend minerBackend)
        {
            string minerName = CgminerName;

            if (minerBackend == MinerBackend.Bfgminer)
            {
                minerName = BfgminerName;
            }

            return(minerName);
        }
コード例 #7
0
ファイル: Installer.cs プロジェクト: Capkeeper/MultiMiner
 public static string GetMinerDownloadRoot(MinerBackend minerBackend)
 {
     if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX)
         return "http://github.com/nwoolls/xgminer-osx";
     else
     {
         if (minerBackend == MinerBackend.Bfgminer)
             return "http://luke.dashjr.org";
         else
             return "http://ck.kolivas.org";
     }
 }
コード例 #8
0
ファイル: Installer.cs プロジェクト: hrvojevujcec/MultiMiner
        public static string GetAvailableMinerVersion(MinerBackend minerBackend)
        {
            string version = String.Empty;

            string minerDownloadUrl = GetMinerDownloadUrl(minerBackend);
            const string pattern = @".+/.+?-(.+?)-.+\..+$";
            Match match = Regex.Match(minerDownloadUrl, pattern);
            if (match.Success)
                version = match.Groups[1].Value;

            return version;
        }
コード例 #9
0
        public static string GetAvailableMinerVersion(MinerBackend minerBackend)
        {
            string version = String.Empty;

            string       minerDownloadUrl = GetMinerDownloadUrl(minerBackend);
            const string pattern          = @".+/.+-(.+)-.+\..+$";
            Match        match            = Regex.Match(minerDownloadUrl, pattern);

            if (match.Success)
            {
                version = match.Groups[1].Value;
            }

            return(version);
        }
コード例 #10
0
        private static string GetMinerDownloadUrl(MinerBackend minerBackend)
        {
            string result = String.Empty;

            if (minerBackend == MinerBackend.Cgminer)
            {
                result = GetCgminerDownloadUrl();
            }
            else if (minerBackend == MinerBackend.Bfgminer)
            {
                result = GetBfgminerDownloadUrl();
            }

            return(result);
        }
コード例 #11
0
ファイル: WizardForm.cs プロジェクト: Capkeeper/MultiMiner
        private void DownloadChosenMiner()
        {
            MinerBackend minerBackend = GetSelectedMinerBackend();

            string minerName         = MinerPath.GetMinerName(minerBackend);
            string minerPath         = Path.Combine("Miners", minerName);
            string destinationFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, minerPath);

            downloadingMinerLabel.Text = String.Format("Please wait while {0} is downloaded from {2} and installed into the folder {1}", minerName, destinationFolder, Installer.GetMinerDownloadRoot(minerBackend));
            Application.DoEvents();

            Cursor = Cursors.WaitCursor;
            Installer.InstallMiner(minerBackend, destinationFolder);
            Cursor = Cursors.Default;

            wizardTabControl.SelectedTab = chooseCoinPage;
        }
コード例 #12
0
ファイル: MinerPath.cs プロジェクト: Capkeeper/MultiMiner
        public static string GetPathToInstalledMiner(MinerBackend minerBackend)
        {
            string executablePath = string.Empty;
            string minerName      = GetMinerName(minerBackend);

            switch (OSVersionPlatform.GetConcretePlatform())
            {
            case PlatformID.MacOSX:
                //try local path first
                executablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format(@"Miners/{0}/bin/{0}", minerName));

                if (!File.Exists(executablePath))
                {
                    //try global path (Homebrew)
                    executablePath = string.Format(@"/usr/local/bin/{0}", minerName);
                }

                break;

            //support Unix - there is no bin folder for the executables like on Mac OS X
            case PlatformID.Unix:
                //try local path first
                executablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format(@"Miners/{0}/{0}", minerName));

                if (!File.Exists(executablePath))
                {
                    //try /usr/local/bin
                    executablePath = string.Format(@"/usr/local/bin/{0}", minerName);
                }

                if (!File.Exists(executablePath))
                {
                    //try /usr/bin
                    executablePath = string.Format(@"/usr/bin/{0}", minerName);
                }

                break;

            default:
                executablePath = string.Format(@"Miners\{0}\{0}.exe", minerName);
                break;
            }

            return(executablePath);
        }
コード例 #13
0
 public static string GetMinerDownloadRoot(MinerBackend minerBackend)
 {
     if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX)
     {
         return("http://github.com/nwoolls/xgminer-osx");
     }
     else
     {
         if (minerBackend == MinerBackend.Bfgminer)
         {
             return("http://luke.dashjr.org");
         }
         else
         {
             return("http://ck.kolivas.org");
         }
     }
 }
コード例 #14
0
ファイル: WizardForm.cs プロジェクト: Capkeeper/MultiMiner
        private void nextButton_Click(object sender, EventArgs e)
        {
            if (!ValidateInput())
            {
                return;
            }

            if (wizardTabControl.SelectedTab == chooseMinerPage)
            {
                MinerBackend minerBackend = GetSelectedMinerBackend();
                if (MinerIsInstalled(minerBackend))
                {
                    wizardTabControl.SelectedIndex += 2;
                }
                else
                {
                    wizardTabControl.SelectedIndex += 1;
                }
            }
            else
            {
                if (wizardTabControl.SelectedIndex < wizardTabControl.TabPages.Count - 1)
                {
                    wizardTabControl.SelectedIndex += 1;
                }
                else
                {
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }


            if (wizardTabControl.SelectedTab == downloadingMinerPage)
            {
                if (OSVersionPlatform.GetConcretePlatform() == PlatformID.Unix)
                {
                    showLinuxInstallationInstructions();
                }
                else
                {
                    DownloadChosenMiner();
                }
            }
        }
コード例 #15
0
ファイル: Installer.cs プロジェクト: hrvojevujcec/MultiMiner
        public static string GetInstalledMinerVersion(MinerBackend minerBackend, string executablePath)
        {
            string version = String.Empty;

            ProcessStartInfo startInfo = new ProcessStartInfo(executablePath, "--version");

            startInfo.UseShellExecute = false;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.CreateNoWindow = true;
            startInfo.RedirectStandardOutput = true;

            startInfo.Arguments = startInfo.Arguments + " --disable-gpu";

            if (minerBackend == MinerBackend.Cgminer)
            {
                string noGpuFilePath;

                //otherwise it still requires OpenCL.dll - not an issue with bfgminer
                if (OSVersionPlatform.GetConcretePlatform() == PlatformID.Unix)
                    noGpuFilePath = startInfo.FileName + "-nogpu";
                else
                    noGpuFilePath = executablePath.Replace("cgminer.exe", "cgminer-nogpu.exe");

                //first make sure the exe exists. this became necessary with cgminer 3.8.0 because
                //ck stopped shipping cgminer-nogpu.exe, as cgminer.exe has no GPU support in 3.8
                if (File.Exists(noGpuFilePath))
                    startInfo.FileName = noGpuFilePath;
            }

            Process process = Process.Start(startInfo);

            string processOutput = process.StandardOutput.ReadToEnd();

            string pattern = String.Format(@"^.+ (.+\..+){0}", Environment.NewLine);
            Match match = Regex.Match(processOutput, pattern);
            if (match.Success)
                version = match.Groups[1].Value;

            return version;
        }
コード例 #16
0
        public static string GetInstalledMinerVersion(MinerBackend minerBackend, string executablePath)
        {
            string version = String.Empty;

            ProcessStartInfo startInfo = new ProcessStartInfo(executablePath, "--version");

            startInfo.UseShellExecute        = false;
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.CreateNoWindow         = true;
            startInfo.RedirectStandardOutput = true;

            startInfo.Arguments = startInfo.Arguments + " --disable-gpu";

            if (minerBackend == MinerBackend.Cgminer)
            {
                //otherwise it still requires OpenCL.dll - not an issue with bfgminer
                if (OSVersionPlatform.GetConcretePlatform() == PlatformID.Unix)
                {
                    startInfo.FileName = startInfo.FileName + "-nogpu";
                }
                else
                {
                    startInfo.FileName = executablePath.Replace("cgminer.exe", "cgminer-nogpu.exe");
                }
            }

            Process process = Process.Start(startInfo);

            string processOutput = process.StandardOutput.ReadToEnd();

            string pattern = String.Format(@"^.+ (.+\..+){0}", Environment.NewLine);
            Match  match   = Regex.Match(processOutput, pattern);

            if (match.Success)
            {
                version = match.Groups[1].Value;
            }

            return(version);
        }
コード例 #17
0
ファイル: MainForm.cs プロジェクト: Capkeeper/MultiMiner
        private static void InstallMiner(MinerBackend minerBackend)
        {
            string minerName = MinerPath.GetMinerName(minerBackend);

            ProgressForm progressForm = new ProgressForm("Downloading and installing " + minerName + " from " + Installer.GetMinerDownloadRoot(minerBackend));
            progressForm.Show();

            //for Mono - show the UI
            Application.DoEvents();
            Thread.Sleep(25);
            Application.DoEvents();
            try
            {
                string minerPath = Path.Combine("Miners", minerName);
                string destinationFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, minerPath);
                Xgminer.Installer.InstallMiner(minerBackend, destinationFolder);
            }
            finally
            {
                progressForm.Close();
            }
        }
コード例 #18
0
ファイル: MinerPath.cs プロジェクト: Capkeeper/MultiMiner
        public static string GetPathToInstalledMiner(MinerBackend minerBackend)
        {
            string executablePath = string.Empty;
            string minerName = GetMinerName(minerBackend);

            switch (OSVersionPlatform.GetConcretePlatform())
            {
                case PlatformID.MacOSX:
                    //try local path first
                    executablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format(@"Miners/{0}/bin/{0}", minerName));

                    if (!File.Exists(executablePath))
                        //try global path (Homebrew)
                        executablePath = string.Format(@"/usr/local/bin/{0}", minerName);

                    break;

                //support Unix - there is no bin folder for the executables like on Mac OS X
                case PlatformID.Unix:
                    //try local path first
                    executablePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format(@"Miners/{0}/{0}", minerName));

                    if (!File.Exists(executablePath))
                        //try /usr/local/bin
                        executablePath = string.Format(@"/usr/local/bin/{0}", minerName);

                    if (!File.Exists(executablePath))
                        //try /usr/bin
                        executablePath = string.Format(@"/usr/bin/{0}", minerName);

                    break;

                default:
                    executablePath = string.Format(@"Miners\{0}\{0}.exe", minerName);
                    break;
            }

            return executablePath;
        }
コード例 #19
0
ファイル: Installer.cs プロジェクト: Capkeeper/MultiMiner
        public static void InstallMiner(MinerBackend minerBackend, string destinationFolder)
        {
            //support Windows and OS X for now, we'll go for Linux in the future
            if (OSVersionPlatform.GetConcretePlatform() == PlatformID.Unix)
                throw new NotImplementedException();

            string minerUrl = GetMinerDownloadUrl(minerBackend);

            if (!String.IsNullOrEmpty(minerUrl))
            {
                string minerDownloadFile = Path.Combine(Path.GetTempPath(), "miner.zip");
                File.Delete(minerDownloadFile);

                new WebClient().DownloadFile(new Uri(minerUrl), minerDownloadFile);
                try
                {
                    UnzipFileToFolder(minerDownloadFile, destinationFolder);
                }
                finally
                {
                    File.Delete(minerDownloadFile);
                }
            }
        }
コード例 #20
0
ファイル: WizardForm.cs プロジェクト: Capkeeper/MultiMiner
        private static bool MinerIsInstalled(MinerBackend minerBackend)
        {
            string path = MinerPath.GetPathToInstalledMiner(minerBackend);

            return(File.Exists(path));
        }
コード例 #21
0
ファイル: MainForm.cs プロジェクト: hrvojevujcec/MultiMiner
 private void TryToCheckForMinerUpdates(MinerBackend minerBackend)
 {
     try
     {
         CheckForMinerUpdates(minerBackend);
     }
     catch (ArgumentException ex)
     {
         string error = String.Format("Error checking for {0} updates", minerBackend.ToString().ToLower());
         notificationsControl.AddNotification(error, error, () =>
         {
         }, "");
     }
 }
コード例 #22
0
ファイル: MainForm.cs プロジェクト: hrvojevujcec/MultiMiner
        private void CheckForMinerUpdates(MinerBackend minerBackend)
        {
            string minerName = MinerPath.GetMinerName(minerBackend);

            if (MinerIsInstalled(minerBackend))
            {
                string availableMinerVersion = String.Empty;
                try
                {
                    availableMinerVersion = Xgminer.Installer.GetAvailableMinerVersion(minerBackend);
                }
                catch (WebException ex)
                {
                    //downloads website is down
                    return;
                }

                string installedMinerVersion = Xgminer.Installer.GetInstalledMinerVersion(minerBackend, MinerPath.GetPathToInstalledMiner(minerBackend));
                if (ThisVersionGreater(availableMinerVersion, installedMinerVersion))
                {
                    int notificationId = minerBackend == MinerBackend.Bfgminer ? bfgminerNotificationId : cgminerNotificationId;

                    string informationUrl = "https://github.com/ckolivas/cgminer/blob/master/NEWS";
                    if (minerBackend == MinerBackend.Bfgminer)
                        informationUrl = "https://github.com/luke-jr/bfgminer/blob/bfgminer/NEWS";

                    notificationsControl.AddNotification(notificationId.ToString(),
                        String.Format("{0} version {1} is available ({2} installed)",
                            minerName, availableMinerVersion, installedMinerVersion), () =>
                        {
                            bool wasMining = miningEngine.Mining;

                            //only stop mining if this is the engine being used
                            if (wasMining && (engineConfiguration.XgminerConfiguration.MinerBackend == minerBackend))
                                StopMining();

                            InstallMiner(minerBackend);

                            //only start mining if we stopped mining
                            if (wasMining && (engineConfiguration.XgminerConfiguration.MinerBackend == minerBackend))
                                StartMining();
                        }, informationUrl);
                }
            }
        }
コード例 #23
0
        static void Main(string[] args)
        {
            //examples of using MultiMiner.Xgminer.dll and MultiMiner.Xgminer.Api.dll

            //download and install the latest version of bfgminer
            const string executablePath = @"D:\bfgminer\";
            const string executableName = "bfgminer.exe";
            MinerBackend minerBackend   = MinerBackend.Bfgminer;

            Console.WriteLine("Downloading and installing {0} from {1} to the directory {2}",
                              executableName, Xgminer.Installer.GetMinerDownloadRoot(minerBackend), executablePath);

            //download and install bfgminer from the official website
            Xgminer.Installer.InstallMiner(minerBackend, executablePath);
            try
            {
                //create an instance of Miner with the downloaded executable
                MinerConfiguration minerConfiguration = new MinerConfiguration()
                {
                    MinerBackend   = minerBackend,
                    ExecutablePath = Path.Combine(executablePath, executableName)
                };
                Miner miner = new Miner(minerConfiguration);

                //use it to iterate through devices
                List <Device> deviceList = miner.DeviceList();

                Console.WriteLine("Using {0} to list available mining devices", executableName);

                //output devices
                foreach (Device device in deviceList)
                {
                    Console.WriteLine("Device detected: {0}\t{1}\t{2}", device.Kind, device.Driver, device.Identifier);
                }

                //start mining if there are devices
                if (deviceList.Count > 0)
                {
                    Console.WriteLine("{0} device(s) detected, mining Bitcoin on Bitminter using all devices", deviceList.Count);

                    //setup a pool
                    MiningPool pool = new MiningPool()
                    {
                        Host     = "mint.bitminter.com",
                        Port     = 3333,
                        Username = "******",
                        Password = "******"
                    };
                    minerConfiguration.Pools.Add(pool);

                    //specify algorithm
                    minerConfiguration.Algorithm = CoinAlgorithm.SHA256;

                    //disable GPU mining
                    minerConfiguration.DisableGpu = true;

                    //specify device indexes to use
                    for (int i = 0; i < deviceList.Count; i++)
                    {
                        minerConfiguration.DeviceIndexes.Add(i);
                    }

                    //enable RPC API
                    minerConfiguration.ApiListen = true;
                    minerConfiguration.ApiPort   = 4028;

                    Console.WriteLine("Launching {0}", executableName);

                    //start mining
                    miner = new Miner(minerConfiguration);
                    System.Diagnostics.Process minerProcess = miner.Launch();
                    try
                    {
                        //get an API context
                        Xgminer.Api.ApiContext apiContext = new Xgminer.Api.ApiContext(minerConfiguration.ApiPort);
                        try
                        {
                            //mine for one minute, monitoring hashrate via the API
                            for (int i = 0; i < 6; i++)
                            {
                                Thread.Sleep(1000 * 10); //sleep 10s

                                //query the miner process via its RPC API for device information
                                List <Xgminer.Api.DeviceInformation> deviceInformation = apiContext.GetDeviceInformation();

                                //output device information
                                foreach (Xgminer.Api.DeviceInformation item in deviceInformation)
                                {
                                    Console.WriteLine("Hasrate for device {0}: {1} current, {2} average", item.Index,
                                                      item.CurrentHashrate, item.AverageHashrate);
                                }
                            }
                        }
                        finally
                        {
                            Console.WriteLine("Quitting mining via the RPC API");

                            //stop mining, try the API first
                            apiContext.QuitMining();
                        }
                    }
                    finally
                    {
                        Console.WriteLine("Killing any remaining process");

                        //then kill the process
                        try
                        {
                            minerProcess.Kill();
                            minerProcess.WaitForExit();
                            minerProcess.Close();
                        }
                        catch (InvalidOperationException ex)
                        {
                            //already closed
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No devices capable of mining detected");
                }
            }
            finally
            {
                Console.WriteLine("Cleaning up, deleting directory {0}", executablePath);
                Directory.Delete(executablePath, true);
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
コード例 #24
0
ファイル: Installer.cs プロジェクト: Capkeeper/MultiMiner
        private static string GetMinerDownloadUrl(MinerBackend minerBackend)
        {
            string result = String.Empty;

            if (minerBackend == MinerBackend.Cgminer)
                result = GetCgminerDownloadUrl();
            else if (minerBackend == MinerBackend.Bfgminer)
                result = GetBfgminerDownloadUrl();

            return result;
        }
コード例 #25
0
ファイル: WizardForm.cs プロジェクト: nwfella/MultiMiner
 private static bool MinerIsInstalled(MinerBackend minerBackend)
 {
     string path = MinerPath.GetPathToInstalledMiner(minerBackend);
     return File.Exists(path);
 }