From 94daedaaedd3eceb8cf41a2238ee10fe6280f37c Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Fri, 28 Jan 2022 20:04:59 +0200
Subject: [PATCH] SL-16681 Better handling of locked files by NSIS Installer

1. When SL window closes it doesn't mean that process died so gave it a bit more time to terminate
2. Added a retry logic in case first run happened too early for some reason
3. Replaced ok/cancel on locked file with abort/retry/ignorei
---
 .../installers/windows/installer_template.nsi |  32 ++++++++++++++----
 indra/newview/installers/windows/lang_da.nsi  | Bin 12128 -> 11992 bytes
 indra/newview/installers/windows/lang_de.nsi  |   2 +-
 .../newview/installers/windows/lang_en-us.nsi | Bin 11802 -> 11666 bytes
 indra/newview/installers/windows/lang_es.nsi  | Bin 13112 -> 12976 bytes
 indra/newview/installers/windows/lang_fr.nsi  | Bin 13628 -> 13492 bytes
 indra/newview/installers/windows/lang_it.nsi  | Bin 12850 -> 12714 bytes
 indra/newview/installers/windows/lang_ja.nsi  | Bin 10016 -> 9880 bytes
 indra/newview/installers/windows/lang_pl.nsi  | Bin 12448 -> 12312 bytes
 .../newview/installers/windows/lang_pt-br.nsi | Bin 13272 -> 13136 bytes
 indra/newview/installers/windows/lang_ru.nsi  | Bin 12586 -> 12450 bytes
 indra/newview/installers/windows/lang_tr.nsi  | Bin 12496 -> 12360 bytes
 indra/newview/installers/windows/lang_zh.nsi  | Bin 9460 -> 9324 bytes
 13 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/indra/newview/installers/windows/installer_template.nsi b/indra/newview/installers/windows/installer_template.nsi
index 668a8025bdf..7513908cb4f 100644
--- a/indra/newview/installers/windows/installer_template.nsi
+++ b/indra/newview/installers/windows/installer_template.nsi
@@ -561,10 +561,17 @@ Function CloseSecondLife
 
   LOOP:
 	  FindWindow $0 "Second Life" ""
-	  IntCmp $0 0 DONE
+	  IntCmp $0 0 SLEEP
 	  Sleep 500
 	  Goto LOOP
-
+	  
+  SLEEP:
+    # Second life window just closed, but program might not be fully done yet
+    # and OS might have not released some locks, wait a bit more to make sure
+    # all file handles were released.
+	# If something still isn't unlocked, it will trigger a notification from
+	# RemoveProgFilesOnInst
+    Sleep 1000
   DONE:
     Pop $0
     Return
@@ -611,6 +618,12 @@ Function RemoveProgFilesOnInst
 # RMDir /r $INSTDIR is especially unsafe if user installed somewhere
 # like Program Files
 
+# Set retry counter. All integers are strings.
+Push $0
+StrCpy $0 0
+
+PREINSTALLREMOVE:
+
 # Remove old SecondLife.exe to invalidate any old shortcuts to it that may be in non-standard locations. See MAINT-3575
 Delete "$INSTDIR\$INSTEXE"
 Delete "$INSTDIR\$VIEWER_EXE"
@@ -627,19 +640,26 @@ RMDir /r "$INSTDIR\vmp_icons"
 # find modules from different versions
 RMDir /r "$INSTDIR\llplugin"
 
-IfErrors 0 PREINSTALLCLEAN
-  StrCmp $SKIP_DIALOGS "true" PREINSTALLCLEAN
-    MessageBox MB_OKCANCEL $(CloseSecondLifeInstRM) IDOK PREINSTALLCLEAN IDCANCEL PREINSTALLFAIL
+IntOp $0 $0 + 1
+
+IfErrors 0 PREINSTALLDONE
+  IntCmp $0 1 PREINSTALLREMOVE #try again once
+    StrCmp $SKIP_DIALOGS "true" PREINSTALLDONE
+      MessageBox MB_ABORTRETRYIGNORE $(CloseSecondLifeInstRM) IDABORT PREINSTALLFAIL IDRETRY PREINSTALLREMOVE
+      # MB_ABORTRETRYIGNORE does not accept IDIGNORE
+      Goto PREINSTALLDONE
 
 PREINSTALLFAIL:
     Quit
 
-PREINSTALLCLEAN:
+PREINSTALLDONE:
 
 # We are no longer including release notes with the viewer, so remove them.
 Delete "$SMPROGRAMS\$INSTSHORTCUT\SL Release Notes.lnk"
 Delete "$INSTDIR\releasenotes.txt"
 
+Pop $0
+
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/indra/newview/installers/windows/lang_da.nsi b/indra/newview/installers/windows/lang_da.nsi
index 0b5ae2b714d97104c4bffaadbe63425d947b32c7..648ddbfb8502e1bee254d26c8c01ce8e40d1026c 100644
GIT binary patch
delta 16
YcmaD5cO!Pg0_Dj%3Qn7|RK9Tm07V%GNdN!<

delta 106
zcmcZ+`yg(^0%chhh8TuC1_&9<kjjt)#K{aL3<?bX4BnFk6(o)Iu*y0!I5PM#I5W61
i_yE<GFysTtWQIhbS;-8klMiwUPc~4K+PqF#iyHvvXBL(K

diff --git a/indra/newview/installers/windows/lang_de.nsi b/indra/newview/installers/windows/lang_de.nsi
index e67bc9e22c7..188c30197a4 100755
--- a/indra/newview/installers/windows/lang_de.nsi
+++ b/indra/newview/installers/windows/lang_de.nsi
@@ -64,7 +64,7 @@ LangString MissingSSE2 ${LANG_GERMAN} "Dieses Gerät verfügt möglicherweise ni
 ; closesecondlife function (install)
 LangString CloseSecondLifeInstDP ${LANG_GERMAN} "Warten auf die Beendigung von Second Life ..."
 LangString CloseSecondLifeInstMB ${LANG_GERMAN} "Second Life kann nicht installiert oder ersetzt werden, wenn es bereits läuft.$\n$\nBeenden Sie, was Sie gerade tun und klicken Sie OK, um Second Life zu beenden.$\nKlicken Sie CANCEL, um die Installation abzubrechen."
-LangString CloseSecondLifeInstRM ${LANG_GERMAN} "Second Life failed to remove some files from a previous install.$\n$\nSelect OK to continue.$\nSelect CANCEL to cancel installation."
+LangString CloseSecondLifeInstRM ${LANG_GERMAN} "Second Life failed to remove some files from a previous install."
 
 ; closesecondlife function (uninstall)
 LangString CloseSecondLifeUnInstDP ${LANG_GERMAN} "Warten auf die Beendigung von Second Life ..."
diff --git a/indra/newview/installers/windows/lang_en-us.nsi b/indra/newview/installers/windows/lang_en-us.nsi
index f75ecfaf08f309a294d39d8a491922e5101fbd6c..0639d51e10fc489a37312db071c7177bf4c151c6 100644
GIT binary patch
delta 12
TcmbOgGbwt*JH^dqN=vu_C-()N

delta 34
mcmbOfJu7CzJ4Id<h8TuC1_&8EIbK0}@-l^#&7Tw(a039rg$p_W

diff --git a/indra/newview/installers/windows/lang_es.nsi b/indra/newview/installers/windows/lang_es.nsi
index 2b9fa6119986f819a599ec913da3c59c28756a78..ee30651a38983aec3b199fb9f7c27adf122d595d 100755
GIT binary patch
delta 16
Xcmdmywjp&xklJJeC8y0Y>M}e4J6Z*y

delta 110
zcmdmxx+85vkeaCqLkvS61B47_NM*<Y;$(&r1_cIx25%r)!jKOnlYwL&kevx6OBqrp
mD{2ZWgVZ=PI5PMFNmm9RB(;e^RmmW;Cco#9-W;Hozykmq<QE?R

diff --git a/indra/newview/installers/windows/lang_fr.nsi b/indra/newview/installers/windows/lang_fr.nsi
index 4e256a3af96cd001b5c5e187275ff42906ed1cf7..7cd90ec3148fdd30e01e9c2aee2408511618eb67 100755
GIT binary patch
delta 16
Ycmdm!wIy={hsI<UX@SiPH0JOC06BgJ2><{9

delta 136
zcmdmzxhHD_hla8WLkvS61B47_NM*<Y;$(&r1_cIx25%r)!jM1tp|Y^K9#%EZ42}$b
z49*O$3_cLGKr)#j5olsE*er#~je?Ss71UWKduj7b=1?)2%p+$o*-leqa+aLh<`Wuk
FxB;<c9vJ`t

diff --git a/indra/newview/installers/windows/lang_it.nsi b/indra/newview/installers/windows/lang_it.nsi
index bf4f51e3260be81cae28e9c4f2bf8f668d17438e..194062da9a8ea42fb5bb5265b974764fdb9d263e 100755
GIT binary patch
delta 12
Tcmdm#vMPB)o$6*bH60!RB@6_P

delta 128
zcmZ3LyeVZvoocoULkvS61B47_NM*<Y;$(&r1_cIx25%r)!jKOnlYwL&kevx6OMxo%
nu<CGTaAfdfaAt62@Ilg<2-K4dGI?^Lfav52oNSwGRP}fO$axwR

diff --git a/indra/newview/installers/windows/lang_ja.nsi b/indra/newview/installers/windows/lang_ja.nsi
index 02d9ae2b40d1b5799b96779fecbf1a44950793fa..a54005ba1466c4e82247fa46d144ad9037b00262 100755
GIT binary patch
delta 12
TcmZ4BH^X<s2ieUPaw|9hCt3xH

delta 144
zcmbQ?yTEV52ibZRh8TuC1_&9<kjjt)#K{aL3<?bX4BkMpgdrbDCIiVlAUhLCmI77i
wVb$Tx;K<;|;LPC4;De+y5vV5_Y_bAae=*RUM4&x6K(b_VKRf&8ce1NE0Do2;<p2Nx

diff --git a/indra/newview/installers/windows/lang_pl.nsi b/indra/newview/installers/windows/lang_pl.nsi
index 4c254b4b2c393c91de7b69aab5a14fa9c9cd2e24..355d806866959266519b0c3069ac600ff23a0c29 100644
GIT binary patch
delta 12
TcmZ3GI3r<0h|1<WDo3~hCYc4K

delta 144
zcmbP{upn_mh)TT*LkvS61B47_NM*<Y;$(&r1_cIx25%r)!jKOnlYwL&kevx6OMxo%
wu<CGTaAfdfaAt62@Ilg<2-K4dHdz6zzZhsvBG8^3AXze5Ux<BkkjgP`06wW4s{jB1

diff --git a/indra/newview/installers/windows/lang_pt-br.nsi b/indra/newview/installers/windows/lang_pt-br.nsi
index 1e9e0b07d212b93301b1c765048eb2d77058b76f..97f5d2b44a946ea8d58ae8eec42a1a966d4d30a3 100755
GIT binary patch
delta 27
jcmcbSej#mxociQnN=}o{$Qn#GP?4FW$+Ou(V+J<>s!Ixx

delta 124
zcmcbRb|Za*oO-qjLkvS61B47_NM*<Y;$(&r1_cIx25%r)!jKOnlYwL&kevx6OMxo%
ju<CGTaAfdfaAt62@Ilg<2-K4dGI{cUVd>2>>Lxq@U;-Hx

diff --git a/indra/newview/installers/windows/lang_ru.nsi b/indra/newview/installers/windows/lang_ru.nsi
index 8ca1fc3d14b0a00198dc3ce8fc473e2a3b28d56b..65a9f4846d42a2331b25181fe99750e6e7e7682c 100755
GIT binary patch
delta 16
XcmZ3Lv?y_df$C%}MW@ZbR1LTRJ17Q1

delta 124
zcmZ3KxGHIbfoir2LkvS61B47_NM*<Y;$(&r1_cIx25%r)!jKOnlYwL&kevx6OMxo%
ju<CGTaAfdfaAt62@Ilg<2-K4dGI_Eir}Sn$)e>$1F$Wk%

diff --git a/indra/newview/installers/windows/lang_tr.nsi b/indra/newview/installers/windows/lang_tr.nsi
index db6f417fc2dc5c3dfa5f7a14827aabcaa905dc8a..e71886cc6609f89a090c31a2c5d9c6cb714dc907 100755
GIT binary patch
delta 16
YcmcbRcp_m#iOS>&3Qn8tR3~u*07G8}+5i9m

delta 124
zcmX?+a3OI+iAuH#LkvS61B47_NM*<Y;$(&r1_cIx25%r)!jKOnlYwL&kevx6OMxo%
ju<CGTaAfdfaAt62@Ilg<2-K4dGI_GUko4vvm22Dpc0C!7

diff --git a/indra/newview/installers/windows/lang_zh.nsi b/indra/newview/installers/windows/lang_zh.nsi
index fad714e83b010372a2b96c9b3dc4464ea565117a..f5f0c6cbdf6539d8683151de663a23a58ede11c1 100755
GIT binary patch
delta 12
Tcmez3`Nm^Im)K?@@khJ>Dh36O

delta 154
zcmaFk@x^mPmsq_DLkvS61B47_NM*<Y;$(&r1_cIx25%r)!jKOnlYwL&kevx6OMxo%
zu<CGTaAfdfaAt62@Ilg<2-K4dHdz6zzZhsvBG8^3AX&l*6apEo$1r(<fW+oSVyAck
Dx`!Wt

-- 
GitLab