From ad4e675f66d79b71034efe8b3a9d7901c60e6bcb Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 26 Nov 2024 20:39:20 +0100 Subject: [PATCH] Add a detection on non empty folder before installing the application. --- cmake/install/windows/NSIS.template.in | 43 ++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/cmake/install/windows/NSIS.template.in b/cmake/install/windows/NSIS.template.in index 4bfdfe54f..4c8d94bc9 100644 --- a/cmake/install/windows/NSIS.template.in +++ b/cmake/install/windows/NSIS.template.in @@ -504,8 +504,46 @@ Function ConditionalAddToRegisty ConditionalAddToRegisty_EmptyString: FunctionEnd + +Function isEmptyDir + # Stack -> # Stack: + Exch $0 # Stack: $0 + Push $1 # Stack: $1, $0 + FindFirst $0 $1 "$0\*.*" + strcmp $1 "." 0 _notempty + FindNext $0 $1 + strcmp $1 ".." 0 _notempty + ClearErrors + FindNext $0 $1 + IfErrors 0 _notempty + FindClose $0 + Pop $1 # Stack: $0 + StrCpy $0 1 + Exch $0 # Stack: 1 (true) + goto _end + _notempty: + FindClose $0 + ClearErrors + Pop $1 # Stack: $0 + StrCpy $0 0 + Exch $0 # Stack: 0 (false) + _end: +FunctionEnd + +Function InstDirValidation + IfFileExists $INSTDIR\* 0 isEmpty + Push "$INSTDIR" + Call isEmptyDir + Pop $0 + StrCmp $0 0 0 isEmpty + MessageBox MB_OK "$INSTDIR is not empty. Please delete it and retry." + Abort + isEmpty: +FunctionEnd + ;-------------------------------- + !ifdef CPACK_USES_DOWNLOAD Function DownloadFile IfFileExists $INSTDIR\* +2 @@ -555,6 +593,8 @@ FunctionEnd !endif Page custom InstallOptionsPage + + !define MUI_PAGE_CUSTOMFUNCTION_LEAVE InstDirValidation !insertmacro MUI_PAGE_DIRECTORY ;Start Menu Folder Page Configuration @@ -911,9 +951,6 @@ SectionEnd ; "Program Files" for AllUsers, "My Documents" for JustMe... - - - Function .onInit ClearErrors ExecWait '"cmd" /C ""%SystemRoot%\System32\tasklist" /NH /FI "IMAGENAME eq @CPACK_NSIS_MUI_FINISHPAGE_RUN@" | "%SystemRoot%\System32\find" /I /C "@CPACK_NSIS_MUI_FINISHPAGE_RUN@""' $0