Skip to content

Commit

Permalink
fix(nsis): prefill $INSTDIR with previous install path and respect `/…
Browse files Browse the repository at this point in the history
…D` flag, closes #6928 (#6935)

* fix(bundler/nsis): prefill $INSTDIR with previous install path

* fix(nsis): prefill $INSTDIR with previous install path and respect `/D` flag, closes #6928
  • Loading branch information
amrbashir authored May 15, 2023
1 parent 2948820 commit 3cc295e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 50 deletions.
6 changes: 6 additions & 0 deletions .changes/nsis-restore-installation-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'tauri-bundler': 'patch'
---

- Fix NSIS installer not using the old installation path as a default when using `perMachine` or `currentUser` install modes.
- NSIS will now respect the `/D` flag which used to set the installation directory from command line.
92 changes: 42 additions & 50 deletions tooling/bundler/src/bundle/windows/templates/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ SetCompressor /SOLID lzma
!addplugindir "${PLUGINSPATH}"
!endif

RequestExecutionLevel user

!if "${INSTALLMODE}" == "perMachine"
RequestExecutionLevel highest
!endif

!if "${INSTALLMODE}" == "currentUser"
RequestExecutionLevel user
!endif

!if "${INSTALLMODE}" == "both"
!define MULTIUSER_MUI
!define MULTIUSER_EXECUTIONLEVEL Highest
!define MULTIUSER_INSTALLMODE_INSTDIR "${PRODUCTNAME}"
!define MULTIUSER_INSTALLMODE_COMMANDLINE
!if "${ARCH}" == "x64"
Expand All @@ -58,11 +60,7 @@ RequestExecutionLevel user
!define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME "CurrentUser"
!define MULTIUSER_INSTALLMODEPAGE_SHOWUSERNAME
!define MULTIUSER_INSTALLMODE_FUNCTION RestorePreviousInstallLocation
Function RestorePreviousInstallLocation
ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" ""
StrCmp $4 "" +2 0
StrCpy $INSTDIR $4
FunctionEnd
!define MULTIUSER_EXECUTIONLEVEL Highest
!include MultiUser.nsh
!endif

Expand Down Expand Up @@ -287,22 +285,27 @@ Function .onInit
SetShellVarContext all
!endif

!if "${INSTALLMODE}" == "perMachine"
; Set default install location
${If} ${RunningX64}
!if "${ARCH}" == "x64"
StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}"
!else if "${ARCH}" == "arm64"
StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}"
!else
${If} $INSTDIR == ""
!if "${INSTALLMODE}" == "perMachine"
; Set default install location
${If} ${RunningX64}
!if "${ARCH}" == "x64"
StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}"
!else if "${ARCH}" == "arm64"
StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCTNAME}"
!else
StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}"
!endif
${Else}
StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}"
!endif
${Else}
StrCpy $INSTDIR "$PROGRAMFILES\${PRODUCTNAME}"
${EndIf}
!else if "${INSTALLMODE}" == "currentUser"
StrCpy $INSTDIR "$LOCALAPPDATA\${PRODUCTNAME}"
!endif
${EndIf}
!else if "${INSTALLMODE}" == "currentUser"
StrCpy $INSTDIR "$LOCALAPPDATA\${PRODUCTNAME}"
!endif

Call RestorePreviousInstallLocation
${EndIf}


!if "${INSTALLMODE}" == "both"
!insertmacro MULTIUSER_INIT
Expand Down Expand Up @@ -443,14 +446,8 @@ Section Install

!if "${INSTALLMODE}" == "both"
; Save install mode to be selected by default for the next installation such as updating
; or when uninstalling
WriteRegStr SHCTX "${UNINSTKEY}" $MultiUser.InstallMode 1

; Save install mode to be read by the uninstaller in order to remove the correct
; registry key
FileOpen $4 "$INSTDIR\installmode" w
FileWrite $4 $MultiUser.InstallMode
FileClose $4
SetFileAttributes "$INSTDIR\installmode" HIDDEN|READONLY
!endif

; Registry information for add/remove programs
Expand Down Expand Up @@ -486,27 +483,6 @@ FunctionEnd
Section Uninstall
!insertmacro CheckIfAppIsRunning

; Remove registry information for add/remove programs
!if "${INSTALLMODE}" == "both"
; Get the saved install mode
FileOpen $4 "$INSTDIR\installmode" r
FileRead $4 $1
FileClose $4
Delete "$INSTDIR\installmode"

${If} $1 == "AllUsers"
DeleteRegKey HKLM "${UNINSTKEY}"
${ElseIf} $1 == "CurrentUser"
DeleteRegKey HKCU "${UNINSTKEY}"
${EndIf}
!else if "${INSTALLMODE}" == "perMachine"
DeleteRegKey HKLM "${UNINSTKEY}"
!else
DeleteRegKey HKCU "${UNINSTKEY}"
!endif

DeleteRegValue HKCU "${MANUPRODUCTKEY}" "Installer Language"

; Delete the app directory and its content from disk
; Copy main executable
Delete "$INSTDIR\${MAINBINARYNAME}.exe"
Expand Down Expand Up @@ -540,5 +516,21 @@ Section Uninstall
RmDir /r "$APPDATA\${BUNDLEID}"
RmDir /r "$LOCALAPPDATA\${BUNDLEID}"
${EndIf}

; Remove registry information for add/remove programs
!if "${INSTALLMODE}" == "both"
DeleteRegKey SHCTX "${UNINSTKEY}"
!else if "${INSTALLMODE}" == "perMachine"
DeleteRegKey HKLM "${UNINSTKEY}"
!else
DeleteRegKey HKCU "${UNINSTKEY}"
!endif

DeleteRegValue HKCU "${MANUPRODUCTKEY}" "Installer Language"
SectionEnd

Function RestorePreviousInstallLocation
ReadRegStr $4 SHCTX "${MANUPRODUCTKEY}" ""
StrCmp $4 "" +2 0
StrCpy $INSTDIR $4
FunctionEnd

0 comments on commit 3cc295e

Please sign in to comment.