From c0a899866876f1b1363b0e8fd1ca3b5ee8f462e5 Mon Sep 17 00:00:00 2001 From: ctrlaltca Date: Sun, 17 Mar 2024 17:54:19 +0100 Subject: [PATCH] NSIS: make the installer wait for the uninstall to finish before proceeding; fix #2546 (#2619) --- cmake/KVIrc.nsi.cmake | 53 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/cmake/KVIrc.nsi.cmake b/cmake/KVIrc.nsi.cmake index 3123cc6fd..b4e68b4ab 100644 --- a/cmake/KVIrc.nsi.cmake +++ b/cmake/KVIrc.nsi.cmake @@ -79,6 +79,48 @@ LangString WinVerUnsupported ${LANG_ENGLISH} "KVIrc does not support the current !include ".\translations\*.nsi" +Function TrimQuotes +Exch $R0 +Push $R1 + + StrCpy $R1 $R0 1 + StrCmp $R1 `"` 0 +2 + StrCpy $R0 $R0 `` 1 + StrCpy $R1 $R0 1 -1 + StrCmp $R1 `"` 0 +2 + StrCpy $R0 $R0 -1 + +Pop $R1 +Exch $R0 +FunctionEnd + +Function GetParent + + Exch $R0 + Push $R1 + Push $R2 + Push $R3 + + StrCpy $R1 0 + StrLen $R2 $R0 + + loop: + IntOp $R1 $R1 + 1 + IntCmp $R1 $R2 get 0 get + StrCpy $R3 $R0 1 -$R1 + StrCmp $R3 "\" get + Goto loop + + get: + StrCpy $R0 $R0 -$R1 + + Pop $R3 + Pop $R2 + Pop $R1 + Exch $R0 + +FunctionEnd + ;-------------------------------- ; Sections @@ -193,7 +235,16 @@ check64: ;Run the uninstaller uninst: ClearErrors - ExecWait "$R0" + ; R0 contains the quoted full path to uninstall.exe + Push $R0 + Call TrimQuotes + Call GetParent + Pop $R0 + ; at this point $R0 will equal to "C:\Program Files\KVirc" + InitPluginsDir + CreateDirectory "$pluginsdir\unold" + CopyFiles /SILENT /FILESONLY "$R0\uninstall.exe" "$pluginsdir\unold" + ExecWait '"$pluginsdir\unold\uninstall.exe" _?=$R0' done: