forked from portapps/vlc-portable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
127 lines (110 loc) Β· 3.58 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//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"
"github.com/portapps/portapps/v3"
"github.com/portapps/portapps/v3/pkg/log"
"github.com/portapps/portapps/v3/pkg/registry"
"github.com/portapps/portapps/v3/pkg/utl"
)
type config struct {
Cleanup bool `yaml:"cleanup" mapstructure:"cleanup"`
Verbose string `yaml:"verbose" mapstructure:"verbose"`
}
var (
app *portapps.App
cfg *config
)
func init() {
var err error
// Default config
cfg = &config{
Cleanup: false,
Verbose: "1",
}
// Init app
if app, err = portapps.NewWithCfg("vlc-portable", "VLC", 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, "vlc.exe")
app.Args = []string{
"--vlm-conf=" + utl.PathJoin(app.DataPath, "vlcrc"),
"--config=" + utl.PathJoin(app.DataPath, "vlcrc"),
"--no-plugins-cache",
"--no-qt-updates-notif",
}
// VLC paths
vlcRoamingPath := utl.PathJoin(os.Getenv("APPDATA"), "vlc")
vlcTmpPath := utl.CreateFolder(app.AppPath, "tmp")
// Set env vars
os.Setenv("VLC_PLUGIN_PATH", utl.CreateFolder(app.DataPath, "plugins"))
os.Setenv("VLC_VERBOSE", cfg.Verbose)
os.Setenv("TEMP", vlcTmpPath)
// VLC volatile files
dataDvdcssPath := utl.PathJoin(app.DataPath, "dvdcss")
dataMlXspf := utl.PathJoin(app.DataPath, "ml.xspf")
dataVlcQtInterface := utl.PathJoin(app.DataPath, "vlc-qt-interface.ini")
roamingDvdcssPath := utl.PathJoin(os.Getenv("APPDATA"), "dvdcss")
roamingMlXspf := utl.PathJoin(vlcRoamingPath, "ml.xspf")
roamingVlcQtInterface := utl.PathJoin(vlcRoamingPath, "vlc-qt-interface.ini")
// Copy existing files from data to roaming folder for the current user
utl.CreateFolder(vlcRoamingPath)
if _, err := os.Stat(dataMlXspf); err == nil {
if err := utl.CopyFile(dataMlXspf, roamingMlXspf); err != nil {
log.Error().Err(err).Msgf("Cannot copy %s", dataMlXspf)
}
}
if _, err := os.Stat(dataVlcQtInterface); err == nil {
if err := utl.CopyFile(dataVlcQtInterface, roamingVlcQtInterface); err != nil {
log.Error().Err(err).Msgf("Cannot copy %s", dataVlcQtInterface)
}
}
// Handle reg key
regFile := utl.PathJoin(utl.CreateFolder(app.RootPath, "reg"), "VLC.reg")
regKey := registry.Key{
Key: `HKCU\Software\VideoLAN\VLC`,
Arch: "32",
}
if err := regKey.Import(regFile); err != nil {
log.Warn().Err(err).Msg("Cannot import registry key")
}
// On exit
defer func() {
// Copy back to data
if _, err := os.Stat(dataDvdcssPath); err == nil {
if err = utl.CopyFolder(dataDvdcssPath, roamingDvdcssPath); err != nil {
log.Warn().Err(err).Msgf("Cannot copy back %s", dataDvdcssPath)
}
}
if _, err := os.Stat(roamingMlXspf); err == nil {
if err = utl.CopyFile(roamingMlXspf, dataMlXspf); err != nil {
log.Warn().Err(err).Msgf("Cannot copy back %s", roamingMlXspf)
}
}
if _, err := os.Stat(roamingVlcQtInterface); err == nil {
if err = utl.CopyFile(roamingVlcQtInterface, dataVlcQtInterface); err != nil {
log.Warn().Err(err).Msgf("Cannot copy back %s", roamingVlcQtInterface)
}
}
// Export reg key
if err := regKey.Export(regFile); err != nil {
log.Error().Err(err).Msg("Cannot export registry key")
}
// Cleanup
if cfg.Cleanup {
utl.Cleanup([]string{
vlcRoamingPath,
vlcTmpPath,
})
if err := regKey.Delete(true); err != nil {
log.Error().Err(err).Msg("Cannot remove registry key")
}
}
}()
defer app.Close()
app.Launch(os.Args[1:])
}