-
Notifications
You must be signed in to change notification settings - Fork 5
/
build-assets.go
48 lines (44 loc) · 1.23 KB
/
build-assets.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 main
import (
"fmt"
"os"
"os/exec"
"strings"
"io/ioutil"
"path/filepath"
)
func b64(filename string) string {
name := filename
name = strings.Replace(name, "\\", "/", -1);
fmt.Printf("Adding %s\n", name);
name = strings.Split(name, "/")[1];
name = strings.Split(name, ".")[0];
name = strings.Replace(name, "-", "_", -1);
name = strings.ToUpper(name);
data, _ := ioutil.ReadFile(filename);
// for b := range(data) {
// .join([(fmt.Sprintf("\\\\x%02X", ord(x))) for x in file(sys.argv[1]).read()]);
// }
return fmt.Sprintf("\t%s = %#v\n", name, string(data));
}
func main() {
fp, _ := os.OpenFile("viewer/gui/bindata.go", os.O_WRONLY|os.O_TRUNC, 0666);
fmt.Fprintf(fp, "package gui\n");
fmt.Fprintf(fp, "const (\n");
names, _ := filepath.Glob("data/*.png")
for _, fn := range(names) {
tmp := fmt.Sprintf("%s.dat", fn);
exec.Command("gdk-pixbuf-pixdata", fn, tmp);
fmt.Fprintf(fp, "%s", b64(tmp));
os.Remove(tmp);
}
fmt.Fprintf(fp, ")\n");
fp, _ = os.OpenFile("common/bindata.go", os.O_WRONLY|os.O_TRUNC, 0666);
fmt.Fprintf(fp, "package common\n");
fmt.Fprintf(fp, "const (\n");
names, _ = filepath.Glob("data/*.txt")
for _, fn := range(names) {
fmt.Fprintf(fp, "%s", b64(fn));
}
fmt.Fprintf(fp, ")\n");
}