-
Notifications
You must be signed in to change notification settings - Fork 1
/
env.go
48 lines (40 loc) · 1011 Bytes
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package muskel
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
appdir "github.com/emersion/go-appdir"
"gitlab.com/gomidi/muskel/predefined"
"gitlab.com/gomidi/muskel/score"
"gitlab.com/metakeule/config"
)
var USER_DIR string
var WORKING_DIR string
func setUserDir(version string) {
USER_DIR = filepath.Join(appdir.New("muskel").UserConfig(), version)
}
func init() {
v, err := config.ParseVersion(VERSION)
if err != nil {
panic("invalid VERSION: " + VERSION)
}
vs := fmt.Sprintf("v%v_%v_%v", v.Major, v.Minor, v.Patch)
setUserDir(vs)
setWorkingDir()
os.MkdirAll(USER_DIR, 0755)
writePredefinedTemplates()
}
func writePredefinedTemplates() {
//fmt.Printf("USER_DIR: %q\n", USER_DIR)
for name, templ := range predefined.SketchesAndTokens {
p := filepath.Join(USER_DIR, name+".mskl")
if !score.FileExists(p) {
ioutil.WriteFile(p, []byte(templ), 0644)
}
p = filepath.Join(USER_DIR, name+".md")
if !score.FileExists(p) {
ioutil.WriteFile(p, []byte(templ), 0644)
}
}
}