Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Initial working version - beta
Browse files Browse the repository at this point in the history
  • Loading branch information
nicehashdev committed Oct 19, 2015
1 parent 46ef7de commit 1defcdb
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 91 deletions.
1 change: 1 addition & 0 deletions NiceHashMiner.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NiceHashMiner", "NiceHashMiner\NiceHashMiner.csproj", "{A70B0AEE-15C4-49E1-9DC9-B936A1EBC2B5}"
ProjectSection(ProjectDependencies) = postProject
{23C94F99-F466-4CBE-90B7-71B450DD7BF1} = {23C94F99-F466-4CBE-90B7-71B450DD7BF1}
{CC9B70AB-897D-4AE9-8785-33CEB199E2E6} = {CC9B70AB-897D-4AE9-8785-33CEB199E2E6}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpuid", "cpuid\cpuid.vcxproj", "{23C94F99-F466-4CBE-90B7-71B450DD7BF1}"
Expand Down
42 changes: 40 additions & 2 deletions NiceHashMiner/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@

namespace NiceHashMiner
{
class Config
public class Group
{
#pragma warning disable 649
public string Name; // only used for easier manual identification in config file
public int[] DisabledDevices;
public double[] BenchmarkSpeeds;
#pragma warning restore 649
}

public class Config
{
#pragma warning disable 649
public bool DebugConsole;
public string BitcoinAddress;
public string WorkerName;
public int Location;
public int LessThreads;
public Group[] Groups;
#pragma warning restore 649

public static Config ConfigData;
Expand All @@ -23,16 +35,42 @@ static Config()
ConfigData.BitcoinAddress = "1PJ5HWjAniHPMuvfu89L6D2CmnL1De1syn";
ConfigData.WorkerName = "worker1";
ConfigData.Location = 0;
ConfigData.LessThreads = 0;
ConfigData.Groups = new Group[0];
ConfigData.DebugConsole = false;

try { ConfigData = JsonConvert.DeserializeObject<Config>(File.ReadAllText("config.json")); }
catch { }
}

public static void Commit()
{
try { File.WriteAllText("config.json", JsonConvert.SerializeObject(ConfigData)); }
try { File.WriteAllText("config.json", JsonConvert.SerializeObject(ConfigData, Formatting.Indented)); }
catch { }
}

public static void RebuildGroups()
{
// rebuild config groups
Group[] CG = new Group[Form1.Miners.Length];
for (int i = 0; i < Form1.Miners.Length; i++)
{
CG[i] = new Group();
CG[i].Name = Form1.Miners[i].MinerDeviceName;
CG[i].BenchmarkSpeeds = new double[Form1.Miners[i].SupportedAlgorithms.Length];
for (int k = 0; k < Form1.Miners[i].SupportedAlgorithms.Length; k++)
CG[i].BenchmarkSpeeds[k] = Form1.Miners[i].SupportedAlgorithms[k].BenchmarkSpeed;
List<int> DD = new List<int>();
for (int k = 0; k < Form1.Miners[i].CDevs.Count; k++)
{
if (!Form1.Miners[i].CDevs[k].Enabled)
DD.Add(k);
}
CG[i].DisabledDevices = DD.ToArray();
}
ConfigData.Groups = CG;
Config.Commit();
}
}

}
8 changes: 8 additions & 0 deletions NiceHashMiner/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 83 additions & 42 deletions NiceHashMiner/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,89 @@ public partial class Form1 : Form
private int CurrentNVIDIAAlgo = -1;
private int CurrentAMDAlgo = -1;

private Random R = new Random((int)DateTime.Now.Ticks);
private Random R;


public Form1()
{
InitializeComponent();

if (Config.ConfigData.DebugConsole)
Helpers.AllocConsole();

Helpers.ConsolePrint("Starting up");

R = new Random((int)DateTime.Now.Ticks);

Text += " v" + Application.ProductVersion;

comboBox1.SelectedIndex = Config.ConfigData.Location;
textBox1.Text = Config.ConfigData.BitcoinAddress;
textBox2.Text = Config.ConfigData.WorkerName;

if (!Helpers.InternalCheckIsWow64())
{
MessageBox.Show("NiceHash Miner works only on 64 bit version of OS!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
return;
}

// get all CPUs
int CPUs = CPUID.GetPhysicalProcessorCount();

Miners = new Miner[CPUs]; // todo: add cc and sgminer

// get all cores (including virtual - HT can benefit mining)
int ThreadsPerCPU = CPUID.GetVirtualCoresCount() / CPUs;

if (!Helpers.InternalCheckIsWow64())
{
MessageBox.Show("NiceHash Miner works only on 64 bit version of OS for CPU mining. CPU mining will be disabled.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
CPUs = 0;
}

if (ThreadsPerCPU * CPUs > 64)
{
MessageBox.Show("NiceHash Miner does not support more than 64 virtual cores!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show("NiceHash Miner does not support more than 64 virtual cores. CPU mining will be disabled.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
CPUs = 0;
}

int ThreadsPerCPUMask = ThreadsPerCPU;
ThreadsPerCPU -= Config.ConfigData.LessThreads;
if (ThreadsPerCPU < 1)
{
MessageBox.Show("LessThreads greater than number of threads per CPU. CPU mining will be disabled.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
CPUs = 0;
}

Miners = new Miner[CPUs]; // todo: add cc and sgminer

if (CPUs == 1)
Miners[0] = new cpuminer(0, ThreadsPerCPU, 0);
else
{
if (CPUs == 1)
Miners[0] = new cpuminer(0, ThreadsPerCPU, 0);
else
{
for (int i = 0; i < CPUs; i++)
Miners[i] = new cpuminer(i, ThreadsPerCPU, CPUID.CreateAffinityMask(i, ThreadsPerCPU));
}
for (int i = 0; i < CPUs; i++)
Miners[i] = new cpuminer(i, ThreadsPerCPU, CPUID.CreateAffinityMask(i, ThreadsPerCPUMask));
}

foreach (Miner m in Miners)
// todo: initialize ccminer

// todo: initialize sgminer

for (int i = 0; i < Miners.Length; i++)
{
foreach (ComputeDevice D in m.CDevs)
if (Config.ConfigData.Groups.Length > i)
{
for (int z = 0; z < Config.ConfigData.Groups[i].BenchmarkSpeeds.Length && z < Miners[i].SupportedAlgorithms.Length; z++)
{
Miners[i].SupportedAlgorithms[z].BenchmarkSpeed = Config.ConfigData.Groups[i].BenchmarkSpeeds[z];
}
}
for (int k = 0; k < Miners[i].CDevs.Count; k++)
{
ComputeDevice D = Miners[i].CDevs[k];
if (Config.ConfigData.Groups.Length > i)
{
for (int z = 0; z < Config.ConfigData.Groups[i].DisabledDevices.Length; z++)
{
if (Config.ConfigData.Groups[i].DisabledDevices[z] == k)
{
D.Enabled = false;
break;
}
}
}
ListViewItem lvi = new ListViewItem();
lvi.SubItems.Add(D.Vendor);
lvi.SubItems.Add(D.Name);
Expand All @@ -88,10 +126,11 @@ public Form1()
}
}

Config.RebuildGroups();

MinerStatsCheck = new Timer();
MinerStatsCheck.Tick += MinerStatsCheck_Tick;
MinerStatsCheck.Interval = 5000; // every 5 seconds
MinerStatsCheck.Start();

UpdateCheck = new Timer();
UpdateCheck.Tick += UpdateCheck_Tick;
Expand Down Expand Up @@ -133,7 +172,7 @@ void SMACPUCheck_Tick(object sender, EventArgs e)
Miners[0].SupportedAlgorithms[i].CurrentProfit = Miners[0].SupportedAlgorithms[i].BenchmarkSpeed *
NiceHashData[Miners[0].SupportedAlgorithms[i].NiceHashID].paying * 0.000000001;

Debug.Print("CPU " + NiceHashData[Miners[0].SupportedAlgorithms[i].NiceHashID].name + " paying " + Miners[0].SupportedAlgorithms[i].CurrentProfit.ToString("F8") + " BTC/Day");
Helpers.ConsolePrint("CPU " + NiceHashData[Miners[0].SupportedAlgorithms[i].NiceHashID].name + " paying " + Miners[0].SupportedAlgorithms[i].CurrentProfit.ToString("F8") + " BTC/Day");

if (Miners[0].SupportedAlgorithms[i].CurrentProfit > MaxProfit)
{
Expand Down Expand Up @@ -172,27 +211,30 @@ void SMACPUCheck_Tick(object sender, EventArgs e)
void BalanceCheck_Tick(object sender, EventArgs e)
{
if (!VerifyMiningAddress()) return;
Helpers.ConsolePrint("NICEHASH: balance get");
double Balance = NiceHashStats.GetBalance(textBox1.Text.Trim());
toolStripStatusLabel6.Text = Balance.ToString("F8");
if (Balance > 0) toolStripStatusLabel6.Text = Balance.ToString("F8");
}


void SMACheck_Tick(object sender, EventArgs e)
{
NiceHashData = NiceHashStats.GetAlgorithmRates();
Helpers.ConsolePrint("NICEHASH: sma get");
NiceHashSMA[] t = NiceHashStats.GetAlgorithmRates();
if (t != null) NiceHashData = t;
}


void UpdateCheck_Tick(object sender, EventArgs e)
{
Helpers.ConsolePrint("NICEHASH: version get");
string ver = NiceHashStats.GetVersion();
if (ver == null) return;

if (ver != Application.ProductVersion)
{
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;
UpdateCheck.Stop();
}
}

Expand All @@ -206,7 +248,12 @@ private void MinerStatsCheck_Tick(object sender, EventArgs e)
foreach (Miner m in Miners)
{
APIData AD = m.GetSummary();
if (AD == null) continue;
if (AD == null)
{
// API is inaccessible, try to restart miner
m.Restart();
continue;
}

if (m is cpuminer)
{
Expand Down Expand Up @@ -246,7 +293,10 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
int location = comboBox1.SelectedIndex;
if (location > 1) location = 1;

System.Diagnostics.Process.Start("http://www.nicehash.com/index.jsp?p=miners&addr=" + textBox1.Text.Trim());
int algo = 0;
if (CurrentCPUAlgo >= 0) algo = Miners[0].SupportedAlgorithms[CurrentCPUAlgo].NiceHashID;

System.Diagnostics.Process.Start("http://www.nicehash.com/index.jsp?p=miners&addr=" + textBox1.Text.Trim() + "&l=" + location + "&a=" + algo);
}


Expand Down Expand Up @@ -281,11 +331,13 @@ private void button1_Click(object sender, EventArgs e)

SMACPUCheck.Start();
SMACPUCheck_Tick(null, null);
MinerStatsCheck.Start();
}


private void button2_Click(object sender, EventArgs e)
{
MinerStatsCheck.Stop();
SMACPUCheck.Stop();

foreach (Miner m in Miners)
Expand All @@ -299,38 +351,27 @@ private void button2_Click(object sender, EventArgs e)
}


//delegate void ResetButtonTextCallback();

//private void ResetButtonText()
//{
// if (this.button1.InvokeRequired)
// {
// ResetButtonTextCallback d = new ResetButtonTextCallback(ResetButtonText);
// this.Invoke(d, new object[] { });
// }
// else
// {
// this.button1.Text = "Start";
// }
//}

private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(VisitURL);
}


private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
ComputeDevice G = e.Item.Tag as ComputeDevice;
G.Enabled = e.Item.Checked;
Config.RebuildGroups();
}


private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
foreach (Miner m in Miners)
m.Stop();
}


private void button3_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(false);
Expand Down
Loading

0 comments on commit 1defcdb

Please sign in to comment.