Add a detection on non empty folder before installing the application.

This commit is contained in:
Julien Wadel 2024-11-26 20:39:20 +01:00
parent df6f39addc
commit ad4e675f66

View file

@ -504,8 +504,46 @@ Function ConditionalAddToRegisty
ConditionalAddToRegisty_EmptyString:
FunctionEnd
Function isEmptyDir
# Stack -> # Stack: <directory>
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