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

Commit

Permalink
Upgrade to version 1.2.1.0
Browse files Browse the repository at this point in the history
- Added support for another optimized sgminer
- Added logging to file
- Added option to set each group's benchmarking times
- Changed default SwitchMinSecondsFixed to 15 minutes
- Bug fixes & improvements
  • Loading branch information
theLosers106 committed Dec 21, 2015
1 parent f0578f7 commit 1a5b2ce
Show file tree
Hide file tree
Showing 19 changed files with 31,356 additions and 146 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,12 @@ cpuid/cpuid.vcxproj.user
*.idb
NiceHashMiner.sdf
NiceHashMiner.opensdf
Release
Release
packages/log4net.2.0.5/log4net.2.0.5.nupkg
packages/log4net.2.0.5/lib/net10-full
packages/log4net.2.0.5/lib/net11-full
packages/log4net.2.0.5/lib/net35-client
packages/log4net.2.0.5/lib/net35-full
packages/log4net.2.0.5/lib/net40-client
packages/log4net.2.0.5/lib/net40-full
packages/log4net.2.0.5/lib/net45-full
2 changes: 1 addition & 1 deletion NiceHashMiner/Bitcoin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static string GetCoinbaseAPIData(string URL)
}
catch (Exception ex)
{
Helpers.ConsolePrint(ex.Message);
Helpers.ConsolePrint("COINBASE", ex.Message);
return null;
}

Expand Down
22 changes: 18 additions & 4 deletions NiceHashMiner/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ public class Config
public int SwitchMinSecondsDynamic;
public int MinerAPIQueryInterval;
public int MinerRestartDelayMS;
public int[] BenchmarkTimeLimits;
public int[] BenchmarkTimeLimitsCPU;
public int[] BenchmarkTimeLimitsNVIDIA;
public int[] BenchmarkTimeLimitsAMD;
public bool StartMiningWhenIdle;
public int MinIdleSeconds;
public int LogLevel;
public long LogMaxFileSize; // in bytes
public Group[] Groups;
#pragma warning restore 649

Expand All @@ -74,22 +78,32 @@ static Config()
ConfigData.HideMiningWindows = false;
ConfigData.AutoStartMining = false;
ConfigData.StartMiningWhenIdle = false;
ConfigData.LogLevel = 1;
ConfigData.LogMaxFileSize = 1048576;

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

if (ConfigData.SwitchMinSecondsFixed <= 0)
ConfigData.SwitchMinSecondsFixed = 3 * 60;
ConfigData.SwitchMinSecondsFixed = 15 * 60;
if (ConfigData.SwitchMinSecondsDynamic <= 0)
ConfigData.SwitchMinSecondsDynamic = 3 * 60;
if (ConfigData.MinerAPIQueryInterval <= 0)
ConfigData.MinerAPIQueryInterval = 5;
if (ConfigData.MinerRestartDelayMS <= 0)
ConfigData.MinerRestartDelayMS = 200;
if (ConfigData.BenchmarkTimeLimits == null || ConfigData.BenchmarkTimeLimits.Length < 3)
ConfigData.BenchmarkTimeLimits = new int[] { 10, 20, 60 };
if (ConfigData.BenchmarkTimeLimitsCPU == null || ConfigData.BenchmarkTimeLimitsCPU.Length < 3)
ConfigData.BenchmarkTimeLimitsCPU = new int[] { 10, 20, 60 };
if (ConfigData.BenchmarkTimeLimitsNVIDIA == null || ConfigData.BenchmarkTimeLimitsNVIDIA.Length < 3)
ConfigData.BenchmarkTimeLimitsNVIDIA = new int[] { 10, 20, 60 };
if (ConfigData.BenchmarkTimeLimitsAMD == null || ConfigData.BenchmarkTimeLimitsAMD.Length < 3)
ConfigData.BenchmarkTimeLimitsAMD = new int[] { 120, 180, 240 };
if (ConfigData.MinIdleSeconds <= 0)
ConfigData.MinIdleSeconds = 60;
if (ConfigData.LogLevel != 0 || ConfigData.LogLevel != 1)
ConfigData.LogLevel = 1;
if (ConfigData.LogMaxFileSize <= 0)
ConfigData.LogMaxFileSize = 1048576;
}

public static void Commit()
Expand Down
50 changes: 32 additions & 18 deletions NiceHashMiner/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ public Form1(bool ss)
f4.ShowDialog();
}

if (Config.ConfigData.LogLevel > 0)
Logger.ConfigureWithFile();

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

Helpers.ConsolePrint("Starting up");
Helpers.ConsolePrint("NICEHASH", "Starting up");

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

Expand Down Expand Up @@ -93,14 +96,14 @@ private void IdleCheck_Tick(object sender, EventArgs e)
if (MSIdle < (Config.ConfigData.MinIdleSeconds * 1000))
{
button2_Click(null, null);
Helpers.ConsolePrint("resumed from idling");
Helpers.ConsolePrint("NICEHASH", "Resumed from idling");
}
}
else
{
if (BenchmarkForm == null && (MSIdle > (Config.ConfigData.MinIdleSeconds * 1000)))
{
Helpers.ConsolePrint("entering idling state");
Helpers.ConsolePrint("NICEHASH", "Entering idling state");
button1_Click(null, null);
}
}
Expand Down Expand Up @@ -462,7 +465,7 @@ void BalanceCheck_Tick(object sender, EventArgs e)
{
if (VerifyMiningAddress())
{
Helpers.ConsolePrint("NICEHASH: balance get");
Helpers.ConsolePrint("NICEHASH", "Balance get");
double Balance = NiceHashStats.GetBalance(textBox1.Text.Trim(), textBox1.Text.Trim() + "." + textBox2.Text.Trim());
if (Balance > 0)
{
Expand All @@ -475,17 +478,17 @@ void BalanceCheck_Tick(object sender, EventArgs e)

void BitcoinExchangeCheck_Tick(object sender, EventArgs e)
{
Helpers.ConsolePrint("COINBASE: bitcoin rate get");
Helpers.ConsolePrint("COINBASE", "Bitcoin rate get");
double BR = Bitcoin.GetUSDExchangeRate();
if (BR > 0) BitcoinRate = BR;
Helpers.ConsolePrint("Current Bitcoin rate: " + BitcoinRate.ToString("F2", CultureInfo.InvariantCulture));
Helpers.ConsolePrint("COINBASE", "Current Bitcoin rate: " + BitcoinRate.ToString("F2", CultureInfo.InvariantCulture));
}


void SMACheck_Tick(object sender, EventArgs e)
{
string worker = textBox1.Text.Trim() + "." + textBox2.Text.Trim();
Helpers.ConsolePrint("NICEHASH: sma get");
Helpers.ConsolePrint("NICEHASH", "SMA get");
NiceHashSMA[] t = NiceHashStats.GetAlgorithmRates(worker);

for (int i = 0; i < 3; i++)
Expand All @@ -496,7 +499,7 @@ void SMACheck_Tick(object sender, EventArgs e)
break;
}

Helpers.ConsolePrint("NICEHASH: sma get failed .. retrying");
Helpers.ConsolePrint("NICEHASH", "SMA get failed .. retrying");
System.Threading.Thread.Sleep(1000);
t = NiceHashStats.GetAlgorithmRates(worker);
}
Expand All @@ -520,7 +523,7 @@ void SMACheck_Tick(object sender, EventArgs e)

void UpdateCheck_Tick(object sender, EventArgs e)
{
Helpers.ConsolePrint("NICEHASH: version get");
Helpers.ConsolePrint("NICEHASH", "Version get");
string ver = NiceHashStats.GetVersion(textBox1.Text.Trim() + "." + textBox2.Text.Trim());

if (ver == null) return;
Expand All @@ -535,16 +538,27 @@ void UpdateCheck_Tick(object sender, EventArgs e)

void SetEnvironmentVariables()
{
Helpers.ConsolePrint("NICEHASH: setting environment variables");
Helpers.ConsolePrint("NICEHASH", "Setting environment variables");

string[] envName = { "GPU_MAX_ALLOC_PERCENT", "GPU_USE_SYNC_OBJECTS", "GPU_MAX_HEAP_SIZE" };
string[] envValue = { "100", "1", "100" };

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo runSetEnv = new System.Diagnostics.ProcessStartInfo();
runSetEnv.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
runSetEnv.FileName = "cmd.exe";
runSetEnv.Arguments = "/C setx GPU_MAX_ALLOC_PERCENT 100 && " +
"setx GPU_USE_SYNC_OBJECTS 1 && setx GPU_MAX_HEAP_SIZE 100";
process.StartInfo = runSetEnv;
process.Start();
for (int i = 0; i < envName.Length; i++)
{
// Check if all the variables is set
if (Environment.GetEnvironmentVariable(envName[i]) == null)
{
try { Environment.SetEnvironmentVariable(envName[i], envValue[i]); }
catch (Exception e) { Helpers.ConsolePrint("NICEHASH", e.ToString()); }
}

// Check to make sure all the values are set correctly
if (!Environment.GetEnvironmentVariable(envName[i]).Equals(envValue[i]))
{
try { Environment.SetEnvironmentVariable(envName[i], envValue[i]); }
catch (Exception e) { Helpers.ConsolePrint("NICEHASH", e.ToString()); }
}
}
}


Expand Down
27 changes: 21 additions & 6 deletions NiceHashMiner/Form2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public partial class Form2 : Form
private int index;
private bool inBenchmark;

private int Time = Config.ConfigData.BenchmarkTimeLimits[1];
private int Time;
private int TimeIndex = 1;
private Miner CurrentlyBenchmarking;

public Form2(bool autostart)
Expand Down Expand Up @@ -89,14 +90,28 @@ private void InitiateBenchmark()
lvi.SubItems[3].Text = "Please wait...";
inBenchmark = true;
CurrentlyBenchmarking = m;

if (m is cpuminer)
Time = Config.ConfigData.BenchmarkTimeLimitsCPU[TimeIndex];
else if (m is ccminer)
Time = Config.ConfigData.BenchmarkTimeLimitsNVIDIA[TimeIndex];
else
{
Time = Config.ConfigData.BenchmarkTimeLimitsAMD[TimeIndex] / 60;

// add an aditional minute if second is not 0
if (DateTime.Now.Second != 0)
Time += 1;
}

m.BenchmarkStart(i, Time, BenchmarkCompleted, lvi);
}
else
{
// average all cpu benchmarks
if (Form1.Miners[0] is cpuminer)
{
Helpers.ConsolePrint("Calculating average CPU speeds:");
Helpers.ConsolePrint("BENCHMARK", "Calculating average CPU speeds:");

double[] Speeds = new double[Form1.Miners[0].SupportedAlgorithms.Length];
int[] MTaken = new int[Form1.Miners[0].SupportedAlgorithms.Length];
Expand All @@ -118,7 +133,7 @@ private void InitiateBenchmark()
for (int i = 0; i < Speeds.Length; i++)
{
if (MTaken[i] > 0) Speeds[i] /= MTaken[i];
Helpers.ConsolePrint(Form1.Miners[0].SupportedAlgorithms[i].NiceHashName + " average speed: " + Form1.Miners[0].PrintSpeed(Speeds[i]));
Helpers.ConsolePrint("BENCHMARK", Form1.Miners[0].SupportedAlgorithms[i].NiceHashName + " average speed: " + Form1.Miners[0].PrintSpeed(Speeds[i]));

foreach (Miner m in Form1.Miners)
{
Expand Down Expand Up @@ -150,17 +165,17 @@ private void Form2_FormClosing(object sender, FormClosingEventArgs e)

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
Time = Config.ConfigData.BenchmarkTimeLimits[0];
TimeIndex = 0;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
Time = Config.ConfigData.BenchmarkTimeLimits[1];
TimeIndex = 1;
}

private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
Time = Config.ConfigData.BenchmarkTimeLimits[2];
TimeIndex = 2;
}

private void button1_Click(object sender, EventArgs e)
Expand Down
7 changes: 5 additions & 2 deletions NiceHashMiner/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ public static bool InternalCheckIsWow64()
}
}

public static void ConsolePrint(string text)
public static void ConsolePrint(string grp, string text)
{
Console.WriteLine("[" +DateTime.Now.ToLongTimeString() + "] " + text);
Console.WriteLine("[" +DateTime.Now.ToLongTimeString() + "] [" + grp + "] " + text);

if (Config.ConfigData.LogLevel > 0)
Logger.log.Info("[" + grp + "] " + text);
}


Expand Down
52 changes: 52 additions & 0 deletions NiceHashMiner/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using log4net.Repository.Hierarchy;
using log4net.Core;
using log4net.Appender;
using log4net.Layout;

namespace NiceHashMiner
{
public class Logger
{
public static readonly ILog log = LogManager.GetLogger(typeof(Logger));

public static void ConfigureWithFile()
{
Hierarchy h = (Hierarchy)LogManager.GetRepository();

if (Config.ConfigData.LogLevel == 1)
h.Root.Level = Level.Info;
else if (Config.ConfigData.LogLevel == 2)
h.Root.Level = Level.Warn;
else if (Config.ConfigData.LogLevel == 3)
h.Root.Level = Level.Error;

h.Root.AddAppender(CreateFileAppender());
h.Configured = true;
}

public static IAppender CreateFileAppender()
{
RollingFileAppender appender = new RollingFileAppender();
appender.Name = "RollingFileAppender";
appender.File = "log.txt";
appender.AppendToFile = true;
appender.RollingStyle = RollingFileAppender.RollingMode.Size;
appender.MaxSizeRollBackups = 1;
appender.MaxFileSize = Config.ConfigData.LogMaxFileSize;
appender.PreserveLogFileNameExtension = true;

PatternLayout layout = new PatternLayout();
layout.ConversionPattern = "[%date{yyyy-MM-dd HH:mm:ss}] [%level] %message%newline";
layout.ActivateOptions();

appender.Layout = layout;
appender.ActivateOptions();

return appender;
}
}
}
Loading

0 comments on commit 1a5b2ce

Please sign in to comment.