diff --git a/d2core/d2config/d2config.go b/d2core/d2config/d2config.go index 76b52f431..15fdbadf8 100644 --- a/d2core/d2config/d2config.go +++ b/d2core/d2config/d2config.go @@ -6,6 +6,7 @@ import ( "log" "os" "path" + "path/filepath" ) var ( @@ -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()