Skip to content

Commit

Permalink
Handle silent upgrade on Windows. (#424)
Browse files Browse the repository at this point in the history
Also log extraction errors during silent installs.
  • Loading branch information
igorpeshansky committed Aug 15, 2023
1 parent 22910f6 commit 63ba1a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
2 changes: 2 additions & 0 deletions windows-installer/setup.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ Section "Install"
${If} $0 != "success"
${IfNot} ${Silent}
MessageBox MB_OK "Failed to unzip: $0"
${Else}
${Print} "Failed to unzip: $0"
${EndIf}
Abort
${EndIf}
Expand Down
54 changes: 27 additions & 27 deletions windows-installer/stackdriver_util.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
SetDetailsPrint lastused

; Restore $0
; Stack: [orig $0 val, ...] -> [...]
; Stack: [orig $0 val, ...] -> [...]
Pop $0
FunctionEnd
!macroend
Expand Down Expand Up @@ -68,9 +68,9 @@

;--------------------------------
; Defines ExecuteCommand and UnExecuteCommand (uninstaller functions)
;
;
; Executes a command with the given parameters via cmd.exe.
;
;
; Call with:
; ${ExecuteCommand} "Command" "Parameters"
; ${UnExecuteCommand} "Command" "Parameters"
Expand Down Expand Up @@ -105,13 +105,13 @@
Push "${Parameters}"
Push "${Command}"
Call ExecuteCommand

; Get and log the return value of nsExec::Exec
Pop $0
${Print} "nsExec::Exec return code: $0"

; Restore $0, $1, $2
; Stack: [orig $2, orig $1, orig $0, ...] -> [...]
; Stack: [orig $2, orig $1, orig $0, ...] -> [...]
Pop $2
Pop $1
Pop $0
Expand All @@ -123,13 +123,13 @@
Push "${Parameters}"
Push "${Command}"
Call un.ExecuteCommand

; Get and log the return value of nsExec::Exec
Pop $0
${UnPrint} "nsExec::Exec return code: $0"

; Restore $0, $1, $2
; Stack: [orig $2, orig $1, orig $0, ...] -> [...]
; Stack: [orig $2, orig $1, orig $0, ...] -> [...]
Pop $2
Pop $1
Pop $0
Expand All @@ -145,12 +145,11 @@

;--------------------------------
; Defines RemoveOldVersion
;
;
; Prompts the user the given program (name param) is already installed.
; If the candidate clicks 'OK' the uninstaller (uninstaller param) will
; be executed. If they click 'Cancel' the install will be aborted.
; NOTE: Does not support silent notification if an old version is installed.
;
;
; Call with:
; ${RemoveOldVersion} "Name" "Full path to uninstall executable"
;--------------------------------
Expand All @@ -159,12 +158,13 @@
MessageBox MB_OKCANCEL \
"${name} is already installed. Click 'OK' to remove the old \
version and continue or 'Cancel' to exit the installer" \
IDOK remove IDCANCEL abort

/SD IDOK \
IDOK remove IDCANCEL abort

; The user does not want to unintall, abort the installer.
abort:
Abort

; Uninstall the program, honor silent options.
remove:
${If} ${Silent}
Expand All @@ -180,13 +180,13 @@
; END RemoveOldVersion
;--------------------------------


;--------------------------------
; Defines RegisterUninstallSoftware
;
;
; Registers the software in the uninstall registry, installs for the current
; user or for the local machine based on install preferences.
;
;
; Call with:
; ${RegisterUninstallSoftware} "Software Name" "SoftwareName" "Uninstaller location"
; "Absolute path to icon" "Company name" "Estimated size in KB" "Version of agent"
Expand All @@ -195,7 +195,7 @@
; Store global var $0 on the stack and copy the reg key to $0
Push $0
StrCpy $0 "${UNINST_REG_KEY}\${compressedName}"

; Write all the needed register information
WriteRegStr HKLM "$0" "DisplayName" "${displayName}"
WriteRegStr HKLM "$0" "UninstallString" "${uninstaller}"
Expand All @@ -204,36 +204,36 @@
WriteRegStr HKLM "$0" "Publisher" "${company}"
WriteRegDWORD HKLM "$0" "EstimatedSize" "${sizeKB}"
WriteRegStr HKLM "$0" "Version" "${version}"

; We do not allow modifying or reparing an install
WriteRegDWORD HKLM "$0" "NoModify" 1
WriteRegDWORD HKLM "$0" "NoRepair" 1

; Restore the $0 global var
Pop $0
!macroend

; Define the RegisterUninstallSoftware function for ease of calling
!define RegisterUninstallSoftware "!insertmacro _STACKDRIVER_REGISTER_UNINSTALL_SOFTWARE_MACRO"
;--------------------------------
; END RegisterUninstallSoftware
;--------------------------------


;--------------------------------
; Defines RemoveRegisterUninstallSoftware
;
;
; Removes the registration for the software in the uninstall registry.
;
;
; Call with:
; ${RemoveRegisterUninstallSoftware} "SoftwareName"
;--------------------------------
!macro _STACKDRIVER_REMOVE_REGISTER_UNINSTALL_SOFTWARE_MACRO name
!macro _STACKDRIVER_REMOVE_REGISTER_UNINSTALL_SOFTWARE_MACRO name
DeleteRegKey HKLM "${UNINST_REG_KEY}\${name}"
!macroend

; Define the RemoveRegisterUninstallSoftware function for ease of calling.
!define RemoveRegisterUninstallSoftware "!insertmacro _STACKDRIVER_REMOVE_REGISTER_UNINSTALL_SOFTWARE_MACRO"
;--------------------------------
; END RemoveRegisterUninstallSoftware
;--------------------------------
;--------------------------------

0 comments on commit 63ba1a5

Please sign in to comment.