forked from pophealth/win-installer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
popHealth.nsi
709 lines (575 loc) · 23.6 KB
/
popHealth.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
; popHealth.nsi
;
; This script will install the popHealth system (with all dependencies) and
; configure so that the popHealth application is available after the next
; system boot. It also sets up an uninstaller so that the user can remove the
; application completely if desired.
;--------------------------------
; Use the lzma compression algorithm for maximum compression
SetCompressor /solid lzma
;--------------------------------
; Include files
!include "LogicLib.nsh"
!include "MUI2.nsh"
!include "scheduletask.nsh"
!include "EnvVarUpdate.nsh"
;--------------------------------
; Only install on Windows XP or more recent (option not supported yet)
;TargetMinimalOS 5.1
; The name of the installer
Name "popHealth"
; The file to write
;OutFile "popHealth-i386.exe"
!ifndef BUILDARCH
!define BUILDARCH 32
!endif
!if ${BUILDARCH} = 32
OutFile "popHealth-i386.exe"
!else
OutFile "popHealth-x86_64.exe"
!endif
!echo "BUILDARCH = ${BUILDARCH}"
; Request application privileges for Windows Vista
RequestExecutionLevel admin
; Install types we support: full, minimal, custom (provided automatically)
InstType "Full"
InstType "Minimal"
; License settings
LicenseForceSelection checkbox "I accept"
;LicenseText
LicenseData license.txt
;--------------------------------
; Some useful defines
!define env_allusers 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!if ${BUILDARCH} = 32
!define ruby_key 'HKLM "software\RubyInstaller\MRI\1.9.2" "InstallLocation"'
!else
!define ruby_key 'HKLM "software\Wow6432Node\RubyInstaller\MRI\1.9.2" "InstallLocation"'
!endif
;--------------------------------
; Some useful macros
; This macro sets an environment variable temporarily for the installer and sub-processes
!macro SetInstallerEnvVar Name Value
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("${Name}", "${Value}").r0'
StrCmp $0 0 0 +2
MessageBox MB_OK "Failed to set environment variable '${Name}'"
!macroend
; This macro adds an environment variable to the registry for all users
!macro AddEnvVarToReg Name Value
WriteRegExpandStr ${env_allusers} '${Name}' '${Value}'
; Make sure Windows knows about the change
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
!macroend
; This macro adds an environment variable to the registry for all users, and
; adds it to the environment of the installer and sub-processes
!macro EnvVarEverywhere Name Value
!insertmacro AddEnvVarToReg '${Name}' '${Value}'
!insertmacro SetInstallerEnvVar '${Name}' '${Value}'
!macroend
!macro SetRubyDir
StrCpy $rubydir "$systemdrive\Ruby192"
ReadRegStr $0 ${ruby_key}
StrCmp $0 "" +2
StrCpy $rubydir $0
!macroend
!macro CheckRubyInstalled Yes No
!insertmacro SetRubyDir
IfFileExists "$rubydir\bin\ruby.exe" ${Yes} ${No}
!macroend
;--------------------------------
;Interface Settings
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP popHealthMiniLogo.bmp
!define MUI_ABORTWARNING
XPStyle on
Var Dialog
var systemdrive ;Set the primary drive letter for the system
var rubydir ; The root directory of the ruby install to use
var mongodir ; The root directory of the mongodb install
var redisdir ; The root directory of the redis install
;--------------------------------
; Pages
!insertmacro MUI_PAGE_WELCOME
;Page license
!insertmacro MUI_PAGE_LICENSE license.txt
;Page components
!insertmacro MUI_PAGE_COMPONENTS
;Page directory
!insertmacro MUI_PAGE_DIRECTORY
Page custom ProxySettingsPage ProxySettingsLeave
;Page instfiles
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
;UninstPage uninstConfirm
!insertmacro MUI_UNPAGE_CONFIRM
UnInstPage custom un.ProxySettingsPage
;UninstPage instfiles
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
; Languages
!insertmacro MUI_LANGUAGE "English"
;=============================================================================
; INSTALLER SECTIONS
;
; The order of the sections determines the order that they will be listed in
; the Components page.
;=============================================================================
;-----------------------------------------------------------------------------
; Uninstaller
;
; Creates and registers an uninstaller for application removal.
;-----------------------------------------------------------------------------
Section "Create Uninstaller" sec_uninstall
SectionIn RO
SetOutPath $INSTDIR
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\popHealth "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\popHealth" "DisplayName" "popHealth"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\popHealth" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\popHealth" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\popHealth" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
;-----------------------------------------------------------------------------
; Start Menu Shortcuts
;
; Registers a Start Menu shortcut for the application uninstaller and another
; to launch a web browser into the popHealth web application.
;-----------------------------------------------------------------------------
Section "Start Menu Shortcuts" sec_startmenu
SectionIn 1 2 3
SetOutPath $INSTDIR
; Create an Internet shortcut for popHealth web app
WriteINIStr "$INSTDIR\popHealth.URL" "InternetShortcut" "URL" "http://localhost:3000/"
CreateDirectory "$SMPROGRAMS\popHealth"
CreateShortCut "$SMPROGRAMS\popHealth\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\popHealth\popHealth.lnk" "$INSTDIR\popHealth.URL" "" "" ""
SectionEnd
;-----------------------------------------------------------------------------
; Ruby
;
; Runs the Ruby install program and waits for it to finish.
; TODO: Need to record somehow whether we actually install this so that the
; uninstaller can remove it.
;-----------------------------------------------------------------------------
Section "Install Ruby" sec_ruby
SectionIn 1 3 ; enabled in Full and Custom installs
AddSize 18534 ; additional size in kB above installer
;Check if ruby exists
!insertmacro CheckRubyInstalled 0 installruby
;Ruby was found
MessageBox MB_ICONQUESTION|MB_YESNO "A current ruby installation was found. Do you want to install it again?$\n$\n\
Current install location: $0" /SD IDNO IDNO rubydone
;Ruby not found
installruby:
SetOutPath $rubydir
File /r Ruby192\*.*
SetOutPath $INSTDIR\depinstallers ; temporary directory
WriteRegStr HKLM "software\Classes\RubyFile\DefaultIcon" "" '$rubydir\bin\ruby.exe,0'
WriteRegStr HKLM "software\Classes\RubyFile\shell\open\command" "" '"$rubydir\bin\ruby.exe" "%1" %*'
WriteRegStr HKLM "software\Classes\RubyWFile\DefaultIcon" "" '$rubydir\bin\rubyw.exe,0'
WriteRegStr HKLM "software\Classes\RubyWFile\shell\open\command" "" '"$rubydir\bin\rubyw.exe" "%1" %*'
File "ruby.reg"
Exec '"$WINDIR\system32\reg.exe" IMPORT ruby.reg'
File "uninstall.reg"
Exec '"$WINDIR\system32\reg.exe" IMPORT uninstall.reg'
!if ${BUILDARCH} = 32
WriteRegStr HKLM "software\RubyInstaller\MRI\1.9.2" "InstallLocation" '$rubydir'
File "32bit.reg"
Exec '"$WINDIR\system32\reg.exe" IMPORT 32bit.reg'
!else
WriteRegStr HKLM "software\Wow6432Node\RubyInstaller\MRI\1.9.2" "InstallLocation" '$rubydir'
File "64bit.reg"
Exec '"$WINDIR\system32\reg.exe" IMPORT 64bit.reg'
!endif
Push $0
Push "PATH"
Push "A"
Push "HKLM"
Push "$rubydir\bin"
Call EnvVarUpdate
Pop $0
Push "PATHEXT"
Push "A"
Push "HKLM"
Push ".RB;.RBW"
Call EnvVarUpdate
Pop $0
Pop $0
WriteRegStr HKCU "software\Microsoft\Windows\CurrentVersion\Uninstall\{BD5F3A9C-22D5-4C1D-AEA0-ED1BE83A1E67}_is1" "Inno Setup: App Path" '$rubydir'
WriteRegStr HKCU "software\Microsoft\Windows\CurrentVersion\Uninstall\{BD5F3A9C-22D5-4C1D-AEA0-ED1BE83A1E67}_is1" "InstallLocation" '$rubydir'
System::Call "advapi32::GetUserName(t .r0, *i ${NSIS_MAX_STRLEN} r1) i.r2"
WriteRegStr HKCU "software\Microsoft\Windows\CurrentVersion\Uninstall\{BD5F3A9C-22D5-4C1D-AEA0-ED1BE83A1E67}_is1" "Inno Setup: User" '$0'
WriteRegStr HKCU "software\Microsoft\Windows\CurrentVersion\Uninstall\{BD5F3A9C-22D5-4C1D-AEA0-ED1BE83A1E67}_is1" "DisplayIcon" '$rubydir\bin\ruby.exe'
WriteRegStr HKCU "software\Microsoft\Windows\CurrentVersion\Uninstall\{BD5F3A9C-22D5-4C1D-AEA0-ED1BE83A1E67}_is1" "UninstallString" '"$rubydir\unins000.exe"'
WriteRegStr HKCU "software\Microsoft\Windows\CurrentVersion\Uninstall\{BD5F3A9C-22D5-4C1D-AEA0-ED1BE83A1E67}_is1" "QuietUninstallString" '"$rubydir\unins000.exe" /SILENT'
;Make sure ruby was installed
!insertmacro CheckRubyInstalled rubydone 0
MessageBox MB_ICONEXCLAMATION|MB_RETRYCANCEL 'We could not verify that ruby was properly installed' \
IDRETRY installruby
rubydone:
Push "$rubydir\bin"
Call AddToPath
SectionEnd
;-----------------------------------------------------------------------------
; Bundler
;
; Installs the bundler gem for user later in the install.
;-----------------------------------------------------------------------------
Section "Install Bundler" sec_bundler
SectionIn 1 3 ; enabled in Full and Custom installs
AddSize 3922 ; additional size in kB above installer
ClearErrors
ExecWait '"$rubydir\bin\gem.bat" install bundler'
IfErrors 0 +2
MessageBox MB_ICONEXCLAMATION|MB_OK "Failed to install the bundler gem."
SectionEnd
;-----------------------------------------------------------------------------
; MongoDB
;
; Installs and registers mongodb to runs as a native Windows service. Since
; this program is distributed as a zip file, it is unpackaged and included
; directly in the popHealth installer. The service is also started so that we
; can use MongoDB later in the installer.
;-----------------------------------------------------------------------------
Section "Install MongoDB" sec_mongodb
SectionIn 1 3 ; enabled in Full and Custom installs
SetOutPath "$systemdrive\mongodb-2.0.1"
File /r mongodb-2.0.1\*.*
; Create a data directory for mongodb
SetOutPath $systemdrive\data\db
; Install the mongodb service
ExecWait '"$mongodir\bin\mongod" --logpath $systemdrive\data\logs --logappend --dbpath $systemdrive\data\db --directoryperdb --install'
; Start the mongodb service
ExecWait 'net.exe start "Mongo DB"'
SectionEnd
;-----------------------------------------------------------------------------
; Redis
;
; Installs the redis server. This program is distributed as a zip file, so
; it is unpackage and included directly in the popHealth installer. Once
; installed, a scheduled task with a boot trigger is registered. This will
; result in the redis server being started every time the machine is rebooted.
;-----------------------------------------------------------------------------
Section "Install Redis" sec_redis
SectionIn 1 3 ; enabled in Full and Custom installs
SetOutPath "$redisdir"
File /r redis-2.4.0\*.*
; Install a scheduled task to start redis on system boot
push "popHealth Redis Server"
push "Run the redis server at startup."
push "PT15S"
push "$redisdir\${BUILDARCH}bit\redis-server.exe"
push "redis.conf"
push "$redisdir\${BUILDARCH}bit"
push "Local Service"
Call CreateTask
pop $0
DetailPrint "Result of scheduling Redis Server task: $0"
SetRebootFlag true
SectionEnd
;-----------------------------------------------------------------------------
; popHealth Web Application
;
; This section copies the popHealth Web Application onto the system. This also
;installs a scheduled task with a boot trigger that will start a web server so
; that the application can be accessed when the system is booted.
;-----------------------------------------------------------------------------
Section "popHealth Web Application" sec_popHealth
SectionIn RO
AddSize 37802 ; current size of cloned repo (in kB)
; Set output path to the installation directory.
SetOutPath $INSTDIR
File /r pophealth
; Install required gems
SetOutPath $rubydir\lib\ruby\gems\1.9.1\gems
File /r bson_ext-1.5.1
File /r json-1.4.6
File /r rcov-0.9.11
SetOutPath $rubydir\lib\ruby\gems\1.9.1\specifications
File bson_ext-1.5.1.gemspec
File json-1.4.6.gemspec
File rcov-0.9.11.gemspec
SetOutPath $INSTDIR\popHealth
ExecWait 'bundle.bat install'
; Create admin user account
ExecWait 'bundle.bat exec rake admin:create_admin_account'
; Install a scheduled task to start a web server on system boot
push "popHealth Web Server"
push "Run the web server that allows access to the popHealth application."
push "PT1M30S"
push "$rubydir\bin\ruby.exe"
push "script/rails server"
push "$INSTDIR\popHealth"
push "System"
Call CreateTask
pop $0
DetailPrint "Result of scheduling Web Server task: $0"
SetRebootFlag true
SectionEnd
;-----------------------------------------------------------------------------
; Resque Workers
;
; This section installs a batch file that will start the resque workers and
; schedules a task with a boot trigger so that the workers are always started
; when the system boots up.
;-----------------------------------------------------------------------------
Section "Install resque workers" sec_resque
SectionIn 1 3 ; enabled in Full and Custom installs
; Set output path to the popHealth web app's script directory
SetOutPath $INSTDIR\popHealth\script
; Install the batch file that starts the workers.
File "run-resque.bat"
; Install the scheduled service to run the resque workers on startup.
push "popHealth Resque Workers"
push "Run the resque workers for the popHealth application."
push "PT45S"
push "$rubydir\bin\ruby.exe"
push '"$rubydir\bin\rake" resque:work'
push "$INSTDIR\popHealth"
push "Local Service"
Call CreateTask
pop $0
DetailPrint "Result of scheduling resque workers task: $0"
SetRebootFlag true
SectionEnd
;-----------------------------------------------------------------------------
; popHealth Quality Measures
;
; This section copies the popHealth Quality Measures onto the system
;-----------------------------------------------------------------------------
Section "popHealth Quality Measures" sec_qualitymeasures
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
File /r measures
; Install required gems
SetOutPath $INSTDIR\measures
ExecWait 'bundle.bat install'
SectionEnd
;-----------------------------------------------------------------------------
; Patient Records
;
; This section adds 500 random patient records to the mongo database so that
; there is data to play around with as soon as the installer finishes.
;-----------------------------------------------------------------------------
Section "Install patient records" sec_samplepatients
SectionIn 1 3 ; enabled in Full and Custom installs
; Set output path to the measures directory
SetOutPath $INSTDIR\measures
; Define an environment variable for the database to use
!insertmacro SetInstallerEnvVar 'DB_NAME' 'pophealth-development'
; Generate records
ExecWait 'bundle.bat exec rake mongo:reload_bundle'
ExecWait 'bundle.bat exec rake patient:random[500]'
SectionEnd
;--------------------------------
; Descriptions
;Language strings
LangString DESC_sec_uninstall ${LANG_ENGLISH} "Provides ability to uninstall popHealth"
LangString DESC_sec_startmenu ${LANG_ENGLISH} "Start Menu shortcuts"
LangString DESC_sec_ruby ${LANG_ENGLISH} "Ruby scripting language"
LangString DESC_sec_bundler ${LANG_ENGLISH} "Ruby Bundler gem"
LangString DESC_sec_mongodb ${Lang_ENGLISH} "MongoDB database server"
LangString DESC_sec_redis ${LANG_ENGLISH} "Redis server"
LangString DESC_sec_qualitymeasures ${LANG_ENGLISH} "popHealth quality measure definitions"
LangString DESC_sec_popHealth ${LANG_ENGLISH} "popHealth web application"
LangString DESC_sec_resque ${LANG_ENGLISH} "popHealth resque workers"
LangString DESC_sec_samplepatients ${LANG_ENGLISH} "Generates 500 sample patient records"
LangString ProxyPage_Title ${LANG_ENGLISH} "Proxy Server Settings"
LangString ProxyPage_SUBTITLE ${LANG_ENGLISH} "Specify the name of the proxy server used to access the Internet"
;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${sec_uninstall} $(DESC_sec_uninstall)
!insertmacro MUI_DESCRIPTION_TEXT ${sec_startmenu} $(DESC_sec_startmenu)
!insertmacro MUI_DESCRIPTION_TEXT ${sec_ruby} $(DESC_sec_ruby)
!insertmacro MUI_DESCRIPTION_TEXT ${sec_bundler} $(DESC_sec_bundler)
!insertmacro MUI_DESCRIPTION_TEXT ${sec_mongodb} $(DESC_sec_mongodb)
!insertmacro MUI_DESCRIPTION_TEXT ${sec_redis} $(DESC_sec_redis)
!insertmacro MUI_DESCRIPTION_TEXT ${sec_qualitymeasures} $(DESC_sec_qualitymeasures)
!insertmacro MUI_DESCRIPTION_TEXT ${sec_popHealth} $(DESC_sec_popHealth)
!insertmacro MUI_DESCRIPTION_TEXT ${sec_resque} $(DESC_sec_resque)
!insertmacro MUI_DESCRIPTION_TEXT ${sec_samplepatients} $(DESC_sec_samplepatients)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;=============================================================================
; UNINSTALLER SECTION
;
; This should undo everyting done by the installer.
; TODO: Need to record exactly which components were installed so that we only
; uninstall those same components.
;=============================================================================
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\popHealth"
DeleteRegKey HKLM SOFTWARE\popHealth
; Uninstall the resque worker scheduled task
ExecWait 'schtasks.exe /end /tn "popHealth Resque Workers"'
push "popHealth Resque Workers"
Call un.DeleteTask
pop $0
DetailPrint "Results of deleting Resque Workers task: $0"
; Uninstall popHealth web application
ExecWait 'schtasks.exe /end /tn "popHealth Web Server"'
push "popHealth Web Server"
Call un.DeleteTask
pop $0
DetailPrint "Results of deleting Web Server task: $0"
RMDIR /r $INSTDIR\popHealth
; Uninstall popHealth quality measures
RMDIR /r $INSTDIR\measures
; Uninstall redis
; Stop task and remove scheduled task.
ExecWait 'schtasks.exe /end /tn "popHealth Redis Server"'
push "popHealth Redis Server"
Call un.DeleteTask
pop $0
DetailPrint "Results of deleting Redis Server task: $0"
RMDIR /r "$redisdir"
; Uninstall mongodb
ExecWait '"$mongodir\bin\mongod" --remove'
RMDIR /r "$mongodir"
; Uninstall the Bundler gem
ExecWait "gem.bat uninstall -x bundler"
; Uninstall ruby -- Should we do a silent uninstall
; TODO: Did we really install it?
MessageBox MB_ICONINFORMATION|MB_YESNO 'We installed Ruby. Do you want us to uninstall it?' \
/SD IDYES IDNO skiprubyuninst
ReadRegStr $0 HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{BD5F3A9C-22D5-4C1D-AEA0-ED1BE83A1E67}_is1" \
"UninstallString"
ExecWait '$0'
skiprubyuninst:
; Remove files and uninstaller
Delete $INSTDIR\uninstall.exe
Delete $INSTDIR\popHealth.URL
; Remove shortcuts, if any
Delete "$SMPROGRAMS\popHealth\*.*"
; Remove directories used
RMDir "$SMPROGRAMS\popHealth"
RMDIR "$INSTDIR\popHealth"
RMDir "$INSTDIR"
SectionEnd
;=============================================================================
; UTILITY FUNCTIONS
;=============================================================================
;--------------------------------
; Functions for Custom pages
; These are window handles of the controls in the Proxy Settings page
Var proxyTitleLabel
Var proxyServerLabel
Var proxyServerText
Var proxyPortLabel
var proxyPortText
var proxyUseProxyCheckbox
; Window handle of window a callback was invoked for
var hwnd
; Values the user entered in the Proxy Settings page
var useProxy
var proxyServer
var proxyPort
;-------------------
; Collect proxy info
Function ProxySettingsPage
!insertmacro MUI_HEADER_TEXT $(ProxyPage_TITLE) $(ProxyPage_SUBTITLE)
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 12u "Configure Proxy to Access the Internet:"
pop $proxyTitleLabel
${NSD_CreateCheckBox} 0 13u 80u 12u "Use Proxy Server"
pop $proxyUseProxyCheckbox
${NSD_OnClick} $proxyUseProxyCheckbox ProxySettingsUseProxyClick
${NSD_SetState} $proxyUseProxyCheckbox $useProxy
${NSD_CreateLabel} 0 28u 80u 12u "Http Proxy Server:"
pop $proxyServerLabel
${NSD_CreateText} 90u 28u 100u 12u $proxyServer
pop $proxyServerText
EnableWindow $proxyServerText 0 # start out disabled
${NSD_CreateLabel} 0 43u 80u 12u "Port:"
pop $proxyPortLabel
${NSD_CreateNumber} 90u 43u 100u 12u $proxyPort
pop $proxyPortText
EnableWindow $proxyPortText 0 # start out disabled
nsDialogs::Show
FunctionEnd
Function ProxySettingsLeave
${NSD_GetState} $proxyUseProxyCheckbox $useProxy
${If} $useProxy == 1
${NSD_GetText} $proxyServerText $proxyServer
${NSD_GetText} $proxyPortText $proxyPort
; Ensure that the proxy server is set
StrCmp $proxyServer '' 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "Proxy server cannot be blank!"
Abort
push $0
StrCpy $0 'http://$proxyServer'
; Append :port only if port is set
StrCmp $proxyPort '' +2
StrCpy $0 '$0:$proxyPort'
; This will permanently set the environment variable for future use of popHealth
!insertmacro AddEnvVarToReg 'http_proxy' $0
!insertmacro AddEnvVarToReg 'https_proxy' $0
; We will also need these environment variables defined for later install tasks
!insertmacro SetInstallerEnvVar 'http_proxy' $0
!insertmacro SetInstallerEnvVar 'https_proxy' $0
pop $0
${EndIf}
FunctionEnd
Function ProxySettingsUseProxyClick
pop $hwnd
${NSD_GetState} $hwnd $0
${If} $0 == 1
EnableWindow $proxyServerText 1
EnableWindow $proxyPortText 1
${Else}
EnableWindow $proxyServerText 0
EnableWindow $proxyPortText 0
${EndIf}
FunctionEnd
; This function removes the environment variable we might have installed
Function un.ProxySettingsPage
DeleteRegValue ${env_allusers} 'http_proxy'
DeleteRegValue ${env_allusers} 'https_proxy'
ClearErrors
FunctionEnd
; This function is called when the installer starts. It is used to initialize some
; needed variables
Function .onInit
StrCpy $systemdrive $WINDIR 2
; The default installation directory
; TODO: change this to $systemdrive\projects for final version.
StrCpy $INSTDIR "$systemdrive\proj\popHealth\"
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
push $0
ReadRegStr $0 HKLM "Software\popHealth" "Install_Dir"
IfFileExists $0 0 +2
StrCpy $INSTDIR $0
pop $0
!insertmacro SetRubyDir
StrCpy $mongodir "$systemdrive\mongodb-2.0.1"
StrCpy $redisdir "$systemdrive\redis-2.4.0"
FunctionEnd
Function un.onInit
StrCpy $systemdrive $WINDIR 2
StrCpy $mongodir "$systemdrive\mongodb-2.0.1"
StrCpy $redisdir "$systemdrive\redis-2.4.0"
FunctionEnd
; This function adds the passed directory to the path (only for installer and subprocesses)
Function AddToPath
; Store registers and pop params
System::Store "S r0"
; Get the current path
ReadEnvStr $R1 PATH
; Add the new directory to the end of the path
StrCpy $R1 "$0;$R1"
; Set the new path in the environment
; System::Call "kernel32::SetEnvironmentVariable(t 'PATH', t R1) i.R9"
!insertmacro SetInstallerEnvVar 'PATH' $R1
; restore registers
System::Store "l"
FunctionEnd