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