mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-06-29 18:45:23 +00:00
Write default configuration file if one is not found. (#298)
This commit is contained in:
parent
554a276520
commit
99e6acf2bb
|
@ -6,6 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -53,6 +54,17 @@ func Initialize() error {
|
||||||
singleton = &config
|
singleton = &config
|
||||||
return nil
|
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()
|
singleton = getDefaultConfiguration()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user