From fc4142e1ed9f284867f999a6223969c62c0b0c57 Mon Sep 17 00:00:00 2001 From: Hugo Chesneau Date: Tue, 12 Dec 2023 17:26:58 +0100 Subject: [PATCH 1/6] change MessageBox if path already exist --- constructor/nsis/main.nsi.tmpl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/constructor/nsis/main.nsi.tmpl b/constructor/nsis/main.nsi.tmpl index a2ae2fb2..d76ac611 100644 --- a/constructor/nsis/main.nsi.tmpl +++ b/constructor/nsis/main.nsi.tmpl @@ -844,12 +844,17 @@ Pop $0 Function OnDirectoryLeave ${LogSet} on ${If} ${IsNonEmptyDirectory} "$InstDir" - DetailPrint "::error:: Directory '$INSTDIR' is not empty, please choose a different location." - MessageBox MB_OK|MB_ICONEXCLAMATION \ + DetailPrint "::error:: Directory '$INSTDIR' is not empty." + MessageBox MB_YESNO \ "Directory '$INSTDIR' is not empty,$\n\ - please choose a different location." \ - /SD IDOK - Abort + do you want to upgrade the installation ?" \ + /SD IDYES \ + IDYES confirmed_yes IDNO confirmed_no + confirmed_no: + MessageBox MB_OK|MB_ICONSTOP "Choose another directory." /SD IDOK + Abort + confirmed_yes: + SetOverwrite "ifdiff" ${EndIf} ReadRegStr $LongPathsEnabled HKLM "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" From c2832a95576b22a669db75ec75123354f0c9ec44 Mon Sep 17 00:00:00 2001 From: Hugo Chesneau Date: Thu, 14 Dec 2023 14:44:26 +0100 Subject: [PATCH 2/6] add SetOverwrite "off" if no selected --- constructor/nsis/main.nsi.tmpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/constructor/nsis/main.nsi.tmpl b/constructor/nsis/main.nsi.tmpl index d76ac611..3f7a8fbe 100644 --- a/constructor/nsis/main.nsi.tmpl +++ b/constructor/nsis/main.nsi.tmpl @@ -847,11 +847,12 @@ Function OnDirectoryLeave DetailPrint "::error:: Directory '$INSTDIR' is not empty." MessageBox MB_YESNO \ "Directory '$INSTDIR' is not empty,$\n\ - do you want to upgrade the installation ?" \ + do you want to update the installation ?" \ /SD IDYES \ IDYES confirmed_yes IDNO confirmed_no confirmed_no: MessageBox MB_OK|MB_ICONSTOP "Choose another directory." /SD IDOK + SetOverwrite "off" Abort confirmed_yes: SetOverwrite "ifdiff" From 6bc801c749c6d740a6333ac0a2b74b6ae2dd790b Mon Sep 17 00:00:00 2001 From: Hugo Chesneau Date: Thu, 14 Dec 2023 16:09:49 +0100 Subject: [PATCH 3/6] add a check validity of the target dir when updating --- constructor/nsis/main.nsi.tmpl | 66 +++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/constructor/nsis/main.nsi.tmpl b/constructor/nsis/main.nsi.tmpl index 3f7a8fbe..f505cc0d 100644 --- a/constructor/nsis/main.nsi.tmpl +++ b/constructor/nsis/main.nsi.tmpl @@ -475,6 +475,68 @@ Function InstModePage_Leave Pop $0 FunctionEnd +Function CheckInstdirValidity + Push $0 + Push $1 + Push $2 + Push $3 + + # Resolve INSTDIR + GetFullPathName $0 $INSTDIR + # If the directory does not exist or cannot be resolved, $0 will be empty + StrCmp $0 "" invalid_dir + StrCpy $INSTDIR $0 + + # Never run the un/installer when $INSTDIR points at system-critical directories + + StrLen $InstDirLen $INSTDIR + # INSTDIR is a full path and has no trailing backslash, + # so if its length is 2, it is pointed at a system root + StrCmp $InstdirLen 2 invalid_dir + + # Never delete anything inside Windows + StrCpy $0 $INSTDIR 7 3 + StrCmp $0 "Windows" invalid_dir + + StrCpy $0 "ALLUSERSPROFILE APPDATA LOCALAPPDATA PROGRAMDATA PROGRAMFILES PROGRAMFILES(x86) PUBLIC SYSTEMDRIVE SYSTEMROOT USERPROFILE" + StrCpy $1 1 + loop_critical: + ${WordFind} $0 " " "E+$1" $2 + IfErrors endloop_critical + ReadEnvStr $3 $2 + StrCmp $3 $INSTDIR invalid_dir + IntOp $1 $1 + 1 + goto loop_critical + endloop_critical: + + # Primitive check to see that $INSTDIR points to the right conda directory + StrCpy $0 "_conda.exe conda-meta\history Uninstall-${NAME}" + StrCpy $1 1 + loop_conda: + ${WordFind} $0 " " "E+$1" $2 + IfErrors endloop_conda + IfFileExists $INSTDIR\$2 0 invalid_dir + IntOp $1 $1 + 1 + goto loop_conda + endloop_conda: + + # All checks have passed + goto valid_dir + + invalid_dir: + MessageBox MB_OK|MB_ICONSTOP \ + "Error: $INSTDIR is not a valid conda directory or another conda directory.$\n\ + Please run the installer from a conda directory." \ + /SD IDABORT + abort + valid_dir: + + Pop $3 + Pop $2 + Pop $1 + Pop $0 +FunctionEnd + Function .onInit ${LogSet} on Push $0 @@ -717,7 +779,7 @@ Function un.onInit IfFileExists $INSTDIR\$2 0 invalid_dir IntOp $1 $1 + 1 goto loop_conda - endloop_conda: + endloop_conda: # All checks have passed goto valid_dir @@ -845,6 +907,7 @@ Function OnDirectoryLeave ${LogSet} on ${If} ${IsNonEmptyDirectory} "$InstDir" DetailPrint "::error:: Directory '$INSTDIR' is not empty." + MessageBox MB_YESNO \ "Directory '$INSTDIR' is not empty,$\n\ do you want to update the installation ?" \ @@ -855,6 +918,7 @@ Function OnDirectoryLeave SetOverwrite "off" Abort confirmed_yes: + call CheckInstdirValidity SetOverwrite "ifdiff" ${EndIf} From e8ebff6678173694b94c0e8e85c17d898b981fd8 Mon Sep 17 00:00:00 2001 From: Hugo Chesneau Date: Thu, 14 Dec 2023 16:26:39 +0100 Subject: [PATCH 4/6] Corrected the CheckInstdirValidity --- constructor/nsis/main.nsi.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constructor/nsis/main.nsi.tmpl b/constructor/nsis/main.nsi.tmpl index f505cc0d..e1f294c7 100644 --- a/constructor/nsis/main.nsi.tmpl +++ b/constructor/nsis/main.nsi.tmpl @@ -510,7 +510,7 @@ Function CheckInstdirValidity endloop_critical: # Primitive check to see that $INSTDIR points to the right conda directory - StrCpy $0 "_conda.exe conda-meta\history Uninstall-${NAME}" + StrCpy $0 "_conda.exe conda-meta\history Uninstall-${NAME}.exe" StrCpy $1 1 loop_conda: ${WordFind} $0 " " "E+$1" $2 From c2f2278fcf58068e0d543e54616e4b630e0a0635 Mon Sep 17 00:00:00 2001 From: Hugo Chesneau Date: Fri, 15 Dec 2023 14:43:44 +0100 Subject: [PATCH 5/6] removed the fact that the update has to be in the same repo --- constructor/nsis/main.nsi.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/constructor/nsis/main.nsi.tmpl b/constructor/nsis/main.nsi.tmpl index e1f294c7..cb5b0d39 100644 --- a/constructor/nsis/main.nsi.tmpl +++ b/constructor/nsis/main.nsi.tmpl @@ -510,7 +510,7 @@ Function CheckInstdirValidity endloop_critical: # Primitive check to see that $INSTDIR points to the right conda directory - StrCpy $0 "_conda.exe conda-meta\history Uninstall-${NAME}.exe" + StrCpy $0 "_conda.exe conda-meta\history" StrCpy $1 1 loop_conda: ${WordFind} $0 " " "E+$1" $2 From a9d535b29625ab3e6c986921008c94bd1794a383 Mon Sep 17 00:00:00 2001 From: Hugo Chesneau Date: Fri, 15 Dec 2023 15:05:59 +0100 Subject: [PATCH 6/6] trailing whitespace correction --- constructor/nsis/main.nsi.tmpl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/constructor/nsis/main.nsi.tmpl b/constructor/nsis/main.nsi.tmpl index cb5b0d39..886891a0 100644 --- a/constructor/nsis/main.nsi.tmpl +++ b/constructor/nsis/main.nsi.tmpl @@ -518,7 +518,7 @@ Function CheckInstdirValidity IfFileExists $INSTDIR\$2 0 invalid_dir IntOp $1 $1 + 1 goto loop_conda - endloop_conda: + endloop_conda: # All checks have passed goto valid_dir @@ -779,7 +779,7 @@ Function un.onInit IfFileExists $INSTDIR\$2 0 invalid_dir IntOp $1 $1 + 1 goto loop_conda - endloop_conda: + endloop_conda: # All checks have passed goto valid_dir @@ -910,16 +910,16 @@ Function OnDirectoryLeave MessageBox MB_YESNO \ "Directory '$INSTDIR' is not empty,$\n\ - do you want to update the installation ?" \ + do you want to update the installation ?" \ /SD IDYES \ IDYES confirmed_yes IDNO confirmed_no confirmed_no: - MessageBox MB_OK|MB_ICONSTOP "Choose another directory." /SD IDOK + MessageBox MB_OK|MB_ICONSTOP "Choose another directory." /SD IDOK SetOverwrite "off" - Abort + Abort confirmed_yes: call CheckInstdirValidity - SetOverwrite "ifdiff" + SetOverwrite "ifdiff" ${EndIf} ReadRegStr $LongPathsEnabled HKLM "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled"