Skip to content

Commit

Permalink
Write default configuration file if one is not found. (OpenDiablo2#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
eezstreet authored Feb 8, 2020
1 parent 554a276 commit 99e6acf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions d2core/d2config/d2config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"path"
"path/filepath"
)

var (
Expand Down Expand Up @@ -53,6 +54,17 @@ func Initialize() error {
singleton = &config
return nil
}
} else {
log.Printf("configuration file not found, writing default")
os.MkdirAll(filepath.Dir(configPath), os.ModePerm)
configFile, err := os.Create(configPath)
if err == nil {
encoder := json.NewEncoder(configFile)
defer configFile.Close()
encoder.Encode(getDefaultConfiguration())
} else {
log.Printf("failed to write default configuration (%s)", err)
}
}

singleton = getDefaultConfiguration()
Expand Down

0 comments on commit 99e6acf

Please sign in to comment.