| 1 |
;; ============================================================ |
| 2 |
; |
| 3 |
; This file is a part of digiKam project |
| 4 |
; https://www.digikam.org |
| 5 |
; |
| 6 |
; Date : 2005-01-01 |
| 7 |
; Description : Functions to catch NSIS events. |
| 8 |
; Note: NSIS >= 3 is required to be compatible with Windows 10. |
| 9 |
; |
| 10 |
; SPDX-FileCopyrightText: 2010-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 11 |
; |
| 12 |
; SPDX-License-Identifier: GPL-2.0-or-later |
| 13 |
; |
| 14 |
; ============================================================ ;; |
| 15 |
|
| 16 |
!ifndef EVENTS_FUNCTIONS_INCLUDED |
| 17 |
!define EVENTS_FUNCTIONS_INCLUDED |
| 18 |
|
| 19 |
Function .onInit |
| 20 |
|
| 21 |
;Do not permit to install 64 bits to 32 bits. |
| 22 |
|
| 23 |
${IfNot} ${RunningX64} |
| 24 |
|
| 25 |
MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST|MB_SETFOREGROUND "This is the 64 bits installer, and it cannot be installed to a 32 bits system." |
| 26 |
SetErrorLevel 2 |
| 27 |
Quit |
| 28 |
|
| 29 |
${EndIf} |
| 30 |
|
| 31 |
;Default installation folder depending of target architecture. |
| 32 |
|
| 33 |
${If} $InstDir == "" ; Don't override setup.exe /D=c:\custom\dir |
| 34 |
StrCpy $InstDir "$PROGRAMFILES64\${MY_PRODUCT}" |
| 35 |
${EndIf} |
| 36 |
|
| 37 |
Push $0 |
| 38 |
UserInfo::GetAccountType |
| 39 |
Pop $0 |
| 40 |
|
| 41 |
${If} $0 != "admin" |
| 42 |
|
| 43 |
;Require admin rights on NT4+ |
| 44 |
|
| 45 |
MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST|MB_SETFOREGROUND "Administrator privileges required!$\r$\n$\r$\nPlease restart the installer using an administrator account." |
| 46 |
SetErrorLevel 740 ; ERROR_ELEVATION_REQUIRED |
| 47 |
Quit |
| 48 |
|
| 49 |
${EndIf} |
| 50 |
|
| 51 |
Pop $0 |
| 52 |
|
| 53 |
Push $R0 |
| 54 |
Push $R1 |
| 55 |
Push $R2 |
| 56 |
|
| 57 |
checkUninstallRequired: |
| 58 |
|
| 59 |
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_PRODUCT}" "UninstallString" |
| 60 |
${StrRep} $R0 $R0 '"' "" ; Remove double-quotes so Delete and RMDir work properly and we can extract the path |
| 61 |
StrCmp $R0 "" done |
| 62 |
|
| 63 |
${IfNot} ${FileExists} $R0 |
| 64 |
|
| 65 |
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_PRODUCT}" |
| 66 |
Goto checkUninstallRequired |
| 67 |
|
| 68 |
${EndIf} |
| 69 |
|
| 70 |
;Get path |
| 71 |
|
| 72 |
${StrStrAdv} $R1 $R0 "\" "<" "<" "0" "0" "0" |
| 73 |
|
| 74 |
ReadRegStr $R2 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MY_PRODUCT}" "DisplayName" ; DisplayName contains version |
| 75 |
|
| 76 |
;TODO: need to internationalize string (see VLC / clementine / etc) |
| 77 |
|
| 78 |
MessageBox MB_YESNO|MB_ICONEXCLAMATION|MB_TOPMOST|MB_SETFOREGROUND "$R2 is currently installed but only a single instance of ${MY_PRODUCT} can be installed at any time.$\r$\n$\r$\n\ |
| 79 |
Note: only the application binary files will be removed from your system at this stage. Your collections and database files kept untouched.$\r$\n$\r$\n\ |
| 80 |
Important: database schemas can be upgraded between major releases, so it's recommended to backup all database files before to start a new digiKam session after this install.$\r$\n$\r$\n\ |
| 81 |
Do you want to uninstall the current instance of ${MY_PRODUCT} and continue installing ${MY_PRODUCT} ${VERSION}?" /SD IDYES IDNO noInstall |
| 82 |
|
| 83 |
;Run the uninstaller |
| 84 |
|
| 85 |
ClearErrors |
| 86 |
|
| 87 |
IfSilent 0 notSilent |
| 88 |
|
| 89 |
ExecWait '"$R0" /S _?=$R1' ; Do not copy the uninstaller to a temp file |
| 90 |
Goto uninstDone |
| 91 |
|
| 92 |
notSilent: |
| 93 |
|
| 94 |
ExecWait '"$R0" _?=$R1' ; Do not copy the uninstaller to a temp file |
| 95 |
|
| 96 |
uninstDone: |
| 97 |
|
| 98 |
IfErrors checkUninstallRequired |
| 99 |
Delete "$R0" ; If uninstall successful, remove uninstaller |
| 100 |
RMDir "$R1" ; remove previous install directory |
| 101 |
Goto checkUninstallRequired |
| 102 |
|
| 103 |
noInstall: |
| 104 |
Abort |
| 105 |
|
| 106 |
done: |
| 107 |
Pop $R2 |
| 108 |
Pop $R1 |
| 109 |
Pop $R0 |
| 110 |
|
| 111 |
FunctionEnd |
| 112 |
|
| 113 |
;------------------------------------------- |
| 114 |
|
| 115 |
Function .onInstSuccess |
| 116 |
|
| 117 |
nsExec::ExecToLog /TIMEOUT=2000 '"$instdir\kbuildsycoca6.exe --noincremental"' |
| 118 |
|
| 119 |
FunctionEnd |
| 120 |
|
| 121 |
;------------------------------------------------------------------------------------- |
| 122 |
|
| 123 |
Function functionFinishRun |
| 124 |
|
| 125 |
; Execute the file with non-elevated rights. |
| 126 |
|
| 127 |
Exec '"$WINDIR\explorer.exe" "$instdir\digikam.exe"' |
| 128 |
|
| 129 |
FunctionEnd |
| 130 |
|
| 131 |
!endif ;EVENTS_FUNCTIONS_INCLUDED |