diff --git a/keyfile/keyfile.go b/keyfile/keyfile.go index 3094cdc1..382fe8f4 100644 --- a/keyfile/keyfile.go +++ b/keyfile/keyfile.go @@ -5,7 +5,7 @@ import ( "crypto/rand" "fmt" "io/ioutil" - "path" + "path/filepath" "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcutil" @@ -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 { diff --git a/miners/lyclminer.go b/miners/lyclminer.go index 1f8a6421..ad0b1364 100644 --- a/miners/lyclminer.go +++ b/miners/lyclminer.go @@ -4,7 +4,7 @@ import ( "bufio" "fmt" "os" - "path" + "path/filepath" "strconv" "strings" @@ -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 @@ -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) @@ -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")} } diff --git a/miners/miners.go b/miners/miners.go index 87eca453..c2d3851a 100644 --- a/miners/miners.go +++ b/miners/miners.go @@ -13,7 +13,6 @@ import ( "path/filepath" "runtime" "strings" - "syscall" "time" "github.com/vertcoin-project/one-click-miner-vnext/logging" @@ -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 { @@ -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) @@ -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) { diff --git a/util/gpus.go b/util/gpus.go index 6380ae8b..85b5ed8c 100644 --- a/util/gpus.go +++ b/util/gpus.go @@ -5,7 +5,6 @@ import ( "regexp" "runtime" "strings" - "syscall" "github.com/vertcoin-project/one-click-miner-vnext/logging" ) @@ -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 { diff --git a/util/miners_linux.go b/util/miners_linux.go new file mode 100644 index 00000000..77e666dd --- /dev/null +++ b/util/miners_linux.go @@ -0,0 +1,11 @@ +// +build !windows + +package util + +import ( + "os/exec" +) + +func PrepareBackgroundCommand(cmd *exec.Cmd) { + +} diff --git a/util/miners_windows.go b/util/miners_windows.go new file mode 100644 index 00000000..f43014d5 --- /dev/null +++ b/util/miners_windows.go @@ -0,0 +1,12 @@ +// +build windows + +package util + +import ( + "os/exec" + "syscall" +) + +func PrepareBackgroundCommand(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true} +} diff --git a/util/util.go b/util/util.go index 6e0da728..750e6194 100644 --- a/util/util.go +++ b/util/util.go @@ -13,7 +13,7 @@ import ( "net/http" "os" "os/exec" - "path" + "path/filepath" "runtime" "strings" "time" @@ -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 "." } @@ -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 @@ -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 diff --git a/wallet/wallet.go b/wallet/wallet.go index f1d13ed9..f981cafb 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -3,7 +3,7 @@ package wallet import ( "encoding/hex" "fmt" - "path" + "path/filepath" "strings" "github.com/btcsuite/btcd/chaincfg/chainhash" @@ -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 }