Sander Schobers
9641719579
Refactored event handling to be able to "handle" events so no other controls will handle the same event again.
51 lines
837 B
Go
51 lines
837 B
Go
package tins2020
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func DecodeJSON(path string, v interface{}) error {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
err = json.NewDecoder(f).Decode(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func EncodeJSON(path string, v interface{}) error {
|
|
f, err := os.Create(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
return json.NewEncoder(f).Encode(v)
|
|
}
|
|
|
|
func UserDir() (string, error) {
|
|
config, err := os.UserConfigDir()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
dir := filepath.Join(config, "tins2020_botanim")
|
|
err = os.MkdirAll(dir, 0777)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return dir, nil
|
|
}
|
|
|
|
func UserFile(name string) (string, error) {
|
|
dir, err := UserDir()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return filepath.Join(dir, name), nil
|
|
}
|