You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
845 B
46 lines
845 B
package main |
|
|
|
import ( |
|
"encoding/json" |
|
"io/ioutil" |
|
) |
|
|
|
/* |
|
Game chess.Game |
|
StartTime time.Time |
|
ConvID string |
|
White string |
|
Black string |
|
Move bool |
|
*/ |
|
func loadConfig() Config { |
|
var c Config |
|
confFile, _ := ioutil.ReadFile(configFile) |
|
_ = json.Unmarshal([]byte(confFile), &c) |
|
for cid, game := range c.Games { |
|
g := game.Game.Clone() |
|
c.Games[cid] = Game{ |
|
Game: *g, |
|
StartTime: game.StartTime, |
|
ConvID: game.ConvID, |
|
White: game.White, |
|
Black: game.Black, |
|
Move: game.Move, |
|
} |
|
} |
|
return c |
|
} |
|
|
|
func saveConfig() { |
|
defer log.PanicSafe("saveConfig") |
|
log.LogInfo("Saving config.") |
|
file, err := json.Marshal(config) |
|
if err != nil { |
|
log.LogErrorType(err) |
|
} |
|
err = ioutil.WriteFile(configFile, file, 0600) |
|
if err != nil { |
|
log.LogErrorType(err) |
|
} |
|
log.LogInfo("Config Saved.") |
|
}
|
|
|