Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exe uninstall support #119

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion system/system_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ limitations under the License.
package system

import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -99,6 +101,22 @@ func uninstallString(installSource, extension string) string {
}
return un
}
default:
if strings.ToLower(v) == strings.ToLower(installSource) {
// Check if the value exists, move on if it doesn't
un, _, err := q.GetStringValue("QuietUninstallString")
if err != nil {
continue
}
if un == "" {
un, _, err = q.GetStringValue("UninstallString")
if err != nil {
// UninstallString not found, move on to next entry
continue
}
}
return un
}
}
}
return ""
Expand Down Expand Up @@ -165,6 +183,14 @@ func Uninstall(dir string, ps *goolib.PkgSpec) error {
un.Args = commands[1:]
un.Args = append([]string{"/qn", "/norestart"}, un.Args...)
filePath = un.Path
default:
r := regexp.MustCompile(`[^\s"]+|"([^"]*)"`)
u := uninstallString(ps.Name, "")
commands := r.FindAllString(u, -1)
// Remove the quotes from the install string since we handle that below
un.Path = strings.Replace(commands[0], "\"", "", -1)
un.Args = commands[1:]
filePath = un.Path
}
if un.Path == "" {
return nil
Expand All @@ -173,7 +199,12 @@ func Uninstall(dir string, ps *goolib.PkgSpec) error {

logger.Infof("Running uninstall command: %q", un.Path)
// logging is only useful for failed uninstall
out, err := oswrap.Create(filepath.Join(dir, un.Path+".log"))
// Only append the directory if the folder structure doesn't exist
logPath := fmt.Sprintf("%s.log", un.Path)
if _, err := os.Stat(un.Path); errors.Is(err, os.ErrNotExist) {
logPath = filepath.Join(dir, logPath)
}
out, err := oswrap.Create(logPath)
if err != nil {
return err
}
Expand Down
Loading