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