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