source: trunk/installation_files/windows/installer.nsi @ 8438

Last change on this file since 8438 was 8427, checked in by davies, 13 years ago

Adding the trapezoidal channel validation test, and editing the ANUGA manual

File size: 16.8 KB
Line 
1!include "config.nsh"
2!include "EnvVarUpdate.nsh"
3
4# libraries used
5!include nsDialogs.nsh
6!include LogicLib.nsh
7
8# nsis config
9Name "${ProductName}"
10OutFile "${ExecutableName}"
11
12!define TemporaryFilesDir "$PLUGINSDIR\files" # used for files only needed by the installer itself, like the 3rd party installers
13
14SetCompressor "lzma" # codec to compress all delivered files
15
16RequestExecutionLevel "admin" # execution level the installer requests, user or admin
17
18# user vars
19# mainly used for uninstallation
20Var PackagesDir # anuga install root ($python\site-packages\anuga)
21Var ViewerInst # has viewer been installed
22Var ViewerDir # anuga viewer install root ($programfiles\anuga viewer)
23Var PythonInst # has python been installed
24Var PythonDir # python install root (C:\python)
25Var MinGWInst # has mingw been installed
26Var MinGWDir # mingw install root ($programfiles\mingw)
27Var NetCDFDir # netcdf binaries ($commonfiles\netcdf)
28Var ScientificPythonInst #has ScientificPython been installed
29Var NumpyInst #has Numpy been installed
30Var MatplotlibInst #has matplotlib beeen installed
31# support variables for user dialogs
32Var Dialog
33Var Control0
34Var Control1
35Var Control2
36Var Control3
37Var Control4
38
39# UI config
40!define MUI_ICON "${InstallerIcon}" # installers icon
41
42# settings for the dialog header image
43!define MUI_HEADERIMAGE
44!define MUI_HEADERIMAGE_BITMAP "${HeaderBitmap}" 
45!define MUI_HEADERIMAGE_RIGHT
46
47# bitmap on the welcome and finish page
48!define MUI_WELCOMEFINISHPAGE_BITMAP "${WelcomeFinishBitmap}"
49
50# the modern ui library
51!include MUI2.nsh
52
53# installer pages
54!insertmacro MUI_PAGE_WELCOME # welcome and introduction page
55Page custom EnterPython # install python and select directory
56Page custom EnterExtensions LeaveExtensions # install extensions
57Page custom EnterMinGW # install mingw and select directory
58!define MUI_LICENSEPAGE_TEXT_TOP "$(LicenseScrollText)"
59!insertmacro MUI_PAGE_LICENSE "$(LicenseFile)" # license page
60!insertmacro MUI_PAGE_COMPONENTS # select other install options
61!insertmacro MUI_PAGE_INSTFILES # compile/test/install anuga and viewer
62!define MUI_FINISHPAGE_LINK "$(WebsiteLabel)"
63!define MUI_FINISHPAGE_LINK_LOCATION "${Website}"
64!define MUI_FINISHPAGE_NOREBOOTSUPPORT
65!insertmacro MUI_PAGE_FINISH # end of installation
66
67## uninstaller pages
68!insertmacro MUI_UNPAGE_COMPONENTS # select what to uninstall
69!insertmacro MUI_UNPAGE_CONFIRM # confirm uninstallation
70!insertmacro MUI_UNPAGE_INSTFILES # do it
71
72## supported languages (string tables)
73!include "translation.nsh"
74
75# installer
76
77Section "$(section_mvcrp)" sec_mvcrp
78  #SectionIn RO # read only, it's required
79  SetOutPath "${TemporaryFilesDir}"
80  File "${FileSource}\prereqs\${MVCRPInst}"
81  ExecWait "${TemporaryFilesDir}\${MVCRPInst} /Q"
82SectionEnd
83
84Section "$(section_netcdf)" sec_ncdf
85  #SectionIn RO # read only, it's required
86  # install netcdf to default, no custom selection here
87  StrCpy $NetCDFDir "${NetCDFDefaultFolder}"
88  SetOutPath $NetCDFDir
89  File /r "${FileSource}\prereqs\${NetCDFFolder}\*.*" # file extraction
90SectionEnd
91
92SectionGroup /e "!$(section_anuga_viewer)" sec_viewer
93  Section
94  # install anuga viewer
95    StrCpy $ViewerDir "${AnugaViewerDefaultFolder}"
96    SetOutPath $ViewerDir
97   
98    File /r "${FileSource}\${AnugaViewerFolder}\*.*"
99    StrCpy $ViewerInst "1"
100  SectionEnd
101 
102  Section "$(section_anuga_viewer_extension)" sec_ext
103  # register file extension with anuga viewer
104    WriteRegStr HKCR "${ViewerExtension}" "" "${ViewerExtensionAlias}"
105    WriteRegStr HKCR "${ViewerExtensionAlias}\shell\open\command" "" "$ViewerDir\animate.exe %1" 
106  SectionEnd
107SectionGroupEnd
108
109Section "!$(section_anuga_install)" sec_install # anuga main
110  SectionIn RO
111  # update path environment 
112  ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$PythonDir"
113  ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$MinGWDir\bin"
114  ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$NetCDFDir"
115  #ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "PATH"
116  #StrCpy $0 "$0;$PythonDir;$MinGWDir\bin;$NetCDFDir;"
117  #WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "PATH" $0
118  SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
119  StrCpy $PackagesDir "$PythonDir\Lib\site-packages"
120 
121  # delete old files
122  SetOutPath "$PackagesDir"
123  RMDir /r "$PackagesDir\anuga"
124  RMDir /r "$PackagesDir\anuga_validation"
125 
126  # copy anuga files
127  File /r "${FileSource}\${AnugaFolder}\anuga"
128  File /r "${FileSource}\${AnugaFolder}\anuga_validation"
129
130  #Set environment path only for the installer to access gcc and python
131  ReadEnvStr $R0 "PATH"
132  StrCpy $R0 "$R0;$MinGWDir\bin;$PythonDir\DLLs;$PythonDir"
133  System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", R0).r2'
134  ReadEnvStr $R0 "PATH"
135
136  # compile anuga
137  SetOutPath "$PackagesDir\anuga"
138  ExecWait '"$PythonDir\python.exe" "$OUTDIR\compile_all.py"'
139SectionEnd
140
141Section "$(section_anuga_test)" sec_test
142  # test anuga
143  SetOutPath "$PackagesDir\anuga"
144  ExecWait '"$PythonDir\python.exe" "$OUTDIR\test_all.py"'
145SectionEnd
146
147Section "$(section_anuga_validate)" sec_validate
148  # validate anuga
149  SetOutPath "$PackagesDir\anuga_validation\automated_validation_tests"
150  Exec '"$PythonDir\python.exe" "$OUTDIR\validate_all.py"'
151SectionEnd
152
153!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
154  !insertmacro MUI_DESCRIPTION_TEXT ${sec_mvcrp} $(description_mvcrp)
155  !insertmacro MUI_DESCRIPTION_TEXT ${sec_ncdf} $(description_netcdf)
156  !insertmacro MUI_DESCRIPTION_TEXT ${sec_install} $(description_anuga_install)
157  !insertmacro MUI_DESCRIPTION_TEXT ${sec_test} $(description_anuga_test)
158  !insertmacro MUI_DESCRIPTION_TEXT ${sec_validate} $(description_anuga_validate)
159  !insertmacro MUI_DESCRIPTION_TEXT ${sec_viewer} $(description_anuga_viewer)
160  !insertmacro MUI_DESCRIPTION_TEXT ${sec_ext} $(description_anuga_viewer_extension)
161!insertmacro MUI_FUNCTION_DESCRIPTION_END
162
163# function executed on initialization of the installer
164Function .onInit
165    # prevent the installer from beeing executed twice a time
166    System::Call "kernel32::CreateMutexA(i 0, i 0, t '$(^Name)') i .n ?e" # create a mutex
167    Pop $0
168    StrCmp $0 0 0 find
169  Return # launch normaly if mutex could be created = no other instance running
170 
171  find:
172    StrLen $0 "$(^Name)"
173    IntOp $0 $0 + 1 
174  loop:
175    FindWindow $1 '#32770' '' 0 $1 # search the installers window if another instance is already running
176    IntCmp $1 0 +4
177    System::Call /NOUNLOAD "user32.dll::GetWindowText(i r1, t .r2, i r0) i.n"
178    StrCmp $2 "$(^Name)" 0 loop # check back for correct window text
179    System::Call "user32::SetForegroundWindow(i r1) i.n" # bring it to front if found
180  Abort # then exit
181FunctionEnd
182
183
184Function .onGUIEnd
185  RMDir /r "${TemporaryFilesDir}"
186FunctionEnd
187
188
189Function EnterPython
190# installbutton and directory selection
191  !insertmacro MUI_HEADER_TEXT "$(page_python_title)" "$(page_python_subtitle)"
192  nsDialogs::Create 1018
193  Pop $Dialog
194  StrCmp $Dialog "error" 0 +2
195  Abort
196  GetDlgItem $Control0 $HWNDPARENT 1
197 
198  # get python directory
199  ReadRegStr $PythonDir HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe" ""
200  StrLen $0 $PythonDir
201  IntOp $0 $0 - 10
202  StrCpy $PythonDir $PythonDir $0
203 
204  # select default, if possible from registry
205  IfFileExists "$PythonDir\python.exe" +2
206  StrCpy $PythonDir "C:\Python25"
207 
208  # create dialog items
209  ${NSD_CreateLabel} 10 10 430 28 "$(page_python_install_label)"
210  ${NSD_CreateButton} 40 50 370 24 "$(page_python_install_button)"
211  Pop $Control1
212  ${NSD_CreateLabel} 10 100 430 28 "$(page_python_browse_label)"
213  ${NSD_CreateDirRequest} 40 140 290 24 "$PythonDir"
214  Pop $Control2
215  ${NSD_CreateButton} 340 140 70 24 "$(page_python_browse_button)"
216  Pop $Control3
217  ${NSD_CreateLabel} 10 190 430 28 "$(page_python_outro)"
218 
219  # register dialog actions
220  ${NSD_OnClick} $Control1 RunPythonSetup
221  ${NSD_OnChange} $Control2 ValidatePythonDir
222  ${NSD_OnClick} $Control3 BrowsePythonDir
223 
224  # check for valid python directory
225  Call ValidatePythonDir
226 
227  # show the page
228  nsDialogs::Show
229FunctionEnd
230
231# extract and run the python installer
232Function RunPythonSetup
233  SetOutPath "${TemporaryFilesDir}"
234  File "${FileSource}\prereqs\${PythonInst}"
235  ExecShell "" '"${TemporaryFilesDir}\${PythonInst}"'
236  StrCpy $PythonInst "1"
237  EnableWindow $Control0 1 # enable next button
238FunctionEnd
239
240# browse for the python dir with a folder dialog
241Function BrowsePythonDir
242  nsDialogs::SelectFolderDialog "$(page_python_browse_dialog_title)" $PythonDir
243  Pop $0
244  StrCmp $0 "error" 0 +2
245  Return
246  ${NSD_SetText} $Control2 $0
247  Call ValidatePythonDir
248FunctionEnd
249
250# enable next button if selected python dir is valid
251Function ValidatePythonDir
252  ${NSD_GetText} $Control2 $PythonDir
253  IfFileExists "$PythonDir\python.exe" ok
254 
255  EnableWindow $Control0 0
256  Return
257  ok:
258  EnableWindow $Control0 1
259FunctionEnd
260
261
262Function EnterExtensions
263# installbuttons for missing extensions
264  !insertmacro MUI_HEADER_TEXT "$(page_extensions_title)" "$(page_extensions_subtitle)"
265  nsDialogs::Create 1018
266  Pop $Dialog
267  StrCmp $Dialog "error" 0 +2
268  Abort
269  GetDlgItem $Control0 $HWNDPARENT 1
270 
271  ${NSD_CreateLabel} 10 10 430 28 "$(page_extensions_intro)"
272  ${NSD_CreateLabel} 40 50 350 28 "$(page_extensions_numpy_ok)"
273  Pop $Control1
274  ${NSD_CreateLabel} 40 100 350 28 "$(page_extensions_scientific_ok)"
275  Pop $Control2
276  ${NSD_CreateLabel} 40 150 350 28 "$(page_extensions_matplotlib_ok)"
277  Pop $Control3
278  ${NSD_CreateLabel} 10 190 430 28 "$(page_extensions_outro_next)"
279  Pop $Control4
280 
281  StrCpy $1 "0"
282  StrCpy $2 "0"
283  StrCpy $3 "0"
284  StrCpy $4 "0"
285  StrCpy $5 "0"
286  IfFileExists "$PackagesDir\Numpy\*.py" 0 +2
287  IntOp $1 $1 + 1
288  IfFileExists "$PackagesDir\Scientific\*.py" 0 +2
289  IntOp $2 $2 + 1
290  IfFileExists "$PackagesDir\matplotlib\*.py" 0 +2
291  IntOp $3 $3 + 1
292  IntOp $4 $2 + $1
293  IntOp $5 $4 + $3
294 
295  IntCmp $1 0 0 num_ok num_ok
296  ${NSD_SetText} $Control1 "$(page_extensions_numpy_label_install)"
297  num_ok:
298 
299  IntCmp $2 0 0 scien_ok scien_ok
300  ${NSD_SetText} $Control2 "$(page_extensions_scientific_label_install)"
301  scien_ok:
302
303  IntCmp $3 0 0 matp_ok matp_ok
304  ${NSD_SetText} $Control3 "$(page_extensions_matplotlib_label_install)"
305  matp_ok:
306
307  IntCmp $5 3 no_inst
308  ${NSD_SetText} $Control4 "$(page_extensions_outro_install)"
309  ${NSD_SetText} $Control0 "$(^InstallBtn)"
310  no_inst:
311 
312  nsDialogs::Show
313FunctionEnd
314
315Function LeaveExtensions
316  IntCmp $5 0 +2
317  Return
318
319  SetOutPath "${TemporaryFilesDir}"
320 
321  IntCmp $1 1 after_num
322  File "${FileSource}\prereqs\${NumpyInst}"
323  ExecWait '"${TemporaryFilesDir}\${NumpyInst}"'
324  StrCpy $NumpyInst "1"
325  after_num:
326 
327  StrCmp $2 1 after_scien
328  File "${FileSource}\prereqs\${ScientificInst}"
329  ExecWait '"${TemporaryFilesDir}\${ScientificInst}"'
330  StrCpy $ScientificPythonInst "1"
331  after_scien:
332
333  StrCmp $3 1 after_matp
334  File "${FileSource}\prereqs\${MatplotlibInst}"
335  ExecWait '"${TemporaryFilesDir}\${MatplotlibInst}"'
336  StrCpy $MatplotlibInst "1"
337  after_matp:
338
339FunctionEnd
340
341
342Function EnterMinGW
343# installbutton and directory selection
344  !insertmacro MUI_HEADER_TEXT "$(page_mingw_title)" "$(page_mingw_subtitle)"
345  nsDialogs::Create 1018
346  Pop $Dialog
347  StrCmp $Dialog "error" 0 +2
348  Abort
349  GetDlgItem $Control0 $HWNDPARENT 1
350 
351  ReadRegStr $MinGWDir HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MinGW" "InstallLocation"
352  IfFileExists "$MinGWDir\bin\gcc.exe" +2
353  StrCpy $MinGWDir "C:\MinGW"
354 
355  ${NSD_CreateLabel} 10 10 430 28 "$(page_mingw_install_label)"
356  ${NSD_CreateButton} 40 50 370 24 "$(page_mingw_install_button)"
357  Pop $Control1
358  ${NSD_CreateLabel} 10 100 430 28 "$(page_mingw_browse_label)"
359  ${NSD_CreateDirRequest} 40 140 290 24 "$MinGWDir"
360  Pop $Control2
361  ${NSD_CreateButton} 340 140 70 24 "$(page_mingw_browse_button)"
362  Pop $Control3
363  ${NSD_CreateLabel} 10 190 430 28 "$(page_mingw_outro)"
364 
365  ${NSD_OnClick} $Control1 RunMinGWSetup
366  ${NSD_OnChange} $Control2 ValidateMinGWDir
367  ${NSD_OnClick} $Control3 BrowseMinGWDir
368 
369  Call ValidateMinGWDir
370  nsDialogs::Show
371FunctionEnd
372
373Function RunMinGWSetup
374  SetOutPath "${TemporaryFilesDir}"
375  File "${FileSource}\prereqs\${MinGWInst}"
376  ExecWait '"${TemporaryFilesDir}\${MinGWInst}"'
377  StrCpy $MinGWInst "1"
378  Call ValidateMinGWDir
379FunctionEnd
380
381Function BrowseMinGWDir
382  nsDialogs::SelectFolderDialog "$(page_mingw_browse_dialog_title)" $MinGWDir
383  Pop $0
384  StrCmp $0 "error" 0 +2
385  Return
386  ${NSD_SetText} $Control2 $0
387  Call ValidateMinGWDir
388FunctionEnd
389
390Function ValidateMinGWDir
391  ${NSD_GetText} $Control2 $MinGWDir
392  IfFileExists "$MinGWDir\bin\gcc.exe" ok
393 
394  EnableWindow $Control0 0
395  Return
396  ok:
397  EnableWindow $Control0 1
398 
399  #Add the MingW\bin path to the envorinment variables
400  #${EnvVarUpdate} $0 "PATH" "A" "HKCU" "$MinGWDir\bin"
401FunctionEnd
402
403Section -uninst_registry
404  SectionIn RO
405  SetOutPath "$PackagesDir\anuga"
406  # write the uninstaller executable to disk
407  WriteUninstaller "$OUTDIR\${UninstallerExecutableName}"
408  # uninstall entry in System->Software, very detailed information :)
409  WriteRegStr HKLM "${UninstallerRegistryKey}" "DisplayName" "${ProductName}"
410  WriteRegStr HKLM "${UninstallerRegistryKey}" "DisplayVersion" "${ProductVersion}"
411  WriteRegStr HKLM "${UninstallerRegistryKey}" "DisplayIcon" "$OUTDIR\${UninstallerExecutableName},0"
412  WriteRegStr HKLM "${UninstallerRegistryKey}" "Publisher" "${Company}"
413  WriteRegStr HKLM "${UninstallerRegistryKey}" "URLInfoAbout" "${Website}"
414  WriteRegStr HKLM "${UninstallerRegistryKey}" "InstallLocation" "$INSTDIR"
415  WriteRegStr HKLM "${UninstallerRegistryKey}" "InstallSource" "$EXEDIR"
416  WriteRegStr HKLM "${UninstallerRegistryKey}" "UninstallString" "$OUTDIR\${UninstallerExecutableName}"
417  WriteRegStr HKLM "${UninstallerRegistryKey}" "ModifyPath" "$OUTDIR\${UninstallerExecutableName}"
418  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "AnugaViewerInstalled" $ViewerInst
419  WriteRegStr HKLM "SOFTWARE\${ProductName}" "AnugaViewerDir" $ViewerDir
420  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "PythonInstalled" $PythonInst
421  WriteRegStr HKLM "SOFTWARE\${ProductName}" "PythonDir" $PythonDir
422  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "ScientificPythonInstalled" $ScientificPythonInst
423  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "NumpyInstalled" $NumpyInst
424  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "MatplotlibInstalled" $MatplotlibInst
425  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "MinGWInstalled" $MinGWInst
426  WriteRegStr HKLM "SOFTWARE\${ProductName}" "MinGWDir" "$MinGWDir"
427  WriteRegStr HKLM "SOFTWARE\${ProductName}" "NetCDFDir" "$NetCDFDir"
428SectionEnd
429
430
431# uninstaller
432Section "un.install"
433  #Remove the MingW\bin path from the envorinment variables
434  ReadRegStr $PythonDir HKEY_LOCAL_MACHINE "SOFTWARE\${ProductName}" "PythonDir"
435  ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$PythonDir"
436  ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$PythonDir\DLLs"
437  ReadRegStr $NetCDFDir HKEY_LOCAL_MACHINE "SOFTWARE\${ProductName}" "NetCDFDir"
438  ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$NetCDFDir"
439  ReadRegStr $MinGWDir HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MinGW" "InstallLocation"
440  ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$MinGWDir\bin"
441 
442  ReadRegStr $INSTDIR HKLM "SOFTWARE\${ProductName}" "PythonDir"
443  SetOutPath "$INSTDIR"
444  RMDir /r "$INSTDIR\Lib\site-packages\anuga"
445  RMDir /r "$INSTDIR\Lib\site-packages\anuga_validation"
446 
447  ReadRegDWORD $0 HKLM "SOFTWARE\${ProductName}" "AnugaViewerInstalled"
448  IntCmp $0 "1" 0 post_viewer post_viewer
449  ReadRegStr $INSTDIR HKLM "SOFTWARE\${ProductName}" "AnugaViewerDir"
450  RMDir /r "$INSTDIR"
451  post_viewer:
452 
453  ReadRegStr $INSTDIR HKLM "SOFTWARE\${ProductName}" "NetCDFDir"
454  RMDir /r "$INSTDIR"
455 
456  DeleteRegKey HKCR "${ViewerExtension}"
457  DeleteRegKey HKCR "${ViewerExtensionAlias}"
458  DeleteRegKey HKLM "${UninstallerRegistryKey}"
459  DeleteRegKey HKLM "SOFTWARE\${ProductName}"
460
461
462SectionEnd
463
464# function executed on initialization of the uninstaller
465Function un.onInit
466    # prevent the uninstaller from beeing executed twice a time
467    System::Call "kernel32::CreateMutexA(i 0, i 0, t '$(^Name)') i .n ?e" # create a mutex
468    Pop $0
469    StrCmp $0 0 0 +2
470  Return # launch normaly if mutex could be created = no other instance running
471   
472    StrLen $0 "$(^Name)"
473    IntOp $0 $0 + 1 
474  loop:
475    FindWindow $1 '#32770' '' 0 $1 # search the uninstallers window if another instance is already running
476    IntCmp $1 0 +4
477    System::Call /NOUNLOAD "user32.dll::GetWindowText(i r1, t .r2, i r0) i.n"
478    StrCmp $2 "$(^Name)" 0 loop # check back for correct window text
479    System::Call "user32::SetForegroundWindow(i r1) i.n" # bring it to front if found
480  Abort # then exit
481FunctionEnd
482
483#EOF
Note: See TracBrowser for help on using the repository browser.