forked from portapps/vscode-portable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 1.28 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
//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"
"path"
"github.com/portapps/portapps/v3"
"github.com/portapps/portapps/v3/pkg/log"
"github.com/portapps/portapps/v3/pkg/utl"
)
type config struct {
Cleanup bool `yaml:"cleanup" mapstructure:"cleanup"`
}
var (
app *portapps.App
cfg *config
)
func init() {
var err error
// Default config
cfg = &config{
Cleanup: false,
}
// Init app
if app, err = portapps.NewWithCfg("vscode-portable", "Visual Studio Code", cfg); 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, "Code.exe")
app.Args = []string{
"--log debug",
}
// Cleanup on exit
if cfg.Cleanup {
defer func() {
utl.Cleanup([]string{
path.Join(os.Getenv("APPDATA"), "Code"),
})
}()
}
os.Setenv("VSCODE_APPDATA", utl.PathJoin(app.DataPath, "appdata"))
if !app.Config().Common.DisableLog {
os.Setenv("VSCODE_LOGS", utl.PathJoin(app.DataPath, "logs"))
}
os.Setenv("VSCODE_EXTENSIONS", utl.PathJoin(app.DataPath, "extensions"))
defer app.Close()
app.Launch(os.Args[1:])
}