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