-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
86 lines (75 loc) · 2.13 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"flag"
"fmt"
_ "image/gif"
_ "image/png"
"os"
"path/filepath"
"runtime/pprof"
"time"
_ "golang.org/x/image/bmp"
"github.com/inkyblackness/hacked/crash"
"github.com/inkyblackness/hacked/editor"
"github.com/inkyblackness/hacked/ui/native"
)
var version string
func main() {
scale := flag.Float64("scale", 1.0, "factor for scaling the UI (0.5 .. 10.0). 1080p displays should use default. 4K most likely 2.0.")
fontFile := flag.String("fontfile", "", "Path to font file (.TTF) to use instead of the default font. Useful for HiDPI displays.")
fontSize := flag.Float64("fontsize", 0.0, "Size of the font to use. If not specified, a default height will be used.")
cpuProfile := flag.String("cpuprofile", "", "write cpu profile to file")
flag.Parse()
var app editor.Application
app.FontFile = *fontFile
app.FontSize = float32(*fontSize)
app.GuiScale = float32(*scale)
if len(version) > 0 {
app.Version = version
} else {
app.Version = fmt.Sprintf("(manual build %v)", time.Now().Format("2006-01-02"))
}
configDir, err := configDir()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Failed to determine config dir: %v", err)
os.Exit(-1)
}
app.ConfigDir = configDir
versionInfo := "InkyBlackness - HackEd - " + app.Version
defer crash.Handler(versionInfo)
profileFin, err := initProfiling(*cpuProfile)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Failed to start CPU profiling: %v\n", err)
}
defer profileFin()
err = native.Run(app.InitializeWindow, versionInfo, 30.0)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Failed to run application: %v\n", err)
}
}
func initProfiling(filename string) (func(), error) {
if filename == "" {
return func() {}, nil
}
f, err := os.Create(filename)
if err != nil {
return func() {}, err
}
err = pprof.StartCPUProfile(f)
return func() {
pprof.StopCPUProfile()
_ = f.Close()
}, err
}
func configDir() (string, error) {
base, err := os.UserConfigDir()
if err != nil {
return "", err
}
fullPath := filepath.Join(base, "InkyBlackness", "HackEd")
err = os.MkdirAll(fullPath, os.ModeDir|0750)
if err != nil {
return "", err
}
return fullPath, nil
}