From e3baef0e9e36e1b0f3e899ef8e83520004b50a29 Mon Sep 17 00:00:00 2001
From: "kali kaneko (leap communications)" <kali@leap.se>
Date: Wed, 22 Apr 2020 18:51:03 +0200
Subject: [PATCH] [pkg] another try at removing the nssm helper

---
 branding/templates/windows/template.nsi | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/branding/templates/windows/template.nsi b/branding/templates/windows/template.nsi
index ce05d27c..f9f8ea10 100755
--- a/branding/templates/windows/template.nsi
+++ b/branding/templates/windows/template.nsi
@@ -46,7 +46,23 @@ RequestExecutionLevel admin
  
 
 Section "InstallFiles"
-  ; first we try to delete the systray, locked by the app.
+  ; first we try to delete the helper, in case it is still the nssm-style
+  ClearErrors
+  Delete 'C:\Program Files\$applicationName\bitmask_helper.exe'
+  IfErrors 0 noErrorHelper
+
+  ; this could fail: uninstalling old nssm helper
+  ExecShellWait "runas" '"$INSTDIR\nssm.exe" stop $applicationNameLower-helper'
+  ExecShellWait "runas" '"$INSTDIR\nssm.exe" remove $applicationNameLower-helper confirm'
+  IfErrors 0 noErrorHelper
+
+  ; Error handling
+  MessageBox MB_OK|MB_ICONEXCLAMATION "$applicationNameLower-helper cannot be deleted. Please try to remove it manually, and then run this installer again."
+  Abort
+
+  noErrorHelper:
+  
+  ; now we try to delete the systray, locked by the app.
   ClearErrors
   Delete 'C:\Program Files\$applicationName\bitmask-vpn.exe'
   IfErrors 0 noError
@@ -98,11 +114,8 @@ Section /o "TAP Virtual Ethernet Adapter" SecTAP
 SectionEnd
 
 Section "Uninstall"
-  ; this could fail: uninstalling old nssm helper
-  ExecShellWait "runas" '"$INSTDIR\nssm.exe" stop $applicationNameLower-helper'
-  ExecShellWait "runas" '"$INSTDIR\nssm.exe" remove $applicationNameLower-helper confirm'
 
-  ; now we uninstall the new-style go helper
+  ; we uninstall the new-style go helper
   ExecShellWait "runas" '"$INSTDIR\bitmask_helper.exe" remove'
 
 
-- 
GitLab