]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/LaTeX.nsh
installer: really fix splitindex support this time
[features.git] / development / Win32 / packaging / installer / include / LaTeX.nsh
1 /*
2 LaTeX.nsh
3
4 Handling of LaTeX distributions
5 */
6
7 # This script contains the following functions:
8 #
9 # - LaTeXActions (checks if MiKTeX or TeXLive is installed)
10 #
11 # - InstallMiKTeX (installs MiKTeX if not already installed),
12 #   only for bunlde installer, uses:
13 #    LaTeXCheck # function from LyXUtils.nsh
14 #
15 # - ConfigureMiKTeX
16 #   (installs the LaTeX class files that are delivered with LyX,
17 #    a Perl interpreter for splitindex
18 #    and enable MiKTeX's automatic package installation)
19 #
20 # - ConfigureTeXLive
21 #   (installs the LaTeX class files that are delivered with LyX)
22 #
23 # - UpdateMiKTeX (asks to update MiKTeX)
24
25 # ---------------------------------------
26
27 Function LaTeXActions
28  # checks if MiKTeX or TeXLive is installed
29
30   StrCpy $Is64bit "false"
31   
32   ${if} ${RunningX64}
33    SetRegView 64 # the PATH is in the 64bit registry section
34   ${endif}
35   # test if MiKTeX is installed
36   # reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
37   ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
38   StrCpy $Search "miktex"
39   Call LaTeXCheck # sets the path to the latex.exe to $PathLaTeX # Function from LyXUtils.nsh
40   
41   StrCpy $String $PathLaTeX
42   StrCpy $Search "x64" # search if it is 64bit MiKTeX
43   Call StrPoint # Function from LyXUtils.nsh
44   ${if} $Pointer != "-1" # if something was found
45    StrCpy $Is64bit "true"
46   ${endif}
47   
48   # check for 32bit MiKTeX
49   ${if} $PathLaTeX != ""
50   ${andif} $Is64bit != "true"
51    ${if} ${RunningX64}
52     SetRegView 32
53    ${endif}
54    # check if MiKTeX 2.8 or newer is installed
55    StrCpy $0 0
56    loop32:
57     EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
58     StrCmp $1 "" done32
59     StrCpy $String $1
60     IntOp $0 $0 + 1
61     Goto loop32
62    done32:
63    ${if} $String == "2.8"
64     StrCpy $MiKTeXVersion "2.8"
65     StrCpy $LaTeXName "MiKTeX 2.8"
66    ${endif}
67    ${if} $String == "2.9"
68     StrCpy $MiKTeXVersion "2.9"
69     StrCpy $LaTeXName "MiKTeX 2.9"
70    ${endif}
71   ${endif}
72   
73   # check for 64bit MiKTeX
74   ${if} $LaTeXName == ""
75    ${if} ${RunningX64}
76     SetRegView 64
77    ${endif}
78    # check if MiKTeX 2.8 or newer is installed
79    StrCpy $0 0
80    loop64:
81     EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
82     StrCmp $1 "" done64
83     StrCpy $String $1
84     IntOp $0 $0 + 1
85     Goto loop64
86    done64:
87    ${if} $String == "2.8"
88     StrCpy $MiKTeXVersion "2.8"
89     StrCpy $LaTeXName "MiKTeX 2.8"
90    ${endif}
91    ${if} $String == "2.9"
92     StrCpy $MiKTeXVersion "2.9"
93     StrCpy $LaTeXName "MiKTeX 2.9"
94    ${endif}
95   ${endif}
96   
97   ${if} $PathLaTeX != ""
98    StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
99   ${else} # check if MiKTeX is installed only for the current user
100    ${if} ${RunningX64}
101     SetRegView 64 # the PATH is in the 64bit registry section
102    ${endif}
103    ReadRegStr $String HKCU "Environment" "Path"
104    StrCpy $Search "miktex"
105    Call LaTeXCheck # function from LyXUtils.nsh
106    ${if} $PathLaTeX != ""
107     StrCpy $MiKTeXUser "HKCU"
108    ${endif}
109   ${endif}
110   ${if} $LaTeXName == "" # check for the MiKTeX version
111    StrCpy $0 0
112    loopB:
113     EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
114     StrCmp $1 "" doneB
115     StrCpy $String $1
116     IntOp $0 $0 + 1
117     Goto loopB
118    doneB:
119    ${if} $String == "2.8"
120     StrCpy $MiKTeXVersion "2.8"
121     StrCpy $LaTeXName "MiKTeX 2.8"
122    ${endif}
123    ${if} $String == "2.9"
124     StrCpy $MiKTeXVersion "2.9"
125     StrCpy $LaTeXName "MiKTeX 2.9"
126    ${endif}
127   ${endif}
128   
129   ${if} $PathLaTeX != ""
130    StrCpy $String $PathLaTeX
131    StrCpy $Search "x64" # search if it is 64bit MiKTeX
132    Call StrPoint # Function from LyXUtils.nsh
133    ${if} $Pointer != "-1" # if something was found
134     StrCpy $Is64bit "true"
135    ${endif}
136    StrCpy $LaTeXInstalled "MiKTeX"
137    # on some installations the path ends with a "\" on some not
138    # therefore assure that we remove it if it exists
139    StrCpy $0 $PathLaTeX "" -1
140    ${if} $0 == "\"
141     StrCpy $PathLaTeX "$PathLaTeX" -1 # delete "\"
142    ${endif}
143   ${endif}
144   
145   # test if TeXLive is installed
146   # TeXLive can be installed so that it appears in the PATH variable and/or only as current user.
147   # The safest method is to first check for the PATH because this is independent of the TeXLive version.
148   ${if} ${RunningX64}
149    SetRegView 64 # the PATH is in the 64bit registry section
150   ${endif}
151   ${if} $PathLaTeX == ""
152    ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
153    StrCpy $Search "TeXLive"
154    Call LaTeXCheck # function from LyXUtils.nsh
155   ${endif}
156   # check for the current user Path variable
157   ${if} $PathLaTeX == ""
158    ReadRegStr $String HKCU "Environment" "Path"
159    StrCpy $Search "texlive"
160    StrCpy $2 "TeXLive"
161    Call LaTeXCheck # function from LyXUtils.nsh
162   ${endif}
163   # check if it was installed to the system
164   ${if} ${RunningX64}
165    SetRegView 32 # TeXLive is a 32bit application
166   ${endif}
167   ${if} $PathLaTeX == ""
168    ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
169    ${if} $String == ""
170     ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "UninstallString"
171    ${endif}
172    ${if} $String != ""
173     StrCpy $String $String -28 # remove '\tlpkg\installer\uninst.bat"'
174     StrCpy $String $String "" 1 # remove the leading quote
175    ${endif}
176    StrCpy $PathLaTeX "$String\bin\win32"
177    # check if the latex.exe exists in the $PathLaTeX folder
178    !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
179    ${if} $5 == "False"
180     StrCpy $PathLaTeX ""
181    ${endif}
182   ${endif}
183   # finally set the name
184   ${if} $PathLaTeX != ""
185   ${andif} $LaTeXName != "MiKTeX 2.8"
186   ${andif} $LaTeXName != "MiKTeX 2.9"
187    StrCpy $LaTeXInstalled "TeXLive"
188    ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
189    ${if} $String == ""
190     ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2012" "DisplayVersion"
191    ${endif}
192    ${if} $String != ""
193     StrCpy $LaTeXName "TeXLive $String"
194    ${else}
195     StrCpy $LaTeXName "TeXLive"
196    ${endif}
197   ${endif}
198
199 FunctionEnd
200
201 # -------------------------------------------
202
203 !if ${SETUPTYPE} == BUNDLE
204
205  Function InstallMiKTeX
206   # installs MiKTeX if not already installed
207   
208   ${if} $PathLaTeX == ""
209    # launch MiKTeX's installer
210    MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
211    ExecWait ${MiKTeXInstall}
212    # test if MiKTeX is installed
213    Call LaTeXActions
214    ${if} ${RunningX64}
215     SetRegView 32 # we install the 32bit version of MiKTeX
216    ${endif}
217    ${if} $PathLaTeX != ""
218     # special entry that it was installed together with LyX
219     # so that we can later uninstall it together with LyX
220     ${if} $MiKTeXUser == "HKCU"
221      WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
222     ${else}
223      WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
224     ${endif}
225     StrCpy $LaTeXInstalled "MiKTeX"
226     StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
227    ${else}
228     MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
229     SetOutPath $TEMP # to be able to delete the $INSTDIR
230     RMDir /r $INSTDIR
231     Abort
232    ${endif} # endif $PathLaTeX != ""
233   ${endif}
234
235   FunctionEnd
236
237 !endif # endif ${SETUPTYPE} == BUNDLE
238
239 # ------------------------------
240
241 Function ConfigureMiKTeX
242  # installs the LaTeX class files that are delivered with LyX,
243  # a Perl interpreter for splitindex
244  # and enable MiKTeX's automatic package installation
245  
246  # install LyX's LaTeX class and style files and a Perl interpreter
247  ${if} $PathLaTeX != ""
248   ${if} $MultiUser.Privileges == "Admin"
249   ${orif} $MultiUser.Privileges == "Power"
250    ${if} $Is64bit == "true"
251     StrCpy $PathLaTeXLocal "$PathLaTeX" -15 # delete "\miktex\bin\x64"
252    ${else}
253     StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
254    ${endif}
255   ${else}
256    StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
257   ${endif}
258
259   # only install the LyX packages if they are not already installed
260   ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
261    # dvipost
262    SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
263    File "${FILES_DVIPOST_PKG}\dvipost.sty"
264    # files in Resources\tex
265    SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
266    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
267   ${endif}
268   # Belarusian support
269   ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\generic\babel\belarusian.ldf"
270    SetOutPath "$PathLaTeXLocal\tex\generic\babel"
271    File "${FILES_DVIPOST_PKG}\belarusian.ldf"
272    File "${FILES_DVIPOST_PKG}\belarusian.sty"
273   ${endif}
274   # Hungarian support
275   # this is a replacement therefore do this in every case
276   SetOutPath "$PathLaTeXLocal\tex\generic\babel"
277   File "${FILES_DVIPOST_PKG}\magyar.ldf"
278   
279   # only install a Perl interpreter if it is not already installed
280   # this is only possible if MikTeX _and_ LyX is installed with the same privileges
281   ${if} ${RunningX64}
282    SetRegView 32 # FIXME: recheck this if the 64bit version of MiKTeX is out of beta state 
283   ${endif}
284   ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\MiKTeX $MiKTeXVersion" "DisplayVersion"
285   ${if} $MultiUser.Privileges != "Admin"
286   ${andif} $MultiUser.Privileges != "Power"
287    ${if} $0 == ""
288     ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
289      MessageBox MB_OK|MB_ICONINFORMATION "$(MultipleIndexesNotAvailable)"
290     ${endif}
291    ${else}
292     # ${FileExists} is disabled for now to repair existing LyX installations using 64bit MiKTeX
293     # re-enable this for LyX 2.1.1
294     #${ifnot} ${FileExists} "$PathLaTeX\perl.exe" 
295      ${if} $Is64bit == "true"
296       StrCpy $3 "$PathLaTeX" -15 # delete "\miktex\bin\x64"
297      ${else}
298       StrCpy $3 "$PathLaTeX" -11 # delete "\miktex\bin"
299      ${endif}
300      SetOutPath "$3"
301      File /r ${FILES_MIKTEX}
302      # move the files to the correct location for 64bit
303      # on 32bit MiKTeX the lib folder has to be parallel to the bin folder
304      # while on 64bit MiKTeX the lib folder has to be inside the bin folder
305      ${if} $Is64bit == "true"
306       CopyFiles /SILENT /FILESONLY "$3\miktex\bin\*.*" "$PathLaTeX"
307       CreateDirectory "$3\miktex\bin\x64\lib"
308       CopyFiles /SILENT "$3\miktex\lib\*.*" "$3\miktex\bin\x64\lib"
309       RMDir /r "$3\miktex\lib"
310       RMDir /r "$3\miktex\bin\lib" # to clean up existing installations; can be removed for LyX 2.1.1
311       Delete "$3\miktex\bin\*.*"
312      ${endif}
313     #${endif}
314    ${endif}
315   ${else} # if admin or power user
316    # ${FileExists} is disabled for now to repair existing LyX installations using 64bit MiKTeX
317    # re-enable this for LyX 2.1.1
318    #${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
319     SetOutPath "$PathLaTeXLocal"
320     File /r ${FILES_MIKTEX}
321     # move the files to the correct location for 64bit
322     ${if} $Is64bit == "true"
323      CopyFiles /SILENT /FILESONLY "$PathLaTeXLocal\miktex\bin\*.*" "$PathLaTeX"
324      CreateDirectory "$PathLaTeXLocal\miktex\bin\x64\lib"
325      CopyFiles /SILENT "$PathLaTeXLocal\miktex\lib\*.*" "$PathLaTeXLocal\miktex\bin\x64\lib"
326      RMDir /r "$PathLaTeXLocal\miktex\lib"
327      RMDir /r "$PathLaTeXLocal\miktex\bin\lib" # to clean up existing installations; can be removed for LyX 2.1.1
328      Delete "$PathLaTeXLocal\miktex\bin\*.*"
329     ${endif}
330    #${endif}
331   ${endif}
332   
333   # refresh MiKTeX's file name database (do this always to assure everything is in place)
334   ${if} $MultiUser.Privileges != "Admin"
335   ${andif} $MultiUser.Privileges != "Power"
336    # call the non-admin version
337    nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
338   ${else}
339    ${if} $MiKTeXUser != "HKCU" # call the admin version
340     nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
341    ${else}
342     nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
343    ${endif}
344   ${endif}
345   Pop $UpdateFNDBReturn # Return value
346   
347  ${endif} # end if $PathLaTeX != ""
348   
349   # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first) and
350   # if there is not package repository (MiKTeX's primary package repository) then set it
351   ${if} ${RunningX64}
352   ${andif} $Is64bit == "true"
353    SetRegView 64
354   ${else}
355    SetRegView 32
356   ${endif}
357   ${if} $MiKTeXUser == "HKCU" # if only for current user
358    WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
359    ReadRegStr $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository"
360    ${if} $1 == ""
361     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" 
362     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
363    ${endif}
364   ${else}
365    WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
366    ReadRegStr $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository"
367    ${if} $1 == ""
368     WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
369     WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
370    ${endif}
371    # we need to state that missing packages should be installed for all users too
372    WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoAdmin" "t"
373   ${endif}
374   
375   # update MiKTeX's package file list
376   ExecWait '$PathLaTeX\mpm.exe --update-fndb'
377   
378   # we must return to 32bit because LyX is a 32bit application
379   SetRegView 32
380   
381 FunctionEnd
382
383 # ------------------------------
384
385 Function ConfigureTeXLive
386  # installs the LaTeX class files that are delivered with LyX
387  # (TeXLive comes already with a Perl interpreter.)
388  
389  ${if} $PathLaTeX != ""
390   StrCpy $PathLaTeXLocal "$PathLaTeX" -10 # delete "\bin\win32"
391   
392   # only install the LyX packages if they are not already installed
393   ${ifnot} ${FileExists} "$PathLaTeXLocal\texmf-dist\tex\latex\lyx\broadway.cls"
394    # dvipost
395    SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\dvipost"
396    File "${FILES_DVIPOST_PKG}\dvipost.sty"
397    # files in Resources\tex
398    SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
399    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
400   ${endif}
401  ${endif}
402  
403  # update TeXLive's package file list
404  ExecWait '$PathLaTeX\texhash'
405  
406  # update TeXLive
407  ExecWait '$PathLaTeX\tlmgr update --all'
408  
409 FunctionEnd
410
411 # ------------------------------
412
413 Function UpdateMiKTeX
414  # asks to update MiKTeX
415
416   MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
417   UpdateNow:
418   # the update wizard is started by the miktex-update.exe
419   ${if} $MultiUser.Privileges != "Admin"
420   ${andif} $MultiUser.Privileges != "Power"
421    # call the non-admin version
422     ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
423   ${else}
424    ${if} $MiKTeXUser != "HKCU" # call the admin version
425     ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"'
426    ${else}
427      ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
428    ${endif}
429   ${endif}
430   UpdateLater:
431
432 FunctionEnd
433