-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
73 lines (63 loc) · 1.66 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
package main
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/chenqinghe/redis-desktop/config"
"github.com/chenqinghe/redis-desktop/i18n"
"github.com/chenqinghe/walk"
"github.com/sirupsen/logrus"
)
func coredump(msg string) {
ioutil.WriteFile("coredump", []byte(msg), os.ModePerm)
os.Exit(1)
}
func main() {
rootPath := os.Getenv("APPDATA")
appPath := filepath.Join(rootPath, "RedisDesktop")
// redirect stdout & stderr to ensure capture panic info
//logFile := filepath.Join(appPath, "RedisDesktop.log")
//if err := os.MkdirAll(filepath.Dir(logFile), os.ModePerm); err != nil {
// coredump(err.Error())
//}
//f, err := NewFileDescriptor(logFile)
//if err != nil {
// coredump(err.Error())
//}
//if err := SetStdHandle(f, f); err != nil {
// coredump(err.Error())
//}
var err error
configPath := filepath.Join(appPath, "config.toml")
_, err = os.Stat(configPath)
if err != nil {
if os.IsNotExist(err) {
if err := config.Save(configPath); err != nil {
logrus.Fatalln("save config:", err)
}
} else {
logrus.Fatalln("stat config file:", err)
}
} else {
if err := config.Load(configPath); err != nil {
logrus.Fatalln("load config:", err)
}
}
lv, err := logrus.ParseLevel(config.Get().LogConfig.Level)
if err != nil {
lv = logrus.InfoLevel
}
logrus.SetLevel(lv)
//logrus.SetReportCaller(true)
lang, ok := i18n.GetLang(config.Get().Lang)
if ok {
i18n.SetDefaultLang(lang)
}
mw := createMainWindow()
mw.SetSessionFile(filepath.Join(appPath, "sessions.dat"))
if err := mw.LoadSession(); err != nil {
walk.MsgBox(mw, "ERROR", i18n.Tr("alert.loadsessionfailed", err.Error()), walk.MsgBoxIconError)
return
}
mw.Run()
}