-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
67 lines (55 loc) · 1.47 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
//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 (
"fmt"
"github.com/portapps/portapps/v3"
"github.com/portapps/portapps/v3/pkg/log"
"github.com/portapps/portapps/v3/pkg/utl"
"github.com/portapps/portapps/v3/pkg/win"
"golang.org/x/sys/windows/registry"
)
type config struct {
Silent bool `yaml:"silent" mapstructure:"silent"`
}
var (
app *portapps.App
cfg *config
)
func init() {
var err error
// Default config
cfg = &config{
Silent: false,
}
// Init app
if app, err = portapps.NewWithCfg("oracle-jdk-portable", "Oracle JDK", cfg); err != nil {
log.Fatal().Err(err).Msg("Cannot initialize application. See log file for more info.")
}
}
func main() {
var err error
var resp int
if !cfg.Silent {
resp, err = win.MsgBox(
fmt.Sprintf("%s portable", app.Name),
"Would you like to set JAVA_HOME in your environment ?",
win.MsgBoxBtnYesNo|win.MsgBoxIconQuestion)
if err != nil {
log.Fatal().Err(err).Msg("Cannot create dialog box")
}
} else {
resp = win.MsgBoxSelectYes
}
if resp != win.MsgBoxSelectYes {
log.Info().Msg("Skipping setting JAVA_HOME...")
return
}
log.Info().Msgf("Set JAVA_HOME=%s", utl.PathJoin(app.AppPath))
err = win.SetPermEnv(registry.CURRENT_USER, "JAVA_HOME", utl.PathJoin(app.AppPath))
if err != nil {
log.Fatal().Err(err).Msg("Cannot set JAVA_HOME")
}
win.RefreshEnv()
defer app.Close()
}