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