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