Skip to content

Commit

Permalink
Warn user if the install directory is not empty
Browse files Browse the repository at this point in the history
Closes #452
  • Loading branch information
dail8859 committed Oct 7, 2023
1 parent bb4f83b commit 6befd63
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
35 changes: 35 additions & 0 deletions installer/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ SetCompressor /SOLID lzma
!insertmacro MUI_PAGE_LICENSE "..\LICENSE"
!insertmacro MULTIUSER_PAGE_INSTALLMODE
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE VerifyInstallDirEmpty
!insertmacro MUI_PAGE_DIRECTORY # In which folder install page.
!define MUI_PAGE_CUSTOMFUNCTION_SHOW "CheckIfRunning"
!insertmacro MUI_PAGE_INSTFILES # Installing page.
Expand Down Expand Up @@ -100,6 +101,37 @@ Function PageWelcomeLicensePre
${endif}
FunctionEnd

Function VerifyInstallDirEmpty
Push $INSTDIR
Call isEmptyDir
Pop $0

${If} $0 == 0
${AndIf} ${FileExists} "$INSTDIR\*"
SetRegView 64

# The uninstaller will run prior to executing the installer (but has not been ran yet)
# so if it is getting installed to the same location as the prior version, it is fine.
ReadRegStr $R0 SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\NotepadNext" "InstallLocation"

# The directory is the same as the previous version, so no need to worry.
${If} $R0 == $INSTDIR
Goto done
${EndIf}

MessageBox MB_ICONEXCLAMATION|MB_YESNO \
`"$INSTDIR" already exists and is not empty! \
This installer will delete all files and folders in that directory before \
installing!$\n$\n\
Do you want to continue?` \
/SD IDYES \
IDYES done
Abort
${EndIf}
done:
FunctionEnd


Function .onInit
${ifnot} ${UAC_IsInnerInstance}
!insertmacro CheckSingleInstance "Setup" "Global" "NotepadNextSetupMutex"
Expand Down Expand Up @@ -143,6 +175,9 @@ Section "Notepad Next"
SectionIn RO
SetOutPath $INSTDIR

# Make sure it is empty
RMDir /r $INSTDIR

File /r /x libcrypto-1_1-x64.dll /x libssl-1_1-x64.dll ..\build\package\*

SetRegView 64
Expand Down
28 changes: 27 additions & 1 deletion installer/utils.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,30 @@
Quit
NotRunning:
FunctionEnd
!macroend
!macroend

# From http://nsis.sourceforge.net/Check_if_dir_is_empty
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

0 comments on commit 6befd63

Please sign in to comment.