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