diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-30 22:58:31 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-30 22:58:31 +0800 |
commit | 6b7dfa1fb5279407177fb9fb6574ad9760a4e307 (patch) | |
tree | 7c8aca5aaf4355256bf245543842065073e56771 /ethutil/config.go | |
parent | 2ef3a989298aa8dca7872be07ad0abbc32728cc7 (diff) | |
parent | 17c825f53a2676ffe17fd7731f8f550aebcb56b0 (diff) | |
download | dexon-6b7dfa1fb5279407177fb9fb6574ad9760a4e307.tar dexon-6b7dfa1fb5279407177fb9fb6574ad9760a4e307.tar.gz dexon-6b7dfa1fb5279407177fb9fb6574ad9760a4e307.tar.bz2 dexon-6b7dfa1fb5279407177fb9fb6574ad9760a4e307.tar.lz dexon-6b7dfa1fb5279407177fb9fb6574ad9760a4e307.tar.xz dexon-6b7dfa1fb5279407177fb9fb6574ad9760a4e307.tar.zst dexon-6b7dfa1fb5279407177fb9fb6574ad9760a4e307.zip |
Merge branch 'develop'
Diffstat (limited to 'ethutil/config.go')
-rw-r--r-- | ethutil/config.go | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/ethutil/config.go b/ethutil/config.go index fb270ce72..916b0d186 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -22,26 +22,54 @@ type config struct { Identifier string } +const defaultConf = ` +id = "" +port = 30303 +upnp = true +maxpeer = 10 +rpc = false +rpcport = 8080 +` + var Config *config +func ApplicationFolder(base string) string { + usr, _ := user.Current() + p := path.Join(usr.HomeDir, base) + + if len(base) > 0 { + //Check if the logging directory already exists, create it if not + _, err := os.Stat(p) + if err != nil { + if os.IsNotExist(err) { + log.Printf("Debug logging directory %s doesn't exist, creating it\n", p) + os.Mkdir(p, 0777) + + } + } + + iniFilePath := path.Join(p, "conf.ini") + _, err = os.Stat(iniFilePath) + if err != nil && os.IsNotExist(err) { + file, err := os.Create(iniFilePath) + if err != nil { + fmt.Println(err) + } else { + assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal", "assets") + file.Write([]byte(defaultConf + "\nasset_path = " + assetPath)) + } + } + } + + return p +} + // Read config // // Initialize the global Config variable with default settings func ReadConfig(base string, logTypes LoggerType, id string) *config { if Config == nil { - usr, _ := user.Current() - path := path.Join(usr.HomeDir, base) - - if len(base) > 0 { - //Check if the logging directory already exists, create it if not - _, err := os.Stat(path) - if err != nil { - if os.IsNotExist(err) { - log.Printf("Debug logging directory %s doesn't exist, creating it\n", path) - os.Mkdir(path, 0777) - } - } - } + path := ApplicationFolder(base) Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC11"} Config.Identifier = id |