-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathuninstall.go
63 lines (52 loc) · 1.52 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
package msi
import (
"github.com/itchio/butler/butlerd"
"github.com/itchio/butler/cmd/elevate"
"github.com/itchio/butler/installer"
"github.com/pkg/errors"
)
func (m *Manager) Uninstall(params *installer.UninstallParams) error {
consumer := params.Consumer
receipt := params.Receipt
if receipt == nil {
return errors.New("Missing receipt, don't know what to uninstall")
}
if receipt.MSIProductCode == "" {
return errors.New("Missing product code in receipt, don't know what to uninstall")
}
args := []string{
"msi-uninstall",
receipt.MSIProductCode,
}
consumer.Infof("Attempting non-elevated MSI uninstall")
res, err := installer.RunSelf(&installer.RunSelfParams{
Consumer: consumer,
Args: args,
})
if err != nil {
return errors.WithStack(err)
}
if res.ExitCode != 0 {
if shouldTryElevated(consumer, res) {
args = append(args, "--elevate")
consumer.Infof("Attempting elevated MSI uninstall")
res, err := installer.RunSelf(&installer.RunSelfParams{
Consumer: consumer,
Args: args,
})
if err != nil {
return errors.WithStack(err)
}
if res.ExitCode != 0 {
if res.ExitCode == elevate.ExitCodeAccessDenied {
msg := "User or system did not grant elevation privileges"
consumer.Errorf(msg)
return errors.WithStack(butlerd.CodeOperationAborted)
}
consumer.Errorf("Elevated MSI uninstall failed (code %d, 0x%x), we're out of options", res.ExitCode, res.ExitCode)
return errors.New("Elevated MSI uninstallation failed")
}
}
}
return nil
}