Skip to content

Commit 2d71dab

Browse files
committed
Extended installer functionality
- Added check, if the application is running, because this lead to errors - Added option to add a shortcut to the autostart folder (RocketChat#57) - Added option to launch the app after the installation (RocketChat#37) - Added option to choose the installation directory (RocketChat#41) - Added the shortcuts as options, so you can choose, if you want a desktop, autostart or start menu shortcut (a part of RocketChat#96) - Enabled / Added these pages: components, browse installation folder, finish page - Extended the comments, so it's easier to find the correct spots
1 parent 83eb0a4 commit 2d71dab

File tree

1 file changed

+142
-16
lines changed

1 file changed

+142
-16
lines changed

resources/windows/installer.nsi

+142-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
; NSIS packaging/install script
22
; Docs: http://nsis.sourceforge.net/Docs/Contents.html
33

4+
; --------------------------------
5+
; Includes
6+
; --------------------------------
7+
48
!include LogicLib.nsh
59
!include nsDialogs.nsh
610

711
; --------------------------------
8-
; Variables
12+
; Variables
913
; --------------------------------
1014

1115
!define dest "{{dest}}"
@@ -26,7 +30,7 @@
2630
!define uninstaller "uninstall.exe"
2731

2832
; --------------------------------
29-
; Installation
33+
; Installation
3034
; --------------------------------
3135

3236
Unicode true
@@ -52,27 +56,56 @@ Caption "${productName} Setup"
5256
SubCaption 3 " "
5357
SubCaption 4 " "
5458

59+
; --------------------------------
60+
; Page layout
61+
; --------------------------------
62+
5563
Page custom welcome
64+
Page components
65+
Page directory
5666
Page instfiles
67+
Page custom finish finishEnd
68+
69+
; --------------------------------
70+
; Control variables
71+
; --------------------------------
5772

5873
Var Image
5974
Var ImageHandle
6075

76+
Var LaunchAppCheckbox
77+
Var LaunchAppCheckbox_State
78+
79+
; --------------------------------
80+
; Installer init
81+
; --------------------------------
82+
6183
Function .onInit
6284

6385
; Extract banner image for welcome page
6486
InitPluginsDir
6587
ReserveFile "${banner}"
6688
File /oname=$PLUGINSDIR\banner.bmp "${banner}"
89+
90+
; Check if the application is currently running, show message if it is
91+
retryInstallation:
92+
FindWindow $0 "Chrome_WidgetWin_1" "Rocket.Chat"
93+
StrCmp $0 0 notRunning
94+
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "${productName} is currently running. Please close the application to continue." /SD IDCANCEL IDRETRY retryInstallation
95+
Abort
96+
notRunning:
6797

6898
FunctionEnd
6999

70-
; Custom welcome page
100+
; --------------------------------
101+
; Welcome page [custom]
102+
; --------------------------------
103+
71104
Function welcome
72105

73106
nsDialogs::Create 1018
74107

75-
${NSD_CreateLabel} 185 1u 210 100% "Welcome to ${productName} version ${version} installer.$\r$\n$\r$\nClick install to begin."
108+
${NSD_CreateLabel} 185 1u 210 100% "Welcome to ${productName} version ${version} installer.$\r$\n$\r$\nClick next to continue."
76109

77110
${NSD_CreateBitmap} 0 0 170 210 ""
78111
Pop $Image
@@ -84,9 +117,15 @@ Function welcome
84117

85118
FunctionEnd
86119

87-
; Installation declarations
88-
Section "Install"
120+
; --------------------------------
121+
; Installation sections
122+
; --------------------------------
123+
124+
Section "Rocket.Chat Client"
89125

126+
; Make this section a requirement
127+
SectionIn RO
128+
90129
WriteRegStr HKLM "${regkey}" "Install_Dir" "$INSTDIR"
91130
WriteRegStr HKLM "${uninstkey}" "DisplayName" "${productName}"
92131
WriteRegStr HKLM "${uninstkey}" "DisplayIcon" '"$INSTDIR\icon.ico"'
@@ -102,18 +141,68 @@ Section "Install"
102141
; Include all files from /build directory
103142
File /r "${src}\*"
104143

105-
; Create start menu shortcut
106-
SetShellVarContext all
107-
CreateShortCut "$SMPROGRAMS\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"
144+
WriteUninstaller "${uninstaller}"
145+
146+
SectionEnd
147+
148+
Section "Desktop shortcut"
149+
108150
; Create desktop shortcut
109151
CreateShortCut "$DESKTOP\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"
152+
153+
SectionEnd
110154

111-
WriteUninstaller "${uninstaller}"
155+
Section "Autostart Entry"
156+
157+
; Create autostart entry
158+
CreateShortCut "$SMSTARTUP\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"
159+
160+
SectionEnd
161+
162+
Section "Start Menu Entry"
112163

164+
; Create start menu entry
165+
SetShellVarContext all
166+
CreateShortCut "$SMPROGRAMS\${productName}.lnk" "$INSTDIR\${exec}" "" "$INSTDIR\icon.ico"
167+
113168
SectionEnd
114169

170+
; --------------------------------
171+
; Finish page [custom]
172+
; --------------------------------
173+
174+
Function finish
175+
176+
nsDialogs::Create 1018
177+
178+
${NSD_CreateLabel} 185 1u 210 30u "${productName} installation successfully finished."
179+
180+
${NSD_CreateCheckbox} 185 35u 100% 10u "Launch ${productName}"
181+
Pop $LaunchAppCheckbox
182+
${NSD_SetState} $LaunchAppCheckbox ${BST_CHECKED}
183+
184+
${NSD_CreateBitmap} 0 0 170 210 ""
185+
Pop $Image
186+
${NSD_SetImage} $Image $PLUGINSDIR\banner.bmp $ImageHandle
187+
188+
nsDialogs::Show
189+
190+
${NSD_FreeImage} $ImageHandle
191+
192+
FunctionEnd
193+
194+
Function finishEnd
195+
; Save checkbox state on installer leave
196+
${NSD_GetState} $LaunchAppCheckbox $LaunchAppCheckbox_State
197+
198+
; Launch the app, if the box is checked
199+
${If} $LaunchAppCheckbox_State == ${BST_CHECKED}
200+
Exec "$INSTDIR\${exec}"
201+
${EndIf}
202+
FunctionEnd
203+
115204
; --------------------------------
116-
; Uninstaller
205+
; Uninstaller
117206
; --------------------------------
118207

119208
ShowUninstDetails nevershow
@@ -122,13 +211,40 @@ UninstallCaption "Uninstall ${productName}"
122211
UninstallText "Don't like ${productName} anymore? Hit uninstall button."
123212
UninstallIcon "${icon}"
124213

214+
; --------------------------------
215+
; Page layout
216+
; --------------------------------
217+
125218
UninstPage custom un.confirm un.confirmOnLeave
126219
UninstPage instfiles
127220

221+
; --------------------------------
222+
; Control variables
223+
; --------------------------------
224+
128225
Var RemoveAppDataCheckbox
129226
Var RemoveAppDataCheckbox_State
130227

131-
; Custom uninstall confirm page
228+
; --------------------------------
229+
; Uninstaller init
230+
; --------------------------------
231+
232+
Function un.onInit
233+
234+
; Check if the application is currently running, show message if it is
235+
retryUninstall:
236+
FindWindow $0 "Chrome_WidgetWin_1" "Rocket.Chat"
237+
StrCmp $0 0 notRunning
238+
MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "${productName} is currently running. Please close the application to continue." /SD IDCANCEL IDRETRY retryUninstall
239+
Abort
240+
notRunning:
241+
242+
FunctionEnd
243+
244+
; --------------------------------
245+
; Confirm page [custom]
246+
; --------------------------------
247+
132248
Function un.confirm
133249

134250
nsDialogs::Create 1018
@@ -149,17 +265,27 @@ Function un.confirmOnLeave
149265

150266
FunctionEnd
151267

152-
; Uninstall declarations
268+
; --------------------------------
269+
; Uninstallation sections
270+
; --------------------------------
271+
153272
Section "Uninstall"
154273

274+
; Remove registry entries
155275
DeleteRegKey HKLM "${uninstkey}"
156276
DeleteRegKey HKLM "${regkey}"
157277

158-
SetShellVarContext all
159-
Delete "$SMPROGRAMS\${productName}.lnk"
160278
; Remove desktop shortcut
161279
Delete "$DESKTOP\${productName}.lnk"
162-
; Remove whole directory from Program Files
280+
281+
; Remove autostart entry
282+
Delete "$SMSTARTUP\${productName}.lnk"
283+
284+
; Remove start menu entry
285+
SetShellVarContext all
286+
Delete "$SMPROGRAMS\${productName}.lnk"
287+
288+
; Remove whole directory from installation directory
163289
RMDir /r "$INSTDIR"
164290

165291
; Remove also appData directory generated by your app if user checked this option

0 commit comments

Comments
 (0)