diff --git a/src/bundler.json b/src/bundler.json index e031793..7ceb4a6 100644 --- a/src/bundler.json +++ b/src/bundler.json @@ -1,8 +1,8 @@ { "app_name": "Stellite GUI Miner v1.1.0", "environments": [ - {"arch": "amd64", "os": "darwin"}, {"arch": "amd64", "os": "linux"}, + {"arch": "amd64", "os": "darwin"}, { "arch": "amd64", "os": "windows", diff --git a/src/bundler_dev.json b/src/bundler_dev.json new file mode 100644 index 0000000..b75919a --- /dev/null +++ b/src/bundler_dev.json @@ -0,0 +1,10 @@ +{ + "app_name": "Stellite GUI Miner v1.1.0", + "environments": [ + {"arch": "amd64", "os": "linux"} + ], + "icon_path_darwin": "resources/icon.icns", + "icon_path_linux": "resources/icon.png", + "icon_path_windows": "resources/icon.ico", + "output_path": "../bin" +} diff --git a/src/gui/miner/xmr_stak.go b/src/gui/miner/xmr_stak.go index 1774c7c..6d1b6f5 100644 --- a/src/gui/miner/xmr_stak.go +++ b/src/gui/miner/xmr_stak.go @@ -7,7 +7,9 @@ import ( "net/http" "os" "path/filepath" + "regexp" "runtime" + "strings" ) // XmrStak implements the miner interface for the xmr-stak miner @@ -118,8 +120,10 @@ func (miner *XmrStak) WriteConfig( // TODO: Currently only CPU threads, extend this to full CPU/GPU config func (miner *XmrStak) GetProcessingConfig() ProcessingConfig { return ProcessingConfig{ - MaxUsage: 0, - Threads: uint16(len(miner.resultStatsCache.Hashrate.Threads)), + MaxUsage: 0, + // xmr-stak reports GPU + CPU threads in the same section, for that reason + // we need to check the actual cpu.txt file to get the real thread count + Threads: miner.getCPUThreadcount(), MaxThreads: uint16(runtime.NumCPU()), Type: miner.name, } @@ -135,6 +139,40 @@ func (miner *XmrStak) GetLastHashrate() float64 { return miner.lastHashrate } +// getCPUThreadcount returns the threads used for the CPU as read from the +// config +func (miner *XmrStak) getCPUThreadcount() uint16 { + configPath := filepath.Join(miner.Base.executablePath, "cpu.txt") + configFileBytes, err := ioutil.ReadFile(configPath) + // If config file doesn't exist, return 0 as the threadcount + if err != nil { + return 0 + } + // xmr-stak uses a strange JSON-like format, I haven't found a Go library + // that can parse the file, so we're doing some basic string matches + lines := strings.Split(string(configFileBytes), "\n") + var validLines string + for _, line := range lines { + for _, char := range line { + // This is a very very very basic check if this line is actually a comment + if string(char) == "/" || string(char) == "*" { + // Skip this line + break + } else { + validLines += string(char) + } + } + } + + var threadcount uint16 + // Match anything enclosed in {} for JSON object + var re = regexp.MustCompile(`{*}`) + for _ = range re.FindAllString(validLines, -1) { + threadcount++ + } + return threadcount +} + // GetStats returns the current miner stats func (miner *XmrStak) GetStats() (Stats, error) { var stats Stats diff --git a/src/main.go b/src/main.go index 63f2c31..3e4ed4a 100644 --- a/src/main.go +++ b/src/main.go @@ -36,8 +36,8 @@ func main() { if err != nil { log.Fatalf("Can't read current directory: %s", err) } - // HACK For local development comment out filepath.Dir here + // HACK For local development comment out filepath.Dir here workingDir = filepath.Dir(workingDir) if err != nil { log.Fatalf("Can't format current directory: %s", err)