-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
74 lines (63 loc) · 2.46 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
//go:generate go install -v github.com/josephspurrier/goversioninfo/cmd/goversioninfo
//go:generate goversioninfo -icon=res/papp.ico -manifest=res/papp.manifest
package main
import (
"os"
"strings"
"github.com/magiconair/properties"
"github.com/portapps/portapps/v3"
"github.com/portapps/portapps/v3/pkg/log"
"github.com/portapps/portapps/v3/pkg/utl"
)
var (
app *portapps.App
)
func init() {
var err error
// Init app
if app, err = portapps.New("dbeaver-portable", "DBeaver"); err != nil {
log.Fatal().Err(err).Msg("Cannot initialize application. See log file for more info.")
}
}
func main() {
utl.CreateFolder(app.DataPath)
app.Process = utl.PathJoin(app.AppPath, "dbeaver.exe")
app.Args = []string{
"-data",
app.DataPath,
"-vm",
utl.PathJoin(app.AppPath, "jre", "bin", "javaw.exe"),
}
driversPath := utl.CreateFolder(app.DataPath, ".metadata", "drivers")
logsPath := utl.CreateFolder(app.DataPath, ".metadata", "logs")
corePrefsPath := utl.CreateFolder(app.DataPath, ".metadata", ".plugins", "org.eclipse.core.runtime", ".settings")
corePrefsFile := utl.PathJoin(corePrefsPath, "org.jkiss.dbeaver.core.prefs")
defaultProps := properties.NewProperties()
_, _, _ = defaultProps.Set("dialog.default.folder", formatPath(app.DataPath))
_, _, _ = defaultProps.Set("logs.debug.location", formatPath(utl.PathJoin(logsPath, "dbeaver-debug.log")))
_, _, _ = defaultProps.Set("qm.logDirectory", formatPath(logsPath))
_, _, _ = defaultProps.Set("ui.auto.update.check", "false")
_, _, _ = defaultProps.Set("ui.drivers.home", formatPath(driversPath))
if !utl.Exists(corePrefsFile) {
log.Info().Msg("Creating default props...")
if err := utl.WriteToFile(corePrefsFile, defaultProps.String()); err != nil {
log.Error().Err(err).Msg("Cannot write default props to org.jkiss.dbeaver.core.prefs")
}
} else {
log.Info().Msg("Loading org.jkiss.dbeaver.core.prefs file...")
corePrefsProps, err := properties.LoadFile(corePrefsFile, properties.UTF8)
if err != nil {
log.Error().Err(err).Msg("Cannot load org.jkiss.dbeaver.core.prefs file")
}
corePrefsProps.Merge(defaultProps)
log.Info().Msg("Writing to org.jkiss.dbeaver.core.prefs")
if err := utl.WriteToFile(corePrefsFile, corePrefsProps.String()); err != nil {
log.Error().Err(err).Msg("Cannot write to org.jkiss.dbeaver.core.prefs")
}
}
defer app.Close()
app.Launch(os.Args[1:])
}
func formatPath(path string) string {
return strings.Replace(strings.Replace(path, `/`, `\`, -1), `\`, `\\`, -1)
}