-
Notifications
You must be signed in to change notification settings - Fork 3
/
icons.go
71 lines (66 loc) · 1.8 KB
/
icons.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"bufio"
"encoding/base64"
"github.com/lxn/walk"
"io"
"path"
"regexp"
"strings"
)
var iconDict = make(map[string]string)
func init() {
f, err := assets.Open(path.Join(hkSplitMakerDir, "icons", "icons.ts"))
if err != nil {
walk.MsgBox(nil, "错误", err.Error(), walk.MsgBoxIconError)
panic(err)
}
defer func() {
if err := f.Close(); err != nil {
walk.MsgBox(nil, "错误", err.Error(), walk.MsgBoxIconError)
}
}()
re, err := regexp.Compile(`import\s+(\w+)\s+from\s+"(.*?)"\s*;`)
if err != nil {
walk.MsgBox(nil, "错误", err.Error(), walk.MsgBoxIconError)
panic(err)
}
rd := bufio.NewReader(f)
line, isPrefix, err := rd.ReadLine()
for ; err == nil; line, isPrefix, err = rd.ReadLine() {
if isPrefix {
walk.MsgBox(nil, "错误", "暂不支持这样的文件", walk.MsgBoxIconError)
panic(err)
}
lineStr := strings.TrimSpace(string(line))
if len(lineStr) < 2 || lineStr[:2] == "//" {
continue
}
result := re.FindStringSubmatch(lineStr)
if result != nil {
iconDict[result[1]] = result[2]
}
}
if err == io.EOF {
err = nil
}
if err != nil {
walk.MsgBox(nil, "错误", err.Error(), walk.MsgBoxIconError)
panic(err)
}
}
func getIcon(splitId string) string {
iconPath, ok := iconDict[splitId]
if !ok {
return ""
}
iconPath = path.Join(hkSplitMakerDir, "icons", iconPath)
buf, err := assets.ReadFile(iconPath)
if err != nil {
return ""
}
s := base64.StdEncoding.EncodeToString(append([]byte{0, 2}, buf...))
return livesplitFormatHeader + s
//return "<![CDATA[" + livesplitFormatHeader + s + "]]>"
}
const livesplitFormatHeader = "AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj00LjAuMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAOw8A"