Use btcutil.AppDataDir for data dir.
This commit is contained in:
parent
503f591e88
commit
1ddd9c38dc
1 changed files with 5 additions and 20 deletions
25
config.go
25
config.go
|
@ -18,6 +18,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/conformal/btcutil"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
"github.com/conformal/go-flags"
|
"github.com/conformal/go-flags"
|
||||||
"os"
|
"os"
|
||||||
|
@ -27,13 +28,15 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultConfigFilename = "btcwallet.conf"
|
defaultConfigFilename = "btcwallet.conf"
|
||||||
|
defaultDataDirname = "data"
|
||||||
defaultBtcNet = btcwire.TestNet3
|
defaultBtcNet = btcwire.TestNet3
|
||||||
defaultLogLevel = "info"
|
defaultLogLevel = "info"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultConfigFile = filepath.Join(btcwalletHomeDir(), defaultConfigFilename)
|
btcwalletHomeDir = btcutil.AppDataDir("btcwallet", false)
|
||||||
defaultDataDir = btcwalletHomeDir()
|
defaultConfigFile = filepath.Join(btcwalletHomeDir, defaultConfigFilename)
|
||||||
|
defaultDataDir = btcwalletHomeDir
|
||||||
)
|
)
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
|
@ -48,24 +51,6 @@ type config struct {
|
||||||
MainNet bool `long:"mainnet" description:"*DISABLED* Use the main Bitcoin network (default testnet3)"`
|
MainNet bool `long:"mainnet" description:"*DISABLED* Use the main Bitcoin network (default testnet3)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// btcwalletHomeDir returns an OS appropriate home directory for btcwallet.
|
|
||||||
func btcwalletHomeDir() string {
|
|
||||||
// Search for Windows APPDATA first. This won't exist on POSIX OSes.
|
|
||||||
appData := os.Getenv("APPDATA")
|
|
||||||
if appData != "" {
|
|
||||||
return filepath.Join(appData, "btcwallet")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back to standard HOME directory that works for most POSIX OSes.
|
|
||||||
home := os.Getenv("HOME")
|
|
||||||
if home != "" {
|
|
||||||
return filepath.Join(home, ".btcwallet")
|
|
||||||
}
|
|
||||||
|
|
||||||
// In the worst case, use the current directory.
|
|
||||||
return "."
|
|
||||||
}
|
|
||||||
|
|
||||||
// updateConfigWithActiveParams update the passed config with parameters
|
// updateConfigWithActiveParams update the passed config with parameters
|
||||||
// from the active net params if the relevant options in the passed config
|
// from the active net params if the relevant options in the passed config
|
||||||
// object are the default so options specified by the user on the command line
|
// object are the default so options specified by the user on the command line
|
||||||
|
|
Loading…
Reference in a new issue