Skip to content

Commit

Permalink
Fixes for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjaap committed Jul 2, 2019
1 parent 9799939 commit a2854dc
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 26 deletions.
4 changes: 2 additions & 2 deletions keyfile/keyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/rand"
"fmt"
"io/ioutil"
"path"
"path/filepath"

"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcutil"
Expand Down Expand Up @@ -52,7 +52,7 @@ func CreateKeyFile(pass string) error {
}

func keyFile() string {
return path.Join(util.DataDirectory(), "keyfile.hex")
return filepath.Join(util.DataDirectory(), "keyfile.hex")
}

func loadPublicKey() []byte {
Expand Down
14 changes: 7 additions & 7 deletions miners/lyclminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bufio"
"fmt"
"os"
"path"
"path/filepath"
"strconv"
"strings"

Expand All @@ -25,8 +25,8 @@ func NewLyclMinerImpl(br *BinaryRunner) MinerImpl {
}

func (l *LyclMinerImpl) Configure(args BinaryArguments) error {
os.Remove(path.Join(util.DataDirectory(), "lyclMiner_tmpl.conf"))
err := l.binaryRunner.launch([]string{"-g", path.Join(util.DataDirectory(), "lyclMiner_tmpl.conf")})
os.Remove(filepath.Join(util.DataDirectory(), "lyclMiner_tmpl.conf"))
err := l.binaryRunner.launch([]string{"-g", filepath.Join(util.DataDirectory(), "lyclMiner_tmpl.conf")})
err2 := l.binaryRunner.wait()
if err != nil {
return err
Expand All @@ -35,15 +35,15 @@ func (l *LyclMinerImpl) Configure(args BinaryArguments) error {
return err2
}

in, err := os.Open(path.Join(util.DataDirectory(), "lyclMiner_tmpl.conf"))
in, err := os.Open(filepath.Join(util.DataDirectory(), "lyclMiner_tmpl.conf"))
if err != nil {
logging.Error(err)
return err
}
defer in.Close()

os.Remove(path.Join(util.DataDirectory(), "lyclMiner.conf"))
out, err := os.Create(path.Join(util.DataDirectory(), "lyclMiner.conf"))
os.Remove(filepath.Join(util.DataDirectory(), "lyclMiner.conf"))
out, err := os.Create(filepath.Join(util.DataDirectory(), "lyclMiner.conf"))
defer out.Close()

scanner := bufio.NewScanner(in)
Expand Down Expand Up @@ -88,5 +88,5 @@ func (l *LyclMinerImpl) HashRate() uint64 {
}

func (l *LyclMinerImpl) ConstructCommandlineArgs(args BinaryArguments) []string {
return []string{path.Join(util.DataDirectory(), "lyclMiner.conf")}
return []string{filepath.Join(util.DataDirectory(), "lyclMiner.conf")}
}
9 changes: 4 additions & 5 deletions miners/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"path/filepath"
"runtime"
"strings"
"syscall"
"time"

"github.com/vertcoin-project/one-click-miner-vnext/logging"
Expand Down Expand Up @@ -152,11 +151,11 @@ func (b *BinaryRunner) Start(args BinaryArguments) error {
}

func (b *BinaryRunner) unpackDir() string {
return path.Join(util.DataDirectory(), "miners", fmt.Sprintf("unpacked-%s", b.MinerBinary.Hash))
return filepath.Join(util.DataDirectory(), "miners", fmt.Sprintf("unpacked-%s", b.MinerBinary.Hash))
}

func (b *BinaryRunner) downloadPath() string {
return path.Join(util.DataDirectory(), "miners", b.MinerBinary.Hash)
return filepath.Join(util.DataDirectory(), "miners", b.MinerBinary.Hash)
}

func (b *BinaryRunner) launch(params []string) error {
Expand All @@ -167,7 +166,7 @@ func (b *BinaryRunner) launch(params []string) error {
logging.Debugf("Launching %s %v\n", exePath, params)
b.cmd = exec.Command(exePath, params...)
b.cmd.Dir = path.Dir(exePath)
b.cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
util.PrepareBackgroundCommand(b.cmd)
r, w := io.Pipe()
go func(b *BinaryRunner, rd io.Reader) {
br := bufio.NewReader(rd)
Expand Down Expand Up @@ -235,7 +234,7 @@ func (b *BinaryRunner) findExecutable() string {

func (b *BinaryRunner) ensureAvailable() error {
freshDownload := false
_ = os.Mkdir(path.Join(util.DataDirectory(), "miners"), 0700)
_ = os.Mkdir(filepath.Join(util.DataDirectory(), "miners"), 0700)
nodePath := b.downloadPath()
_, err := os.Stat(nodePath)
if os.IsNotExist(err) {
Expand Down
3 changes: 1 addition & 2 deletions util/gpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"regexp"
"runtime"
"strings"
"syscall"

"github.com/vertcoin-project/one-click-miner-vnext/logging"
)
Expand Down Expand Up @@ -71,7 +70,7 @@ func GetGPUs() []GPU {
gpus := []string{}
if runtime.GOOS == "windows" {
info := exec.Command("cmd", "/C", "wmic path win32_VideoController get name")
info.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
PrepareBackgroundCommand(info)
history, _ := info.Output()
possibleGpus := strings.Split(string(history), "\n")
for _, g := range possibleGpus {
Expand Down
11 changes: 11 additions & 0 deletions util/miners_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !windows

package util

import (
"os/exec"
)

func PrepareBackgroundCommand(cmd *exec.Cmd) {

}
12 changes: 12 additions & 0 deletions util/miners_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build windows

package util

import (
"os/exec"
"syscall"
)

func PrepareBackgroundCommand(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
}
16 changes: 8 additions & 8 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"time"
Expand All @@ -26,11 +26,11 @@ const APP_NAME string = "vertcoin-ocm"

func DataDirectory() string {
if runtime.GOOS == "windows" {
return path.Join(os.Getenv("APPDATA"), APP_NAME)
return filepath.Join(os.Getenv("APPDATA"), APP_NAME)
} else if runtime.GOOS == "darwin" {
return path.Join(os.Getenv("HOME"), "Library", "Application Support", APP_NAME)
return filepath.Join(os.Getenv("HOME"), "Library", "Application Support", APP_NAME)
} else if runtime.GOOS == "linux" {
return path.Join(os.Getenv("HOME"), fmt.Sprintf(".%s", strings.ToLower(APP_NAME)))
return filepath.Join(os.Getenv("HOME"), fmt.Sprintf(".%s", strings.ToLower(APP_NAME)))
}
return "."
}
Expand Down Expand Up @@ -115,8 +115,8 @@ func UnpackZip(archive, unpackPath string) error {
defer r.Close()

for _, f := range r.File {
targetPath := path.Join(unpackPath, f.Name)
os.MkdirAll(path.Dir(targetPath), 0700)
targetPath := filepath.Join(unpackPath, f.Name)
os.MkdirAll(filepath.Dir(targetPath), 0700)
outFile, err := os.OpenFile(targetPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
return err
Expand Down Expand Up @@ -170,8 +170,8 @@ func UnpackTar(archive, unpackPath string) error {
case tar.TypeDir:
continue
case tar.TypeReg:
targetPath := path.Join(unpackPath, name)
os.MkdirAll(path.Dir(targetPath), 0700)
targetPath := filepath.Join(unpackPath, name)
os.MkdirAll(filepath.Dir(targetPath), 0700)
outFile, err := os.OpenFile(targetPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0700)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package wallet
import (
"encoding/hex"
"fmt"
"path"
"path/filepath"
"strings"

"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand Down Expand Up @@ -45,7 +45,7 @@ type Tx struct {

func NewWallet(addr string) (*Wallet, error) {
logging.Infof("Initializing wallet %s", addr)
db, err := buntdb.Open(path.Join(util.DataDirectory(), "wallet.db"))
db, err := buntdb.Open(filepath.Join(util.DataDirectory(), "wallet.db"))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a2854dc

Please sign in to comment.