]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/LaTeX.nsh
installer: various fixed for immediate release
[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   WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
246   ${if} $MiKTeXUser != "HKCU"
247    WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
248   ${endif}
249   # set package repository (MiKTeX's primary package repository)
250   WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
251   WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
252   ${if} $MiKTeXUser != "HKCU"
253    WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
254    WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
255   ${endif}
256   
257   # update MiKTeX's package file list
258   ExecWait '$PathLaTeX\mpm.exe --update-fndb'
259   # the following feature is planned to be used for a possible Live version
260   # copy LaTeX-packages needed by LyX
261   # SetOutPath "$INSTDIR"
262   # File /r "${LaTeXPackagesDir}"
263   
264 FunctionEnd
265
266 # ------------------------------
267
268 Function ConfigureTeXLive
269  # installs the LaTeX class files that are delivered with LyX
270  # (TeXLive comes already with a Perl interpreter.)
271  
272  ${if} $PathLaTeX != ""
273   StrCpy $PathLaTeXLocal "$PathLaTeX" -10 # delete "\bin\win32"
274   
275   # only install the LyX packages if they are not already installed
276   ${ifnot} ${FileExists} "$PathLaTeXLocal\texmf-dist\tex\latex\lyx\broadway.cls"
277    # dvipost
278    SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\dvipost"
279    File "${FILES_DVIPOST_PKG}\dvipost.sty"
280    # files in Resources\tex
281    SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
282    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
283   ${endif}
284  ${endif}
285  
286  # update TeXLive's package file list
287  ExecWait '$PathLaTeX\texhash'
288  
289  # update TeXLive
290  ExecWait '$PathLaTeX\tlmgr update --all'
291  
292 FunctionEnd
293
294 # ------------------------------
295
296 Function UpdateMiKTeX
297  # asks to update MiKTeX
298
299   MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
300   UpdateNow:
301   # the update wizard is started by the miktex-update.exe
302   ${if} $MultiUser.Privileges != "Admin"
303   ${andif} $MultiUser.Privileges != "Power"
304    # call the non-admin version
305     ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
306   ${else}
307    ${if} $MiKTeXUser != "HKCU" # call the admin version
308     ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"'
309    ${else}
310      ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
311    ${endif}
312   ${endif}
313   UpdateLater:
314
315 FunctionEnd
316