-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathuninstall.go
71 lines (55 loc) · 1.71 KB
/
uninstall.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
package nsis
import (
"path/filepath"
"github.com/itchio/butler/filtering"
"github.com/itchio/butler/installer"
"github.com/itchio/dash"
"github.com/pkg/errors"
)
func (m *Manager) Uninstall(params *installer.UninstallParams) error {
consumer := params.Consumer
folder := params.InstallFolderPath
consumer.Infof("%s: probing with configurator", folder)
verdict, err := dash.Configure(folder, &dash.ConfigureParams{
Consumer: consumer,
Filter: filtering.FilterPaths,
})
if err != nil {
return errors.Wrap(err, "looking for nsis uninstaller")
}
var chosen *dash.Candidate
for _, c := range verdict.Candidates {
if c.Flavor != dash.FlavorNativeWindows {
consumer.Infof("%s: ignoring (not native windows)", c.Path)
continue
}
if c.WindowsInfo == nil {
consumer.Infof("%s: ignoring (nil windows info)", c.Path)
continue
}
if c.WindowsInfo.InstallerType != "nsis" {
consumer.Infof("%s: ignoring (wrong installer type '%s')", c.Path, c.WindowsInfo.InstallerType)
continue
}
consumer.Infof("%s: is our chosen uninstaller", c.Path)
chosen = c
break
}
if chosen == nil {
return errors.New("could not find nsis uninstaller in folder")
}
uninstallerPath := filepath.Join(folder, chosen.Path)
cmdTokens := []string{
uninstallerPath,
"/S", // run the uninstaller silently
}
pathArgs := getSeriouslyMisdesignedNsisPathArguments("_?=", params.InstallFolderPath)
cmdTokens = append(cmdTokens, pathArgs...)
consumer.Infof("→ Launching nsis uninstaller")
exitCode, err := installer.RunElevatedCommand(consumer, cmdTokens)
err = installer.CheckExitCode(exitCode, err)
if err != nil {
return errors.Wrap(err, "making sure nsis uninstaller ran correctly")
}
return nil
}