-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathuninstall.go
64 lines (50 loc) · 1.5 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
package inno
import (
"path/filepath"
"github.com/go-errors/errors"
"github.com/itchio/butler/configurator"
"github.com/itchio/butler/installer"
)
func (m *Manager) Uninstall(params *installer.UninstallParams) error {
consumer := params.Consumer
folder := params.InstallFolderPath
consumer.Infof("%s: probing with configurator", folder)
verdict, err := configurator.Configure(folder, false)
if err != nil {
return errors.Wrap(err, 0)
}
var chosen *configurator.Candidate
for _, c := range verdict.Candidates {
if c.Flavor != configurator.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 != "inno" {
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 inno uninstaller in folder")
}
uninstallerPath := filepath.Join(folder, chosen.Path)
cmdTokens := []string{
uninstallerPath,
"/VERYSILENT", // be vewwy vewwy quiet
}
consumer.Infof("→ Launching inno uninstaller")
// N.B: InnoSetup uninstallers are smart enough to elevate themselves.
exitCode, err := installer.RunCommand(consumer, cmdTokens)
err = installer.CheckExitCode(exitCode, err)
if err != nil {
return errors.Wrap(err, 0)
}
return nil
}