Warning, /graphics/digikam/project/bundles/vcpkg/installer/process_running.nsh is written in an unsupported language. File is not indexed.
0001 ;; ============================================================ 0002 ; 0003 ; This file is a part of digiKam project 0004 ; https://www.digikam.org 0005 ; 0006 ; Date : 2005-01-01 0007 ; Description : Functions to check if executable is running. 0008 ; Note: NSIS >= 3 is required to be compatible with Windows 10. 0009 ; 0010 ; SPDX-FileCopyrightText: 2005-2017 by Tim Kosse <tim dot kosse at filezilla-project dot org> 0011 ; SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0012 ; 0013 ; SPDX-License-Identifier: GPL-2.0-or-later 0014 ; 0015 ; ============================================================ ;; 0016 0017 !ifndef EXECUTABLE_RUNNING_INCLUDED 0018 !define EXECUTABLE_RUNNING_INCLUDED 0019 0020 !include "LogicLib.nsh" 0021 0022 ; Returns number of processes * 4 on top of stack, 0023 ; array with all processes right below it. 0024 ; Array should be cleared using System::Free 0025 0026 !macro ENUMPROCESSES un 0027 0028 Function ${un}EnumProcesses 0029 0030 ; Is this really necesssary for $Rx? 0031 Push $R1 0032 Push $R0 0033 Push $R2 0034 Push $R3 0035 0036 ; Double size of array each time EnumProcesses fills it completely so that 0037 ; we do get all processes 0038 0039 StrCpy $R1 1024 0040 0041 enum_processes_loop: 0042 0043 System::Alloc $R1 0044 0045 Pop $R0 0046 0047 System::Call "psapi::EnumProcesses(i R0, i R1, *i .R2) i .R3" 0048 0049 ${If} $R3 == 0 0050 ; EnumProcesses failed, how can that be? :P 0051 goto enum_processes_fail 0052 ${EndIf} 0053 0054 ${If} $R1 == $R2 0055 0056 ; Too small buffer. Retry with twice the size 0057 0058 Intop $R1 $R1 * 2 0059 System::Free $R0 0060 0061 goto enum_processes_loop 0062 0063 ${EndIf} 0064 0065 StrCpy $R1 $R2 0066 0067 ; Restore registers 0068 ; and put results on stack 0069 Pop $R3 0070 Pop $R2 0071 Exch $R0 0072 Exch 0073 Exch $R1 0074 return 0075 0076 enum_processes_fail: 0077 0078 Pop $R3 0079 Pop $R2 0080 Pop $R0 0081 Pop $R1 0082 0083 Push 0 0084 Push 0 0085 0086 FunctionEnd 0087 0088 !macroend 0089 0090 ; Insert function as an installer and uninstaller function. 0091 !insertmacro ENUMPROCESSES "" 0092 !insertmacro ENUMPROCESSES "un." 0093 0094 ;------------------------------------------- 0095 0096 ; Expects process ID on top of stack, returns 0097 ; filename (in device syntax) on top of stack 0098 0099 !macro GETFILENAMEFROMPROCESSID un 0100 0101 Function ${un}GetFilenameFromProcessId 0102 0103 Exch $R0 0104 Push $R1 0105 Push $R2 0106 Push $R3 0107 0108 !define ${un}PROCESS_QUERY_INFORMATION 0x0400 0109 System::Call "kernel32::OpenProcess(i ${${un}PROCESS_QUERY_INFORMATION}, i 0, i $R0) i .R0" 0110 0111 ${If} $R0 == 0 0112 0113 Pop $R3 0114 Pop $R2 0115 Pop $R1 0116 Pop $R0 0117 Push '' 0118 return 0119 0120 ${EndIf} 0121 0122 StrCpy $R3 ${NSIS_MAX_STRLEN} 0123 System::Call "kernel32::QueryFullProcessImageName(i R0, i 0, t .R1, *i R3) i .R2" 0124 0125 ${If} $R2 == 0 0126 ; Fallback 0127 System::Call "psapi::GetProcessImageFileName(i R0, t .R1, i ${NSIS_MAX_STRLEN}) i .R2" 0128 ${EndIf} 0129 0130 ${If} $R2 == 0 0131 0132 System::Call "kernel32::CloseHandle(i R0)" 0133 Pop $R3 0134 Pop $R2 0135 Pop $R1 0136 Pop $R0 0137 Push '' 0138 0139 return 0140 0141 ${EndIf} 0142 0143 System::Call "kernel32::CloseHandle(i R0)" 0144 0145 Pop $R3 0146 Pop $R2 0147 StrCpy $R0 $R1 0148 Pop $R1 0149 Exch $R0 0150 0151 FunctionEnd 0152 0153 !macroend 0154 0155 ; Insert function as an installer and uninstaller function. 0156 !insertmacro GETFILENAMEFROMPROCESSID "" 0157 !insertmacro GETFILENAMEFROMPROCESSID "un." 0158 0159 ;------------------------------------------- 0160 0161 ; Expects process name on top of stack. Afterwards, top of stack contains path 0162 ; to the process if it's running or an empty string if it is not. 0163 0164 !macro ISPROCESSRUNNING un 0165 0166 Function ${un}IsProcessRunning 0167 0168 Exch $R0 ; Name 0169 0170 Push $R1 ; Bytes 0171 Push $R2 ; Array 0172 Push $R3 ; Counter 0173 Push $R4 ; Strlen 0174 Push $R5 ; Current process ID and image filename 0175 Push $R6 ; Last part of path 0176 0177 StrCpy $R0 "\$R0" 0178 0179 StrLen $R4 $R0 0180 IntOp $R4 0 - $R4 0181 0182 Call ${un}EnumProcesses 0183 0184 Pop $R1 0185 Pop $R2 0186 0187 StrCpy $R3 0 0188 0189 ${While} $R3 < $R1 0190 0191 IntOp $R5 $R2 + $R3 0192 0193 System::Call "*$R5(i .R5)" 0194 Push $R5 0195 0196 Call ${un}GetFilenameFromProcessId 0197 0198 Pop $R5 0199 0200 ; Get last part of filename 0201 StrCpy $R6 $R5 '' $R4 0202 0203 ${If} $R6 == $R0 0204 0205 ; Program is running 0206 StrCpy $R0 $R5 0207 Pop $R6 0208 Pop $R5 0209 Pop $R4 0210 Pop $R3 0211 Pop $R2 0212 Pop $R1 0213 Exch $R0 0214 return 0215 0216 ${EndIf} 0217 0218 IntOp $R3 $R3 + 4 0219 0220 ${EndWhile} 0221 0222 Pop $R5 0223 Pop $R4 0224 Pop $R3 0225 Pop $R2 0226 Pop $R1 0227 Pop $R0 0228 Push '' 0229 0230 FunctionEnd 0231 0232 !macroend 0233 0234 ; Insert function as an installer and uninstaller function. 0235 !insertmacro ISPROCESSRUNNING "" 0236 !insertmacro ISPROCESSRUNNING "un." 0237 0238 ;------------------------------------------- 0239 0240 !macro CHECKDIGIKAM un 0241 0242 Function ${un}CheckDigikamRunning 0243 0244 Push "digikam.exe" 0245 Call ${un}IsProcessRunning 0246 Pop $R1 0247 0248 ${While} $R1 != '' 0249 0250 MessageBox MB_ABORTRETRYIGNORE|MB_DEFBUTTON2 "digiKam appears to be running.$\nPlease close all running instances of digiKam before continuing the installation." /SD IDIGNORE IDABORT CheckDigikamRunning_abort IDIGNORE CheckDigikamRunning_ignore 0251 0252 Push "digikam.exe" 0253 Call ${un}IsProcessRunning 0254 Pop $R1 0255 0256 ${EndWhile} 0257 0258 CheckDigikamRunning_ignore: 0259 Return 0260 0261 CheckDigikamRunning_abort: 0262 Quit 0263 0264 FunctionEnd 0265 0266 !macroend 0267 0268 ; Insert function as an installer and uninstaller function. 0269 !insertmacro CHECKDIGIKAM "" 0270 !insertmacro CHECKDIGIKAM "un." 0271 0272 ;------------------------------------------- 0273 0274 !macro CHECKSHOWFOTO un 0275 0276 Function ${un}CheckShowfotoRunning 0277 0278 Push "showfoto.exe" 0279 Call ${un}IsProcessRunning 0280 Pop $R1 0281 0282 ${While} $R1 != '' 0283 0284 MessageBox MB_ABORTRETRYIGNORE|MB_DEFBUTTON2 "Showfoto appears to be running.$\nPlease close all running instances of Showfoto before continuing the installation." /SD IDIGNORE IDABORT CheckShowfotoRunning_abort IDIGNORE CheckShowfotoRunning_ignore 0285 0286 Push "showfoto.exe" 0287 Call ${un}IsProcessRunning 0288 Pop $R1 0289 0290 ${EndWhile} 0291 0292 CheckShowfotoRunning_ignore: 0293 Return 0294 0295 CheckShowfotoRunning_abort: 0296 Quit 0297 0298 FunctionEnd 0299 0300 !macroend 0301 0302 ; Insert function as an installer and uninstaller function. 0303 !insertmacro CHECKSHOWFOTO "" 0304 !insertmacro CHECKSHOWFOTO "un." 0305 0306 ;------------------------------------------- 0307 0308 !endif ;EXECUTABLE_RUNNING_INCLUDED