@@ -38,15 +38,17 @@ SetCompressor /SOLID lzma
3838 !addplugindir " ${PLUGINSPATH}"
3939!endif
4040
41- RequestExecutionLevel user
4241
4342!if " ${INSTALLMODE}" == " perMachine"
4443 RequestExecutionLevel highest
4544!endif
4645
46+ !if " ${INSTALLMODE}" == " currentUser"
47+ RequestExecutionLevel user
48+ !endif
49+
4750!if " ${INSTALLMODE}" == " both"
4851 !define MULTIUSER_MUI
49- !define MULTIUSER_EXECUTIONLEVEL Highest
5052 !define MULTIUSER_INSTALLMODE_INSTDIR " ${PRODUCTNAME}"
5153 !define MULTIUSER_INSTALLMODE_COMMANDLINE
5254 !if " ${ARCH}" == " x64"
@@ -58,11 +60,7 @@ RequestExecutionLevel user
5860 !define MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME " CurrentUser"
5961 !define MULTIUSER_INSTALLMODEPAGE_SHOWUSERNAME
6062 !define MULTIUSER_INSTALLMODE_FUNCTION RestorePreviousInstallLocation
61- Function RestorePreviousInstallLocation
62- ReadRegStr $4 SHCTX " ${MANUPRODUCTKEY}" " "
63- StrCmp $4 " " +2 0
64- StrCpy $INSTDIR $4
65- FunctionEnd
63+ !define MULTIUSER_EXECUTIONLEVEL Highest
6664 !include MultiUser.nsh
6765!endif
6866
@@ -287,22 +285,27 @@ Function .onInit
287285 SetShellVarContext all
288286 !endif
289287
290- !if " ${INSTALLMODE}" == " perMachine"
291- ; Set default install location
292- ${If} ${RunningX64}
293- !if " ${ARCH}" == " x64"
294- StrCpy $INSTDIR " $PROGRAMFILES64\${PRODUCTNAME}"
295- !else if " ${ARCH}" == " arm64"
296- StrCpy $INSTDIR " $PROGRAMFILES64\${PRODUCTNAME}"
297- !else
288+ ${If} $INSTDIR == " "
289+ !if " ${INSTALLMODE}" == " perMachine"
290+ ; Set default install location
291+ ${If} ${RunningX64}
292+ !if " ${ARCH}" == " x64"
293+ StrCpy $INSTDIR " $PROGRAMFILES64\${PRODUCTNAME}"
294+ !else if " ${ARCH}" == " arm64"
295+ StrCpy $INSTDIR " $PROGRAMFILES64\${PRODUCTNAME}"
296+ !else
297+ StrCpy $INSTDIR " $PROGRAMFILES\${PRODUCTNAME}"
298+ !endif
299+ ${Else}
298300 StrCpy $INSTDIR " $PROGRAMFILES\${PRODUCTNAME}"
299- !endif
300- ${Else}
301- StrCpy $INSTDIR " $PROGRAMFILES\${PRODUCTNAME}"
302- ${EndIf}
303- !else if " ${INSTALLMODE}" == " currentUser"
304- StrCpy $INSTDIR " $LOCALAPPDATA\${PRODUCTNAME}"
305- !endif
301+ ${EndIf}
302+ !else if " ${INSTALLMODE}" == " currentUser"
303+ StrCpy $INSTDIR " $LOCALAPPDATA\${PRODUCTNAME}"
304+ !endif
305+
306+ Call RestorePreviousInstallLocation
307+ ${EndIf}
308+
306309
307310 !if " ${INSTALLMODE}" == " both"
308311 !insertmacro MULTIUSER_INIT
@@ -443,14 +446,8 @@ Section Install
443446
444447 !if " ${INSTALLMODE}" == " both"
445448 ; Save install mode to be selected by default for the next installation such as updating
449+ ; or when uninstalling
446450 WriteRegStr SHCTX " ${UNINSTKEY}" $MultiUser .InstallMode 1
447-
448- ; Save install mode to be read by the uninstaller in order to remove the correct
449- ; registry key
450- FileOpen $4 " $INSTDIR\installmode" w
451- FileWrite $4 $MultiUser .InstallMode
452- FileClose $4
453- SetFileAttributes " $INSTDIR\installmode" HIDDEN |READONLY
454451 !endif
455452
456453 ; Registry information for add/remove programs
@@ -486,27 +483,6 @@ FunctionEnd
486483Section Uninstall
487484 !insertmacro CheckIfAppIsRunning
488485
489- ; Remove registry information for add/remove programs
490- !if " ${INSTALLMODE}" == " both"
491- ; Get the saved install mode
492- FileOpen $4 " $INSTDIR\installmode" r
493- FileRead $4 $1
494- FileClose $4
495- Delete " $INSTDIR\installmode"
496-
497- ${If} $1 == " AllUsers"
498- DeleteRegKey HKLM " ${UNINSTKEY}"
499- ${ElseIf} $1 == " CurrentUser"
500- DeleteRegKey HKCU " ${UNINSTKEY}"
501- ${EndIf}
502- !else if " ${INSTALLMODE}" == " perMachine"
503- DeleteRegKey HKLM " ${UNINSTKEY}"
504- !else
505- DeleteRegKey HKCU " ${UNINSTKEY}"
506- !endif
507-
508- DeleteRegValue HKCU " ${MANUPRODUCTKEY}" " Installer Language"
509-
510486 ; Delete the app directory and its content from disk
511487 ; Copy main executable
512488 Delete " $INSTDIR\${MAINBINARYNAME}.exe"
@@ -540,5 +516,21 @@ Section Uninstall
540516 RmDir /r " $APPDATA\${BUNDLEID}"
541517 RmDir /r " $LOCALAPPDATA\${BUNDLEID}"
542518 ${EndIf}
519+
520+ ; Remove registry information for add/remove programs
521+ !if " ${INSTALLMODE}" == " both"
522+ DeleteRegKey SHCTX " ${UNINSTKEY}"
523+ !else if " ${INSTALLMODE}" == " perMachine"
524+ DeleteRegKey HKLM " ${UNINSTKEY}"
525+ !else
526+ DeleteRegKey HKCU " ${UNINSTKEY}"
527+ !endif
528+
529+ DeleteRegValue HKCU " ${MANUPRODUCTKEY}" " Installer Language"
543530SectionEnd
544531
532+ Function RestorePreviousInstallLocation
533+ ReadRegStr $4 SHCTX " ${MANUPRODUCTKEY}" " "
534+ StrCmp $4 " " +2 0
535+ StrCpy $INSTDIR $4
536+ FunctionEnd
0 commit comments