Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Major changes to installer
Browse files Browse the repository at this point in the history
- Remember install location (#63)
- Remember shortcuts and autostart parameters
- Silently uninstall previous version
- Let users decide whether they want to delete the settings file when uninstalling or not
  • Loading branch information
aleab committed Apr 6, 2018
1 parent 9bc727e commit ee88029
Show file tree
Hide file tree
Showing 19 changed files with 1,297 additions and 44 deletions.
46 changes: 39 additions & 7 deletions InstallationScript/Functions.nsh
@@ -1,4 +1,34 @@
!include LogicLib.nsh
!include FileFunc.nsh
!include .\NSISpcre.nsh

!insertmacro REMatches


; FileExists is already part of LogicLib, but returns true for directories as well as files
!macro _FileExists2 _a _b _t _f
!insertmacro _LOGICLIB_TEMP
StrCpy $_LOGICLIB_TEMP "0"
StrCmp `${_b}` `` +4 0 ; if path is not blank, continue to next check
IfFileExists `${_b}` `0` +3 ; if path exists, continue to next check (IfFileExists returns true if this is a directory)
IfFileExists `${_b}\*.*` +2 0 ; if path is not a directory, continue to confirm exists
StrCpy $_LOGICLIB_TEMP "1" ; file exists
; now we have a definitive value - the file exists or it does not
StrCmp $_LOGICLIB_TEMP "1" `${_t}` `${_f}`
!macroend
!undef FileExists

!define FileExists `"" FileExists2`
!macro _DirExists _a _b _t _f
!insertmacro _LOGICLIB_TEMP
StrCpy $_LOGICLIB_TEMP "0"
StrCmp `${_b}` `` +3 0 ; if path is not blank, continue to next check
IfFileExists `${_b}\*.*` 0 +2 ; if directory exists, continue to confirm exists
StrCpy $_LOGICLIB_TEMP "1"
StrCmp $_LOGICLIB_TEMP "1" `${_t}` `${_f}`
!macroend
!define DirExists `"" DirExists`


;--------------------------------
; Function Macros
Expand All @@ -10,6 +40,7 @@
!macroend
!define TrimQuotes `!insertmacro _TrimQuotes`


;--------------------------------
; Functions

Expand All @@ -32,22 +63,23 @@ Function TrimQuotes
Exch $R0
FunctionEnd


;--------------------------------

Function UninstallPreviousVersions
Push $R0
Push $R1

ReadRegStr $R0 HKLM "${RegUninstallKey}" "UninstallString"
StrCmp $R0 "" done

${TrimQuotes} $R0 $R0
${GetParent} $R0 $R1
${If} $R0 != ""
${TrimQuotes} $R0 $R0
${GetParent} $R0 $R1

ClearErrors
ExecWait '$R0 _?=$R1'
ClearErrors
ExecWait '$R0 /S _?=$R1'
RMDir /r "$R1"
${EndIf}

Pop $R1
Pop $R0
done:
FunctionEnd
153 changes: 119 additions & 34 deletions InstallationScript/Install.nsi
@@ -1,17 +1,26 @@
!define APPNAME "Toastify"
!define PUBLISHER "Jesper Palm, Oren Nachman, Alessandro Attard Barbini"
!define DESCRIPTION "Toastify adds global hotkeys and toast notifications to Spotify"
!define VERSIONMAJOR 1
!define VERSIONMINOR 10
!define VERSIONBUILD 8
!define HELPURL "https://github.com/aleab/toastify/issues"
!define UPDATEURL "https://github.com/aleab/toastify/releases"
!define ABOUTURL "https://aleab.github.io/toastify/"
!define ESTIMATEDSIZE 4510

!define RegUninstallKey "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}"


!include LogicLib.nsh
!include MUI.nsh
!include x64.nsh
!include WinVer.nsh

!define ProgramName "Toastify"
!define RegUninstallKey "Software\Microsoft\Windows\CurrentVersion\Uninstall\${ProgramName}"

!include .\NSISpcre.nsh
!include .\DotNetChecker.nsh
!include .\Functions.nsh

!define EstimatedSize 4510

Name "${ProgramName} Installer"
Name "${APPNAME} Installer"
RequestExecutionLevel admin
CRCCheck force

Expand All @@ -22,6 +31,7 @@ ManifestSupportedOS "{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" # Windows 10
OutFile "ToastifyInstaller.exe"
InstallDir $PROGRAMFILES64\Toastify


;--------------------------------
; Pages

Expand All @@ -30,32 +40,38 @@ Page directory
Page instfiles

# These statements modify settings for MUI_PAGE_FINISH
!define MUI_FINISHPAGE_AUTOCLOSE
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Launch ${ProgramName} now"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchApplication"
!define MUI_FINISHPAGE_AUTOCLOSE
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Launch ${APPNAME} now"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchApplication"
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

UninstPage components
UninstPage uninstConfirm
UninstPage instfiles


;--------------------------------
; Installer

Section "${ProgramName} (required)"
Var /GLOBAL PrevDesktopShortcutArgs
Var /GLOBAL PrevSMShortcutArgs
Var /GLOBAL PrevAutostartArgs

Section "${APPNAME} (required)"
SectionIn RO
AddSize ${EstimatedSize}

# Since process termination is non-destructive for Toastify, just kill it
DetailPrint "Shutting down ${ProgramName}..."
DetailPrint "Shutting down ${APPNAME}..."
KillProcWMI::KillProc "Toastify.exe"
Sleep 2000

# Uninstall previous versions
DetailPrint "Uninstalling previous versions of ${ProgramName}..."
DetailPrint "Uninstalling previous versions of ${APPNAME}..."
Call UninstallPreviousVersions

# Check .NET Framework
Expand Down Expand Up @@ -92,41 +108,49 @@ Section "${ProgramName} (required)"
Delete "$INSTDIR\uninstall.exe"

# Write the uninstall keys for Windows
WriteRegStr HKLM "${RegUninstallKey}" "DisplayName" "Toastify"
WriteRegStr HKLM "${RegUninstallKey}" "UninstallString" '"$INSTDIR\uninst.exe"'
WriteRegStr HKLM "${RegUninstallKey}" "DisplayName" "${APPNAME}"
WriteRegStr HKLM "${RegUninstallKey}" "DisplayIcon" "$INSTDIR\Toastify.exe,0"
WriteRegStr HKLM "${RegUninstallKey}" "Publisher" "Jesper Palm, Oren Nachman, Alessandro Attard Barbini"
WriteRegStr HKLM "${RegUninstallKey}" "Version" "1.10.8"
WriteRegStr HKLM "${RegUninstallKey}" "DisplayVersion" "1.10.8"
WriteRegStr HKLM "${RegUninstallKey}" "Publisher" "${PUBLISHER}"
WriteRegStr HKLM "${RegUninstallKey}" "Version" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
WriteRegStr HKLM "${RegUninstallKey}" "DisplayVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}"
WriteRegStr HKLM "${RegUninstallKey}" "InstallLocation" "$INSTDIR"
WriteRegStr HKLM "${RegUninstallKey}" "UninstallString" '"$INSTDIR\uninst.exe"'
WriteRegStr HKLM "${RegUninstallKey}" "QuietUninstallString" '"$INSTDIR\uninst.exe" /S'
WriteRegStr HKLM "${RegUninstallKey}" "HelpLink" "${HELPURL}"
WriteRegStr HKLM "${RegUninstallKey}" "URLUpdateInfo" "${UPDATEURL}"
WriteRegStr HKLM "${RegUninstallKey}" "URLInfoAbout" "${ABOUTURL}"
WriteRegDWORD HKLM "${RegUninstallKey}" "EstimatedSize" ${EstimatedSize}
WriteRegDWORD HKLM "${RegUninstallKey}" "NoModify" 1
WriteRegDWORD HKLM "${RegUninstallKey}" "NoRepair" 1
WriteUninstaller "uninst.exe"

SectionEnd

Section "Desktop icon"
CreateShortCut "$DESKTOP\Toastify.lnk" "$INSTDIR\Toastify.exe" "" "$INSTDIR\Toastify.exe" 0
CreateShortCut "$DESKTOP\Toastify.lnk" "$INSTDIR\Toastify.exe" "$PrevDesktopShortcutArgs" "$INSTDIR\Toastify.exe" 0
SectionEnd

Section "Start Menu icon"
CreateShortCut "$SMPROGRAMS\Toastify.lnk" "$INSTDIR\Toastify.exe" "" "$INSTDIR\Toastify.exe" 0
CreateShortCut "$SMPROGRAMS\Toastify.lnk" "$INSTDIR\Toastify.exe" "$PrevSMShortcutArgs" "$INSTDIR\Toastify.exe" 0
SectionEnd

Section /o "Autostart"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "Toastify" '"$INSTDIR\Toastify.exe"'
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "Toastify" '"$INSTDIR\Toastify.exe"$PrevAutostartArgs'
SectionEnd


;--------------------------------
; Uninstaller

Section "Uninstall"

Section "un.Toastify"
SectionIn RO

# Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Toastify"
DeleteRegValue HKCU "Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Run" "Toastify"
DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "Toastify"
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "Toastify"

# Remove files and uninstaller
# Remove files
Delete "$INSTDIR\Toastify.exe"
Delete "$INSTDIR\Toastify.exe.config"
Delete "$INSTDIR\Toastify.pdb"
Expand All @@ -143,27 +167,88 @@ Section "Uninstall"
Delete "$INSTDIR\LICENSE"
Delete "$INSTDIR\LICENSE-3RD-PARTY"
Delete "$INSTDIR\uninst.exe"

# remove the settings directory
Delete "$APPDATA\Toastify.xml"
RMDir "$APPDATA\Toastify"

# Remove log files
Delete "$LOCALAPPDATA\Toastify\Toastify.log*"

# Remove shortcuts
Delete "$DESKTOP\Toastify.lnk"
Delete "$SMPROGRAMS\Toastify.lnk"

# Remove directories used
RMDir "$INSTDIR"
# Remove directories
RMDir /r "$INSTDIR"
SectionEnd

Section /o "un.Settings"
Delete "$APPDATA\Toastify\Toastify.cfg"
Delete "$LOCALAPPDATA\Toastify\proxy.sec"
SectionEnd


;--------------------------------
; Functions

Function .onInit
Push $R0
Push $R1

StrCpy $INSTDIR "$PROGRAMFILES64\Toastify"

StrCpy $PrevDesktopShortcutArgs ""
StrCpy $PrevSMShortcutArgs ""
StrCpy $PrevAutostartArgs ""

# Get previous install location
ReadRegStr $R0 HKLM "${RegUninstallKey}" "InstallLocation"
${If} $R0 != ""
StrCpy $INSTDIR "$R0"
${Else}
ReadRegStr $R0 HKLM "${RegUninstallKey}" "UninstallString"
${If} $R0 != ""
${TrimQuotes} $R0 $R0
${GetParent} $R0 $R1
StrCpy $INSTDIR "$R1"
${EndIf}
${EndIf}

# Get the arguments of the previous Desktop shortcut
${If} ${FileExists} "$DESKTOP\Toastify.lnk"
ClearErrors
ShellLink::GetShortCutArgs "$DESKTOP\Toastify.lnk"
${IfNot} ${Errors}
Pop $PrevDesktopShortcutArgs
${EndIf}
${EndIf}

# Get the arguments of the previous StartMenu shortcut
${If} ${FileExists} "$SMPROGRAMS\Toastify.lnk"
ClearErrors
ShellLink::GetShortCutArgs "$SMPROGRAMS\Toastify.lnk"
${IfNot} ${Errors}
Pop $PrevSMShortcutArgs
${EndIf}
${EndIf}

# Get the arguments of the previous Autostart entry
ReadRegStr $R0 HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "Toastify"
${If} $R0 != ""
${RECaptureMatches} $0 '.*Toastify.exe"?(.*)' $R0 0
StrCpy $PrevAutostartArgs $1
${EndIf}

Pop $R1
Pop $R0
FunctionEnd

Function LaunchApplication
ShellExecAsUser::ShellExecAsUser "" "$INSTDIR\Toastify.exe" ""
# Should we use some command line argument?
${If} $PrevAutostartArgs != ""
StrCpy $0 $PrevAutostartArgs
${ElseIf} $PrevSMShortcutArgs != ""
StrCpy $0 $PrevSMShortcutArgs
${Else}
StrCpy $0 $PrevDesktopShortcutArgs
${EndIf}

ShellExecAsUser::ShellExecAsUser "" "$INSTDIR\Toastify.exe" "$0"
FunctionEnd

0 comments on commit ee88029

Please sign in to comment.