1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-09 09:20:44 +00:00

Write default configuration file if one is not found. (#298)

This commit is contained in:
Nick 2020-02-07 22:21:15 -05:00 committed by GitHub
parent 554a276520
commit 99e6acf2bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()