]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/installer/setup/install.nsh
f228ab589eb78576668304931f039279af47128f
[lyx.git] / development / Win32 / packaging / installer / setup / install.nsh
1 /*
2
3 install.nsh
4
5 Installation of program files, dictionaries and external components
6
7 */
8
9 #--------------------------------
10 # Program files
11
12 Var PythonCompileFile
13 Var PythonCompileReturn
14
15 Section -ProgramFiles SecProgramFiles
16
17   # Install and register the core LyX files
18   
19   # The macros are defined in filelists.nsh
20   # the parameters are COMMAND DIRECTORY that form command '${COMMAND} "${DIRECTORY}files"  
21   
22   # Initializes the plug-ins dir ($PLUGINSDIR) if not already initialized.
23   # $PLUGINSDIR is automatically deleted when the installer exits.
24   InitPluginsDir
25   
26   # Binaries
27   SetOutPath "$INSTDIR\bin"
28   !insertmacro FileListLyXBin File "${FILES_LYX}\bin\"
29   !insertmacro FileListLyXLauncher File "${FILES_LAUNCHER}\"  
30   !insertmacro FileListQtBin File "${FILES_QT}\bin\"
31   !insertmacro FileListDll File "${FILES_DEPS}\bin\"
32   !insertmacro FileListMSVCBin File "${FILES_MSVC}\"
33   !insertmacro FileListMSVCManifest File "..\"
34   !insertmacro FileListNetpbmBin File "${FILES_NETPBM}\"
35   !insertmacro FileListDTLBin File "${FILES_DTL}\"
36   !insertmacro FileListDvipostBin File "${FILES_DVIPOST}\"
37   !insertmacro FileListPDFViewBin File "${FILES_PDFVIEW}\"
38   !insertmacro FileListPDFToolsBin File "${FILES_PDFTOOLS}\"
39   !insertmacro FileListNSISPluginsStandard File "${NSISDIR}\Plugins\"
40   !insertmacro FileListNSISPlugins File "${FILES_NSISPLUGINS}\"
41   !insertmacro FileListMetaFile2EPS File "${FILES_METAFILE2EPS}\"
42   
43   # Resources
44   SetOutPath "$INSTDIR"
45   # recursively copy all files under Resources
46   File /r "${FILES_LYX}\Resources"
47   
48   # Components of Python
49   SetOutPath "$INSTDIR\python"
50   !insertmacro FileListPythonBin File "${FILES_PYTHON}\"
51   !insertmacro FileListMSVCBin File "${FILES_MSVC}\"
52   !insertmacro FileListMSVCManifest File "..\"  
53   SetOutPath "$INSTDIR\python\Lib"
54   !insertmacro FileListPythonLib File "${FILES_PYTHON}\Lib\"
55   SetOutPath "$INSTDIR\python\Lib\encodings"
56   !insertmacro FileListPythonLibEncodings File "${FILES_PYTHON}\Lib\encodings\"
57   
58   # Compile all Pyton files to byte-code
59   # The user using the scripts may not have write access
60   FileOpen $PythonCompileFile "$INSTDIR\compilepy.py" w
61   FileWrite $PythonCompileFile "import compileall$\r$\n"
62   FileWrite $PythonCompileFile "compileall.compile_dir('$INSTDIR\python\Lib')$\r$\n"
63   FileWrite $PythonCompileFile "compileall.compile_dir('$INSTDIR\Resources')$\r$\n"
64   FileClose $PythonCompileFile
65   DetailPrint $(TEXT_CONFIGURE_PYTHON)
66   nsExec::ExecToLog '"$INSTDIR\python\python.exe" "$INSTDIR\compilepy.py"'
67   Pop $PythonCompileReturn # Return value
68   Delete "$INSTDIR\compilepy.py"
69   
70   !ifdef BUNDLE_IMAGEMAGICK
71   # Components of ImageMagick
72   SetOutPath "$INSTDIR\imagemagick"
73   !insertmacro FileListImageMagick File "${FILES_IMAGEMAGICK}\"
74   !insertmacro FileListMSVCBin File "${FILES_MSVC}\"
75   !insertmacro FileListMSVCManifest File "..\"
76   !endif  
77   
78   !ifdef BUNDLE_GHOSTSCRIPT
79   # Components of Ghostscript
80   SetOutPath "$INSTDIR\ghostscript"
81   !insertmacro FileListGhostscript File "${FILES_GHOSTSCRIPT}\"
82   !insertmacro FileListMSVCBin File "${FILES_MSVC}\"
83   !insertmacro FileListMSVCManifest File "..\"
84   
85   !endif  
86   
87   # Aspell
88
89   # Copy installer to pluginsdir (a temp dir)
90   File /oname=$PLUGINSDIR\AspellData.exe "${FILES_ASPELLDATA}\AspellData.exe"
91
92   # Silently install AspellData.exe (/S option)
93   ${If} $MultiUser.InstallMode == "CurrentUser"
94     ExecWait '"$PLUGINSDIR\AspellData.exe" /S /CurrentUser'
95   ${Else}
96     ExecWait '"$PLUGINSDIR\AspellData.exe" /S /AllUsers'
97   ${EndIf}
98
99   # Remove the installer
100   Delete "$PLUGINSDIR\AspellData.exe"
101
102   # Aiksarus data
103   SetOutPath "$INSTDIR\aiksaurus"
104   !insertmacro FileListAiksaurusData File "${FILES_AIKSAURUS}\"
105   
106   # Create uninstaller
107   WriteUninstaller "$INSTDIR\${SETUP_UNINSTALLER}"
108
109 SectionEnd
110
111 #--------------------------------
112 # Support code for file downloads
113
114 !macro DOWNLOAD_FILE RET ID FILENAME APPEND
115
116   # Downloads a file using the Inetc plug-in (HTTP or FTP)
117   
118   # RET = Return value (OK if succesful)
119   # ID = Name of the download in settings.nsh
120   # FILENAME = Location to store file
121   # APPEND = Filename to append to server location in settings.nsh
122
123   # Try first time
124   Inetc::get "${DOWNLOAD_${ID}}${APPEND}" "$PLUGINSDIR\${FILENAME}" /END
125   Pop ${RET} # Return value (OK if succesful)
126
127   ${If} ${RET} != "OK"
128     # Download failed, try again (usally we get a different mirror)
129     Inetc::get "${DOWNLOAD_${ID}}${APPEND}" "$PLUGINSDIR\${FILENAME}" /END
130     Pop ${RET}
131   ${EndIf}
132
133 !macroend
134
135 #--------------------------------
136 # Aspell dictionaries
137
138 Var DictionaryFile
139 Var DictionaryLangName
140 Var DictionaryLangCode
141 Var DictionaryPath
142
143 Var AspellHive
144 Var AspellPath
145
146 Var DownloadResult
147
148 Section -AspellDicts
149
150   # Check whether the system or local version of Aspell should be used
151   # The patched Aspell uses the same logic
152
153   ReadRegStr $AspellPath HKCU "Software\Aspell" "Base Path"
154
155   ${If} $AspellPath == ""
156     StrCpy $AspellHive HKLM
157   ${Else}
158     StrCpy $AspellHive HKCU
159   ${EndIf}
160
161 SectionEnd
162
163 !macro SECTION_DICT FILE LANGNAME LANGCODE SIZE
164
165   # One section for each dictionary
166
167   Section /o "${LANGNAME}"
168
169     AddSize ${SIZE}
170
171     StrCpy $DictionaryFile "${FILE}"
172     StrCpy $DictionaryLangName "${LANGNAME}"
173     StrCpy $DictionaryLangCode ${LANGCODE}
174
175     Call DownloadDictionary
176
177   SectionEnd
178
179 !macroend
180
181 # Include all sections
182 !insertmacro Dictionaries '!insertmacro SECTION_DICT'
183
184 Function DownloadDictionary
185
186   # Download and install a dictionary
187
188   dict_download:
189   
190     !insertmacro DOWNLOAD_FILE $DownloadResult ASPELLDICTS aspell6-$DictionaryFile.exe /aspell6-$DictionaryFile.exe
191
192     ${If} $DownloadResult != "OK"
193       # Download failed
194       MessageBox MB_YESNO|MB_ICONEXCLAMATION "$(TEXT_DOWNLOAD_FAILED_DICT) ($DownloadResult)" IDYES dict_download
195       Goto dict_noinstall
196     ${EndIf}
197
198     install_dict:
199
200       ExecWait '"$PLUGINSDIR\aspell6-$DictionaryFile.exe" /NoDirChange /AutoClose'
201
202       ${If} $AspellHive == HKLM
203         ReadRegStr $DictionaryPath HKLM "Software\Aspell\Dictionaries" $DictionaryLangCode
204       ${Else}
205         ReadRegStr $DictionaryPath HKCU "Software\Aspell\Dictionaries" $DictionaryLangCode
206       ${EndIf}
207
208       ${If} $DictionaryPath == ""
209         MessageBox MB_YESNO|MB_ICONEXCLAMATION "$(TEXT_NOTINSTALLED_DICT)" IDYES install_dict
210       ${EndIf}
211
212       Delete "$PLUGINSDIR\aspell6-$DictionaryFile.exe"
213
214     dict_noinstall:
215
216 FunctionEnd
217
218 #--------------------------------
219 # Extenral components
220
221 Var PathAllUsers
222 Var PathCurrentUser
223
224 !macro EXTERNAL COMPONENT
225
226   # Download/Install the component
227   
228   ${If} $Setup${COMPONENT} == ${TRUE}
229   
230     StrCpy $Path${COMPONENT} "" ;A new one will be installed
231   
232     !ifndef BUNDLESETUP_${COMPONENT}
233       !insertmacro EXTERNAL_DOWNLOAD ${COMPONENT}
234     !else
235       !insertmacro EXTERNAL_INSTALL ${COMPONENT}
236     !endif
237     
238   ${EndIf}
239
240 !macroend
241
242 !macro EXTERNAL_RUNINSTALLER COMPONENT
243
244   # Run the installer application of the component that does the actual installation.
245
246   install_${COMPONENT}:
247       
248     ExecWait '"$PLUGINSDIR\${COMPONENT}Setup.exe"'
249     
250     # Updates the path environment variable of the instaler process to the latest system value
251     ReadRegStr $PathAllUsers HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path
252     ReadRegStr $PathCurrentUser HKCU "Environment" Path
253     System::Call 'kernel32::SetEnvironmentVariableA(t, t) i("Path", "$PathAllUsers;$PathCurrentUser").'
254
255     Call Search${COMPONENT}
256     
257     ${If} $Path${COMPONENT} == ""  
258       MessageBox MB_YESNO|MB_ICONEXCLAMATION $(TEXT_NOTINSTALLED_${COMPONENT}) IDYES install_${COMPONENT}
259     ${EndIf}
260       
261     Delete "$PLUGINSDIR\${COMPONENT}Setup.exe"
262      
263 !macroend
264
265 !macro EXTERNAL_DOWNLOAD COMPONENT
266
267   download_${COMPONENT}:
268
269     !insertmacro DOWNLOAD_FILE $DownloadResult "${COMPONENT}" "${COMPONENT}Setup.exe" ""
270  
271     ${If} $DownloadResult != "OK"
272       # Download failed
273       MessageBox MB_YESNO|MB_ICONEXCLAMATION "$(TEXT_DOWNLOAD_FAILED_${COMPONENT}) ($DownloadResult)" IDYES download_${COMPONENT}
274       Goto noinstall_${COMPONENT}
275     ${EndIf}
276       
277     !insertmacro EXTERNAL_RUNINSTALLER ${COMPONENT}
278       
279   noinstall_${COMPONENT}:
280
281 !macroend
282
283 !macro EXTERNAL_INSTALL COMPONENT
284
285   # Extract
286   File /oname=$PLUGINSDIR\${COMPONENT}Setup.exe ${FILES_BUNDLE}\${INSTALL_${COMPONENT}}
287     
288   !insertmacro EXTERNAL_RUNINSTALLER ${COMPONENT}
289     
290 !macroend
291
292
293 # Sections for external components
294
295 Section -LaTeX ExternalLaTeX
296   !insertmacro EXTERNAL LaTeX
297 SectionEnd
298
299 !ifndef BUNDLE_IMAGEMAGICK
300
301 Section -ImageMagick ExternalImageMagick
302   !insertmacro EXTERNAL ImageMagick
303 SectionEnd
304
305 !endif
306
307 !ifndef BUNDLE_GHOSTSCRIPT
308
309 Section -Ghostscript ExternalGhostscript
310   !insertmacro EXTERNAL Ghostscript
311 SectionEnd
312
313 !endif
314
315 Function InitExternal
316
317   # Get sizes of external component installers
318   
319   SectionGetSize ${ExternalLaTeX} $SizeLaTeX
320   !ifndef BUNDLE_IMAGEMAGICK
321     SectionGetSize ${ExternalImageMagick} $SizeImageMagick
322   !endif
323   !ifndef BUNDLE_GHOSTSCRIPT
324     SectionGetSize ${ExternalGhostscript} $SizeGhostscript
325   !endif
326   
327   # Add download size
328   
329   !ifndef BUNDLESETUP_MIKTEX
330     IntOp $SizeLaTeX $SizeLaTeX + ${SIZE_DOWNLOAD_LATEX}
331   !endif
332   !ifndef BUNDLE_IMAGEMAGICK & BUNDLESETUP_IMAGEMAGICK
333     IntOp $SizeImagemagick $SizeImagemagick + ${SIZE_DOWNLOAD_IMAGEMAGICK}
334   !endif
335   !ifndef BUNDLE_GHOSTSCRIPT & BUNDLESETUP_GHOSTSCRIPT
336     IntOp $SizeGhostscript $SizeGhostscript + ${SIZE_DOWNLOAD_GHOSTSCRIPT}
337   !endif
338
339 FunctionEnd