source: installation_files/windows/installer.nsi @ 7528

Last change on this file since 7528 was 7528, checked in by nariman, 15 years ago

Fixed up path for validate_all during installation.

  • Property svn:executable set to *
File size: 16.9 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_core"
125  RMDir /r "$PackagesDir\anuga_validation"
126 
127  # copy anuga files
128  File /r "${FileSource}\${AnugaFolder}\anuga"
129  File /r "${FileSource}\${AnugaFolder}\anuga_core"
130  File /r "${FileSource}\${AnugaFolder}\anuga_validation"
131
132  #Set environment path only for the installer to access gcc and python
133  ReadEnvStr $R0 "PATH"
134  StrCpy $R0 "$R0;$MinGWDir\bin;$PythonDir\DLLs;$PythonDir"
135  System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", R0).r2'
136  ReadEnvStr $R0 "PATH"
137
138  # compile anuga
139  SetOutPath "$PackagesDir\anuga"
140  ExecWait '"$PythonDir\python.exe" "$OUTDIR\compile_all.py"'
141SectionEnd
142
143Section "$(section_anuga_test)" sec_test
144  # test anuga
145  SetOutPath "$PackagesDir\anuga"
146  ExecWait '"$PythonDir\python.exe" "$OUTDIR\test_all.py"'
147SectionEnd
148
149Section "$(section_anuga_validate)" sec_validate
150  # validate anuga
151  SetOutPath "$PackagesDir\anuga_validation\automated_validation_tests"
152  Exec '"$PythonDir\python.exe" "$OUTDIR\validate_all.py"'
153SectionEnd
154
155!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
156  !insertmacro MUI_DESCRIPTION_TEXT ${sec_mvcrp} $(description_mvcrp)
157  !insertmacro MUI_DESCRIPTION_TEXT ${sec_ncdf} $(description_netcdf)
158  !insertmacro MUI_DESCRIPTION_TEXT ${sec_install} $(description_anuga_install)
159  !insertmacro MUI_DESCRIPTION_TEXT ${sec_test} $(description_anuga_test)
160  !insertmacro MUI_DESCRIPTION_TEXT ${sec_validate} $(description_anuga_validate)
161  !insertmacro MUI_DESCRIPTION_TEXT ${sec_viewer} $(description_anuga_viewer)
162  !insertmacro MUI_DESCRIPTION_TEXT ${sec_ext} $(description_anuga_viewer_extension)
163!insertmacro MUI_FUNCTION_DESCRIPTION_END
164
165# function executed on initialization of the installer
166Function .onInit
167    # prevent the installer from beeing executed twice a time
168    System::Call "kernel32::CreateMutexA(i 0, i 0, t '$(^Name)') i .n ?e" # create a mutex
169    Pop $0
170    StrCmp $0 0 0 find
171  Return # launch normaly if mutex could be created = no other instance running
172 
173  find:
174    StrLen $0 "$(^Name)"
175    IntOp $0 $0 + 1 
176  loop:
177    FindWindow $1 '#32770' '' 0 $1 # search the installers window if another instance is already running
178    IntCmp $1 0 +4
179    System::Call /NOUNLOAD "user32.dll::GetWindowText(i r1, t .r2, i r0) i.n"
180    StrCmp $2 "$(^Name)" 0 loop # check back for correct window text
181    System::Call "user32::SetForegroundWindow(i r1) i.n" # bring it to front if found
182  Abort # then exit
183FunctionEnd
184
185
186Function .onGUIEnd
187  RMDir /r "${TemporaryFilesDir}"
188FunctionEnd
189
190
191Function EnterPython
192# installbutton and directory selection
193  !insertmacro MUI_HEADER_TEXT "$(page_python_title)" "$(page_python_subtitle)"
194  nsDialogs::Create 1018
195  Pop $Dialog
196  StrCmp $Dialog "error" 0 +2
197  Abort
198  GetDlgItem $Control0 $HWNDPARENT 1
199 
200  # get python directory
201  ReadRegStr $PythonDir HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe" ""
202  StrLen $0 $PythonDir
203  IntOp $0 $0 - 10
204  StrCpy $PythonDir $PythonDir $0
205 
206  # select default, if possible from registry
207  IfFileExists "$PythonDir\python.exe" +2
208  StrCpy $PythonDir "C:\Python25"
209 
210  # create dialog items
211  ${NSD_CreateLabel} 10 10 430 28 "$(page_python_install_label)"
212  ${NSD_CreateButton} 40 50 370 24 "$(page_python_install_button)"
213  Pop $Control1
214  ${NSD_CreateLabel} 10 100 430 28 "$(page_python_browse_label)"
215  ${NSD_CreateDirRequest} 40 140 290 24 "$PythonDir"
216  Pop $Control2
217  ${NSD_CreateButton} 340 140 70 24 "$(page_python_browse_button)"
218  Pop $Control3
219  ${NSD_CreateLabel} 10 190 430 28 "$(page_python_outro)"
220 
221  # register dialog actions
222  ${NSD_OnClick} $Control1 RunPythonSetup
223  ${NSD_OnChange} $Control2 ValidatePythonDir
224  ${NSD_OnClick} $Control3 BrowsePythonDir
225 
226  # check for valid python directory
227  Call ValidatePythonDir
228 
229  # show the page
230  nsDialogs::Show
231FunctionEnd
232
233# extract and run the python installer
234Function RunPythonSetup
235  SetOutPath "${TemporaryFilesDir}"
236  File "${FileSource}\prereqs\${PythonInst}"
237  ExecShell "" '"${TemporaryFilesDir}\${PythonInst}"'
238  StrCpy $PythonInst "1"
239  EnableWindow $Control0 1 # enable next button
240FunctionEnd
241
242# browse for the python dir with a folder dialog
243Function BrowsePythonDir
244  nsDialogs::SelectFolderDialog "$(page_python_browse_dialog_title)" $PythonDir
245  Pop $0
246  StrCmp $0 "error" 0 +2
247  Return
248  ${NSD_SetText} $Control2 $0
249  Call ValidatePythonDir
250FunctionEnd
251
252# enable next button if selected python dir is valid
253Function ValidatePythonDir
254  ${NSD_GetText} $Control2 $PythonDir
255  IfFileExists "$PythonDir\python.exe" ok
256 
257  EnableWindow $Control0 0
258  Return
259  ok:
260  EnableWindow $Control0 1
261FunctionEnd
262
263
264Function EnterExtensions
265# installbuttons for missing extensions
266  !insertmacro MUI_HEADER_TEXT "$(page_extensions_title)" "$(page_extensions_subtitle)"
267  nsDialogs::Create 1018
268  Pop $Dialog
269  StrCmp $Dialog "error" 0 +2
270  Abort
271  GetDlgItem $Control0 $HWNDPARENT 1
272 
273  ${NSD_CreateLabel} 10 10 430 28 "$(page_extensions_intro)"
274  ${NSD_CreateLabel} 40 50 350 28 "$(page_extensions_numpy_ok)"
275  Pop $Control1
276  ${NSD_CreateLabel} 40 100 350 28 "$(page_extensions_scientific_ok)"
277  Pop $Control2
278  ${NSD_CreateLabel} 40 150 350 28 "$(page_extensions_matplotlib_ok)"
279  Pop $Control3
280  ${NSD_CreateLabel} 10 190 430 28 "$(page_extensions_outro_next)"
281  Pop $Control4
282 
283  StrCpy $1 "0"
284  StrCpy $2 "0"
285  StrCpy $3 "0"
286  StrCpy $4 "0"
287  StrCpy $5 "0"
288  IfFileExists "$PackagesDir\Numpy\*.py" 0 +2
289  IntOp $1 $1 + 1
290  IfFileExists "$PackagesDir\Scientific\*.py" 0 +2
291  IntOp $2 $2 + 1
292  IfFileExists "$PackagesDir\matplotlib\*.py" 0 +2
293  IntOp $3 $3 + 1
294  IntOp $4 $2 + $1
295  IntOp $5 $4 + $3
296 
297  IntCmp $1 0 0 num_ok num_ok
298  ${NSD_SetText} $Control1 "$(page_extensions_numpy_label_install)"
299  num_ok:
300 
301  IntCmp $2 0 0 scien_ok scien_ok
302  ${NSD_SetText} $Control2 "$(page_extensions_scientific_label_install)"
303  scien_ok:
304
305  IntCmp $3 0 0 matp_ok matp_ok
306  ${NSD_SetText} $Control3 "$(page_extensions_matplotlib_label_install)"
307  matp_ok:
308
309  IntCmp $5 3 no_inst
310  ${NSD_SetText} $Control4 "$(page_extensions_outro_install)"
311  ${NSD_SetText} $Control0 "$(^InstallBtn)"
312  no_inst:
313 
314  nsDialogs::Show
315FunctionEnd
316
317Function LeaveExtensions
318  IntCmp $5 0 +2
319  Return
320
321  SetOutPath "${TemporaryFilesDir}"
322 
323  IntCmp $1 1 after_num
324  File "${FileSource}\prereqs\${NumpyInst}"
325  ExecWait '"${TemporaryFilesDir}\${NumpyInst}"'
326  StrCpy $NumpyInst "1"
327  after_num:
328 
329  StrCmp $2 1 after_scien
330  File "${FileSource}\prereqs\${ScientificInst}"
331  ExecWait '"${TemporaryFilesDir}\${ScientificInst}"'
332  StrCpy $ScientificPythonInst "1"
333  after_scien:
334
335  StrCmp $3 1 after_matp
336  File "${FileSource}\prereqs\${MatplotlibInst}"
337  ExecWait '"${TemporaryFilesDir}\${MatplotlibInst}"'
338  StrCpy $MatplotlibInst "1"
339  after_matp:
340
341FunctionEnd
342
343
344Function EnterMinGW
345# installbutton and directory selection
346  !insertmacro MUI_HEADER_TEXT "$(page_mingw_title)" "$(page_mingw_subtitle)"
347  nsDialogs::Create 1018
348  Pop $Dialog
349  StrCmp $Dialog "error" 0 +2
350  Abort
351  GetDlgItem $Control0 $HWNDPARENT 1
352 
353  ReadRegStr $MinGWDir HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MinGW" "InstallLocation"
354  IfFileExists "$MinGWDir\bin\gcc.exe" +2
355  StrCpy $MinGWDir "C:\MinGW"
356 
357  ${NSD_CreateLabel} 10 10 430 28 "$(page_mingw_install_label)"
358  ${NSD_CreateButton} 40 50 370 24 "$(page_mingw_install_button)"
359  Pop $Control1
360  ${NSD_CreateLabel} 10 100 430 28 "$(page_mingw_browse_label)"
361  ${NSD_CreateDirRequest} 40 140 290 24 "$MinGWDir"
362  Pop $Control2
363  ${NSD_CreateButton} 340 140 70 24 "$(page_mingw_browse_button)"
364  Pop $Control3
365  ${NSD_CreateLabel} 10 190 430 28 "$(page_mingw_outro)"
366 
367  ${NSD_OnClick} $Control1 RunMinGWSetup
368  ${NSD_OnChange} $Control2 ValidateMinGWDir
369  ${NSD_OnClick} $Control3 BrowseMinGWDir
370 
371  Call ValidateMinGWDir
372  nsDialogs::Show
373FunctionEnd
374
375Function RunMinGWSetup
376  SetOutPath "${TemporaryFilesDir}"
377  File "${FileSource}\prereqs\${MinGWInst}"
378  ExecWait '"${TemporaryFilesDir}\${MinGWInst}"'
379  StrCpy $MinGWInst "1"
380  Call ValidateMinGWDir
381FunctionEnd
382
383Function BrowseMinGWDir
384  nsDialogs::SelectFolderDialog "$(page_mingw_browse_dialog_title)" $MinGWDir
385  Pop $0
386  StrCmp $0 "error" 0 +2
387  Return
388  ${NSD_SetText} $Control2 $0
389  Call ValidateMinGWDir
390FunctionEnd
391
392Function ValidateMinGWDir
393  ${NSD_GetText} $Control2 $MinGWDir
394  IfFileExists "$MinGWDir\bin\gcc.exe" ok
395 
396  EnableWindow $Control0 0
397  Return
398  ok:
399  EnableWindow $Control0 1
400 
401  #Add the MingW\bin path to the envorinment variables
402  #${EnvVarUpdate} $0 "PATH" "A" "HKCU" "$MinGWDir\bin"
403FunctionEnd
404
405Section -uninst_registry
406  SectionIn RO
407  SetOutPath "$PackagesDir\anuga"
408  # write the uninstaller executable to disk
409  WriteUninstaller "$OUTDIR\${UninstallerExecutableName}"
410  # uninstall entry in System->Software, very detailed information :)
411  WriteRegStr HKLM "${UninstallerRegistryKey}" "DisplayName" "${ProductName}"
412  WriteRegStr HKLM "${UninstallerRegistryKey}" "DisplayVersion" "${ProductVersion}"
413  WriteRegStr HKLM "${UninstallerRegistryKey}" "DisplayIcon" "$OUTDIR\${UninstallerExecutableName},0"
414  WriteRegStr HKLM "${UninstallerRegistryKey}" "Publisher" "${Company}"
415  WriteRegStr HKLM "${UninstallerRegistryKey}" "URLInfoAbout" "${Website}"
416  WriteRegStr HKLM "${UninstallerRegistryKey}" "InstallLocation" "$INSTDIR"
417  WriteRegStr HKLM "${UninstallerRegistryKey}" "InstallSource" "$EXEDIR"
418  WriteRegStr HKLM "${UninstallerRegistryKey}" "UninstallString" "$OUTDIR\${UninstallerExecutableName}"
419  WriteRegStr HKLM "${UninstallerRegistryKey}" "ModifyPath" "$OUTDIR\${UninstallerExecutableName}"
420  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "AnugaViewerInstalled" $ViewerInst
421  WriteRegStr HKLM "SOFTWARE\${ProductName}" "AnugaViewerDir" $ViewerDir
422  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "PythonInstalled" $PythonInst
423  WriteRegStr HKLM "SOFTWARE\${ProductName}" "PythonDir" $PythonDir
424  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "ScientificPythonInstalled" $ScientificPythonInst
425  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "NumpyInstalled" $NumpyInst
426  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "MatplotlibInstalled" $MatplotlibInst
427  WriteRegDWORD HKLM "SOFTWARE\${ProductName}" "MinGWInstalled" $MinGWInst
428  WriteRegStr HKLM "SOFTWARE\${ProductName}" "MinGWDir" "$MinGWDir"
429  WriteRegStr HKLM "SOFTWARE\${ProductName}" "NetCDFDir" "$NetCDFDir"
430SectionEnd
431
432
433# uninstaller
434Section "un.install"
435  #Remove the MingW\bin path from the envorinment variables
436  ReadRegStr $PythonDir HKEY_LOCAL_MACHINE "SOFTWARE\${ProductName}" "PythonDir"
437  ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$PythonDir"
438  ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$PythonDir\DLLs"
439  ReadRegStr $NetCDFDir HKEY_LOCAL_MACHINE "SOFTWARE\${ProductName}" "NetCDFDir"
440  ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$NetCDFDir"
441  ReadRegStr $MinGWDir HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MinGW" "InstallLocation"
442  ${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$MinGWDir\bin"
443 
444  ReadRegStr $INSTDIR HKLM "SOFTWARE\${ProductName}" "PythonDir"
445  SetOutPath "$INSTDIR"
446  RMDir /r "$INSTDIR\Lib\site-packages\anuga"
447  RMDir /r "$INSTDIR\Lib\site-packages\anuga_core"
448  RMDir /r "$INSTDIR\Lib\site-packages\anuga_validation"
449 
450  ReadRegDWORD $0 HKLM "SOFTWARE\${ProductName}" "AnugaViewerInstalled"
451  IntCmp $0 "1" 0 post_viewer post_viewer
452  ReadRegStr $INSTDIR HKLM "SOFTWARE\${ProductName}" "AnugaViewerDir"
453  RMDir /r "$INSTDIR"
454  post_viewer:
455 
456  ReadRegStr $INSTDIR HKLM "SOFTWARE\${ProductName}" "NetCDFDir"
457  RMDir /r "$INSTDIR"
458 
459  DeleteRegKey HKCR "${ViewerExtension}"
460  DeleteRegKey HKCR "${ViewerExtensionAlias}"
461  DeleteRegKey HKLM "${UninstallerRegistryKey}"
462  DeleteRegKey HKLM "SOFTWARE\${ProductName}"
463
464
465SectionEnd
466
467# function executed on initialization of the uninstaller
468Function un.onInit
469    # prevent the uninstaller from beeing executed twice a time
470    System::Call "kernel32::CreateMutexA(i 0, i 0, t '$(^Name)') i .n ?e" # create a mutex
471    Pop $0
472    StrCmp $0 0 0 +2
473  Return # launch normaly if mutex could be created = no other instance running
474   
475    StrLen $0 "$(^Name)"
476    IntOp $0 $0 + 1 
477  loop:
478    FindWindow $1 '#32770' '' 0 $1 # search the uninstallers window if another instance is already running
479    IntCmp $1 0 +4
480    System::Call /NOUNLOAD "user32.dll::GetWindowText(i r1, t .r2, i r0) i.n"
481    StrCmp $2 "$(^Name)" 0 loop # check back for correct window text
482    System::Call "user32::SetForegroundWindow(i r1) i.n" # bring it to front if found
483  Abort # then exit
484FunctionEnd
485
486#EOF
Note: See TracBrowser for help on using the repository browser.