From eaa60f129d9db8dd1121bafa8a750d465fd4c0f4 Mon Sep 17 00:00:00 2001 From: Michael Herrmann Date: Mon, 4 Mar 2019 17:34:18 +0100 Subject: [PATCH] Implement Uninstaller for Windows --- Makefile | 17 ++++++---- windows/Uninstaller.nsi | 72 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 windows/Uninstaller.nsi diff --git a/Makefile b/Makefile index eacc836..023be15 100644 --- a/Makefile +++ b/Makefile @@ -66,17 +66,22 @@ launcher-windows: build-windows powershell -Command "(gc ${GEN_SRC_DIR}\launcher\versioninfo.json) -creplace 'YEAR', (Get-Date -UFormat '%Y') | Out-File -Encoding default ${GEN_SRC_DIR}\launcher\versioninfo.json" copy aminal.ico "${GEN_SRC_DIR}\launcher" /Y go generate "${GEN_SRC_DIR}\launcher" - if exist "bin\windows\launcher" rmdir /S /Q "bin\windows\launcher" - mkdir "bin\windows\launcher\Versions\${VERSION}" - go build -o "bin\windows\launcher\${BINARY}.exe" -ldflags "-H windowsgui" "${GEN_SRC_DIR}\launcher" - copy ${BINARY}-windows-amd64.exe "bin\windows\launcher\Versions\${VERSION}\${BINARY}.exe" /Y + if exist "bin\windows\Aminal" rmdir /S /Q "bin\windows\Aminal" + mkdir "bin\windows\Aminal\Versions\${VERSION}" + go build -o "bin\windows\Aminal\${BINARY}.exe" -ldflags "-H windowsgui" "${GEN_SRC_DIR}\launcher" + copy ${BINARY}-windows-amd64.exe "bin\windows\Aminal\Versions\${VERSION}\${BINARY}.exe" /Y + +.PHONY: uninstaller-windows +uninstaller-windows: launcher-windows + makensis "/XOutFile bin/windows/UninstallerSetup.exe" /NOCD windows\Uninstaller.nsi + cmd /c "bin\windows\UninstallerSetup.exe /S /D=%cd%\bin\windows\Aminal" .PHONY: installer-windows -installer-windows: +installer-windows: uninstaller-windows if exist "${GEN_SRC_DIR}\installer" rmdir /S /Q "${GEN_SRC_DIR}\installer" xcopy "windows\installer\*.*" "${GEN_SRC_DIR}\installer" /K /H /Y /Q /I powershell -Command "(gc ${GEN_SRC_DIR}\installer\installer.go) -creplace 'VERSION', '${VERSION}' | Out-File -Encoding default ${GEN_SRC_DIR}\installer\installer.go" - go-bindata -prefix "bin\windows\launcher" -o "${GEN_SRC_DIR}/installer/data/data.go" "./bin/windows/launcher/..." + go-bindata -prefix "bin\windows\Aminal" -o "${GEN_SRC_DIR}/installer/data/data.go" "./bin/windows/Aminal/..." powershell -Command "(gc ${GEN_SRC_DIR}\installer\data\data.go) -creplace 'package main', 'package data' | Out-File -Encoding default ${GEN_SRC_DIR}\installer\data\data.go" go build -o bin/windows/AminalSetup.exe -ldflags "-H windowsgui" "${GEN_SRC_DIR}/installer/installer.go" rem If an .exe name contains "installer", "setup" etc., then at least Windows 10 automatically diff --git a/windows/Uninstaller.nsi b/windows/Uninstaller.nsi new file mode 100644 index 0000000..c6a2688 --- /dev/null +++ b/windows/Uninstaller.nsi @@ -0,0 +1,72 @@ +!include MUI2.nsh + +;-------------------------------- +;Perform Machine-level install, if possible + +!define MULTIUSER_EXECUTIONLEVEL Highest +;Add support for command-line args that let uninstaller know whether to +;uninstall machine- or user installation: +!define MULTIUSER_INSTALLMODE_COMMANDLINE +!include MultiUser.nsh +!include LogicLib.nsh + +Function .onInit + !insertmacro MULTIUSER_INIT +FunctionEnd + +Function un.onInit + !insertmacro MULTIUSER_UNINIT +FunctionEnd + +;-------------------------------- +;General + + Name "Aminal" + +;-------------------------------- +;Pages + + !insertmacro MUI_UNPAGE_CONFIRM + !insertmacro MUI_UNPAGE_INSTFILES + +;-------------------------------- +;Languages + + !insertmacro MUI_LANGUAGE "English" + +;-------------------------------- +;Installer Sections + +Section + SetOutPath "$InstDir" + WriteUninstaller "$InstDir\uninstall.exe" +SectionEnd + +;-------------------------------- +;Uninstaller Section + +!define UNINST_KEY \ + "Software\Microsoft\Windows\CurrentVersion\Uninstall\Aminal" +!define ROOT_KEY "Software\Aminal" +!define UPDATE_KEY \ + "${ROOT_KEY}\Update\Clients\{35B0CF1E-FBB0-486F-A1DA-BE3A41DDC780}" + +Section "Uninstall" + + RMDir /r "$InstDir\Versions" + Delete "$InstDir\Aminal.exe" + Delete "$InstDir\uninstall.exe" + ;Omaha leaves this directory behind. Delete if empty: + RMDir "$InstDir\CrashReports" + RMDir "$InstDir" + Delete "$SMPROGRAMS\Aminal.lnk" + DeleteRegKey SHCTX "${UNINST_KEY}" + DeleteRegKey SHCTX "${UPDATE_KEY}" + DeleteRegKey /ifempty SHCTX "${ROOT_KEY}\Update\Clients" + ;Try to speed up uninstall of Omaha: + DeleteRegValue SHCTX "${ROOT_KEY}\Update" "LastChecked" + DeleteRegKey /ifempty SHCTX "${ROOT_KEY}\Update" + WriteRegStr SHCTX "${ROOT_KEY}" "" "" + DeleteRegKey /ifempty SHCTX "${ROOT_KEY}" + +SectionEnd \ No newline at end of file