Windows installer: Improve architecture detection

Show an appropriate error if the ARM64 installer is run on non-ARM
Windows or if the x64 installer is run on a 32-bit system, and set the
correct architecture in `CurrentVersion\Uninstall` registry key.

Also fix `x86`/`x64` being swapped in the registry
(https://groups.google.com/g/zotero-dev/c/1Aju4t2TNTo/m/Ga4V8vLrAQAJ)
This commit is contained in:
Dan Stillman 2024-08-10 02:44:58 -04:00
parent 6e155de3e1
commit b8b4bebfc5
4 changed files with 35 additions and 11 deletions

View file

@ -764,8 +764,10 @@ if [ $BUILD_WIN == 1 ]; then
# Build uninstaller # Build uninstaller
if [ "$arch" = "win32" ]; then if [ "$arch" = "win32" ]; then
"`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /V1 "`cygpath -w \"$BUILD_DIR/win_installer/uninstaller.nsi\"`" "`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /V1 "`cygpath -w \"$BUILD_DIR/win_installer/uninstaller.nsi\"`"
elif [[ "$arch" = "win-x64" ]] || [[ "$arch" = "win-arm64" ]]; then elif [ "$arch" = "win-x64" ]; then
"`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /DHAVE_64BIT_BUILD /V1 "`cygpath -w \"$BUILD_DIR/win_installer/uninstaller.nsi\"`" "`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /DHAVE_64BIT_BUILD /V1 "`cygpath -w \"$BUILD_DIR/win_installer/uninstaller.nsi\"`"
elif [ "$arch" = "win-arm64" ]; then
"`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /DHAVE_64BIT_BUILD /D_ARM64_ /V1 "`cygpath -w \"$BUILD_DIR/win_installer/uninstaller.nsi\"`"
fi fi
mv "$BUILD_DIR/win_installer/helper.exe" "$APPDIR/uninstall" mv "$BUILD_DIR/win_installer/helper.exe" "$APPDIR/uninstall"
@ -798,8 +800,10 @@ if [ $BUILD_WIN == 1 ]; then
# Build and sign setup.exe # Build and sign setup.exe
if [ "$arch" = "win32" ]; then if [ "$arch" = "win32" ]; then
"`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /V1 "`cygpath -w \"$BUILD_DIR/win_installer/installer.nsi\"`" "`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /V1 "`cygpath -w \"$BUILD_DIR/win_installer/installer.nsi\"`"
elif [[ "$arch" = "win-x64" ]] || [[ "$arch" = "win-arm64" ]]; then elif [ "$arch" = "win-x64" ]; then
"`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /DHAVE_64BIT_BUILD /V1 "`cygpath -w \"$BUILD_DIR/win_installer/installer.nsi\"`" "`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /DHAVE_64BIT_BUILD /V1 "`cygpath -w \"$BUILD_DIR/win_installer/installer.nsi\"`"
elif [ "$arch" = "win-arm64" ]; then
"`cygpath -u \"${NSIS_DIR}makensis.exe\"`" /DHAVE_64BIT_BUILD /D_ARM64_ /V1 "`cygpath -w \"$BUILD_DIR/win_installer/installer.nsi\"`"
fi fi
mv "$BUILD_DIR/win_installer/setup.exe" "$INSTALLER_STAGE_DIR" mv "$BUILD_DIR/win_installer/setup.exe" "$INSTALLER_STAGE_DIR"

View file

@ -1280,6 +1280,7 @@ Var Trash
; (not on Windows XP http://support.microsoft.com/kb/282747) so just use it ; (not on Windows XP http://support.microsoft.com/kb/282747) so just use it
; when installing on an x64 systems even when installing an x86 application. ; when installing on an x64 systems even when installing an x86 application.
${If} ${RunningX64} ${If} ${RunningX64}
${OrIf} ${IsNativeARM64}
${DisableX64FSRedirection} ${DisableX64FSRedirection}
ExecWait '"$SYSDIR\regsvr32.exe" /s "${DLL}"' ExecWait '"$SYSDIR\regsvr32.exe" /s "${DLL}"'
${EnableX64FSRedirection} ${EnableX64FSRedirection}
@ -1295,6 +1296,7 @@ Var Trash
; (not on Windows XP http://support.microsoft.com/kb/282747) so just use it ; (not on Windows XP http://support.microsoft.com/kb/282747) so just use it
; when installing on an x64 systems even when installing an x86 application. ; when installing on an x64 systems even when installing an x86 application.
${If} ${RunningX64} ${If} ${RunningX64}
${OrIf} ${IsNativeARM64}
${DisableX64FSRedirection} ${DisableX64FSRedirection}
ExecWait '"$SYSDIR\regsvr32.exe" /s /u "${DLL}"' ExecWait '"$SYSDIR\regsvr32.exe" /s /u "${DLL}"'
${EnableX64FSRedirection} ${EnableX64FSRedirection}
@ -2114,6 +2116,7 @@ FunctionEnd
StrCpy $R6 0 ; set the counter for the outer loop to 0 StrCpy $R6 0 ; set the counter for the outer loop to 0
${If} ${RunningX64} ${If} ${RunningX64}
${OrIf} ${IsNativeARM64}
StrCpy $R0 "false" StrCpy $R0 "false"
; Set the registry to the 32 bit registry for 64 bit installations or to ; Set the registry to the 32 bit registry for 64 bit installations or to
; the 64 bit registry for 32 bit installations at the beginning so it can ; the 64 bit registry for 32 bit installations at the beginning so it can
@ -2185,6 +2188,7 @@ FunctionEnd
end: end:
${If} ${RunningX64} ${If} ${RunningX64}
${OrIf} ${IsNativeARM64}
${AndIf} "$R0" == "false" ${AndIf} "$R0" == "false"
; Set the registry to the correct view. ; Set the registry to the correct view.
!ifdef HAVE_64BIT_BUILD !ifdef HAVE_64BIT_BUILD
@ -4152,6 +4156,7 @@ FunctionEnd
!ifdef HAVE_64BIT_BUILD !ifdef HAVE_64BIT_BUILD
${Unless} ${RunningX64} ${Unless} ${RunningX64}
${OrUnless} ${IsNativeARM64}
${OrUnless} ${AtLeastWin7} ${OrUnless} ${AtLeastWin7}
MessageBox MB_OK|MB_ICONSTOP "$R9" IDOK MessageBox MB_OK|MB_ICONSTOP "$R9" IDOK
; Nothing initialized so no need to call OnEndCommon ; Nothing initialized so no need to call OnEndCommon
@ -4768,11 +4773,7 @@ FunctionEnd
${LogMsg} "OS Name : Unable to detect" ${LogMsg} "OS Name : Unable to detect"
${EndIf} ${EndIf}
!ifdef HAVE_64BIT_BUILD ${LogMsg} "Target CPU : ${ARCH}"
${LogMsg} "Target CPU : x64"
!else
${LogMsg} "Target CPU : x86"
!endif
Pop $9 Pop $9
Pop $R0 Pop $R0

View file

@ -43,11 +43,16 @@
# ARCH is used when it is necessary to differentiate the x64 registry keys from # ARCH is used when it is necessary to differentiate the x64 registry keys from
# the x86 registry keys (e.g. the uninstall registry key). # the x86 registry keys (e.g. the uninstall registry key).
!ifdef HAVE_64BIT_BUILD !ifdef HAVE_64BIT_BUILD
!define ARCH "x86" !ifdef _ARM64_
!define MinSupportedVer "64-bit Microsoft Windows 7" !define ARCH "AArch64"
!else !define MinSupportedVer "Microsoft Windows 10 for ARM"
!else
!define ARCH "x64" !define ARCH "x64"
!define MinSupportedVer "Microsoft Windows 7" !define MinSupportedVer "64-bit Microsoft Windows 7"
!endif
!else
!define ARCH "x86"
!define MinSupportedVer "Microsoft Windows 7"
!endif !endif
# File details shared by both the installer and uninstaller # File details shared by both the installer and uninstaller

View file

@ -924,6 +924,20 @@ Function .onInit
${InstallOnInitCommon} "$(WARN_MIN_SUPPORTED_OS_MSG)" ${InstallOnInitCommon} "$(WARN_MIN_SUPPORTED_OS_MSG)"
!ifdef HAVE_64BIT_BUILD
${If} "${ARCH}" == "AArch64"
${IfNot} ${IsNativeARM64}
MessageBox MB_OK|MB_ICONSTOP "$(WARN_MIN_SUPPORTED_OS_MSG)" IDOK
; Nothing initialized so no need to call OnEndCommon
Quit
${EndIf}
${ElseIfNot} ${RunningX64}
MessageBox MB_OK|MB_ICONSTOP "$(WARN_MIN_SUPPORTED_OS_MSG)" IDOK
; Nothing initialized so no need to call OnEndCommon
Quit
${EndIf}
!endif
StrCpy $R1 "Zotero Standalone" StrCpy $R1 "Zotero Standalone"
StrCpy $R2 "An older version of Zotero is installed. If you continue, the existing version will be removed.$\n$\nYour Zotero data will not be affected." StrCpy $R2 "An older version of Zotero is installed. If you continue, the existing version will be removed.$\n$\nYour Zotero data will not be affected."
Call UninstallOld Call UninstallOld