From ec758d123702a5aed2a8f34bbfa21d5f30a570e1 Mon Sep 17 00:00:00 2001
From: "kali kaneko (leap communications)" <kali@leap.se>
Date: Wed, 29 Apr 2020 17:13:34 +0200
Subject: [PATCH] [pkg] fix upgrade from 0.20.1

---
 branding/templates/windows/template.nsi | 29 +++++++++++++------------
 docker/Makefile                         |  2 +-
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/branding/templates/windows/template.nsi b/branding/templates/windows/template.nsi
index 6fa189b2..ee72009b 100755
--- a/branding/templates/windows/template.nsi
+++ b/branding/templates/windows/template.nsi
@@ -56,39 +56,40 @@ RequestExecutionLevel admin
 
 Section "InstallFiles"
   ; first we try to delete the helper (it can be the old one or a previous version of the new one)
-  DetailPrint "Trying to uninstall any older helper..."
-  ClearErrors
-  Delete 'C:\Program Files\$applicationName\bitmask_helper.exe'
-
   DetailPrint "Trying to uninstall new helper..."
-  ClearErrors
+  IfFileExists $INSTDIR\helper.exe 0 +4
   ExecWait '"$INSTDIR\helper.exe" stop'
   ExecWait '"$INSTDIR\helper.exe" remove'
-  ClearErrors
   Delete 'C:\Program Files\$applicationName\helper.exe'
-  ;IfErrors 0 noErrorHelper
 
   ; uninstalling old nssm helper - could fail if it isn't there, or if nssm is not there...
   ClearErrors
   DetailPrint "Trying to uninstall an old style helper..."
+  IfFileExists $INSTDIR\bitmask_helper.exe 0 +8
   ExecWait '"$INSTDIR\nssm.exe" stop $applicationNameLower-helper'
   ExecWait '"$INSTDIR\nssm.exe" remove $applicationNameLower-helper confirm'
-  ;IfErrors 0 noErrorHelper
-  DetailPrint "Failed to stop nssm-style helper, maybe it was not there"
+  ClearErrors
+  Sleep 1000
+  Delete 'C:\Program Files\$applicationName\bitmask_helper.exe'
+  IfErrors 0 +2
+  DetailPrint "Failed to delete nssm-style helper, maybe it was not there"
 
   ; let's try to stop it in case it's the new style helper -- we need to do it to be able to overwrite it.
   ; we don't care about errors because if we're upgrading from 0.20.1 this will not work.
   ClearErrors
   DetailPrint "Trying to uninstall a new style helper..."
-  ExecWait '"$INSTDIR\bitmask_helper.exe" stop'
-  ;IfErrors 0 noErrorHelper
-  DetailPrint "Failed to stop new-style helper, maybe it was not there"
-
-  ;noErrorHelper:
+  IfFileExists $INSTDIR\bitmask_helper.exe 0 +4
+  Exec '"$INSTDIR\bitmask_helper.exe" stop'
+  IfErrors 0 noErrorHelper
+  DetailPrint "old-style bitmask_helper.exe not present"
+  GoTo +2
+  DetailPrint "cannot stop old-style bitmask_helper.exe"
+  noErrorHelper:
   
   ; now we try to delete the systray, locked by the app - just to know if another instance of FoobarVPN is running.
   ClearErrors
   DetailPrint "Checking for a running systray..."
+
   Delete 'C:\Program Files\$applicationName\bitmask-vpn.exe'
   IfErrors 0 noDelError
 
diff --git a/docker/Makefile b/docker/Makefile
index ac674cb7..5fd51211 100644
--- a/docker/Makefile
+++ b/docker/Makefile
@@ -31,7 +31,7 @@ login:
 package_win: clean_win package_win_stage_1 sign_win_uninstaller_in_host package_win_stage_2 sign_win_installer_in_host
 
 clean_win:
-	@rm ../deploy/*.exe
+	@rm -f ../deploy/*.exe
 
 package_win_stage_1:
 	docker run \
-- 
GitLab