2 # check if MiKTeX or TeXLive is installed
4 # test if MiKTeX is installed
5 # reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
6 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
7 StrCpy $Search "miktex"
8 Call LaTeXCheck # sets the path to the latex.exe to $PathLaTeX # Function from LyXUtils.nsh
10 ${if} $PathLaTeX != ""
11 # check if MiKTeX 2.7 or newer is installed
14 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
20 ${if} $String == "2.7"
21 StrCpy $MiKTeXVersion "2.7"
22 StrCpy $LaTeXName "MiKTeX 2.7"
24 ${if} $String == "2.8"
25 StrCpy $MiKTeXVersion "2.8"
26 StrCpy $LaTeXName "MiKTeX 2.8"
28 ${if} $String == "2.9"
29 StrCpy $MiKTeXVersion "2.9"
30 StrCpy $LaTeXName "MiKTeX 2.9"
34 ${if} $PathLaTeX != ""
35 StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
36 ${else} # check if MiKTeX is installed only for the current user
37 ReadRegStr $String HKCU "Environment" "Path"
38 StrCpy $Search "miktex"
39 Call LaTeXCheck # function from LyXUtils.nsh
40 ${if} $PathLaTeX != ""
41 StrCpy $MiKTeXUser "HKCU"
44 ${if} $LaTeXName == "" # check for the MiKTeX version
47 EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
53 ${if} $String == "2.7"
54 StrCpy $MiKTeXVersion "2.7"
55 StrCpy $LaTeXName "MiKTeX 2.7"
57 ${if} $String == "2.8"
58 StrCpy $MiKTeXVersion "2.8"
59 StrCpy $LaTeXName "MiKTeX 2.8"
61 ${if} $String == "2.9"
62 StrCpy $MiKTeXVersion "2.9"
63 StrCpy $LaTeXName "MiKTeX 2.9"
67 ${if} $PathLaTeX != ""
68 StrCpy $LaTeXInstalled "MiKTeX"
71 # test if TeXLive is installed
72 # as described at TeXLives' homepage there should be an entry in the PATH
73 ${if} $PathLaTeX == ""
74 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
75 StrCpy $Search "TeXLive"
76 Call LaTeXCheck # function from LyXUtils.nsh
78 # check for the current user Path variable (the case when it is a live CD/DVD)
79 ${if} $PathLaTeX == ""
80 ReadRegStr $String HKCU "Environment" "Path"
81 StrCpy $Search "texlive"
83 Call LaTeXCheck # function from LyXUtils.nsh
85 # check if the variable TLroot exists (the case when it is installed using the program "tlpmgui")
86 ${if} $PathLaTeX == ""
87 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "TLroot"
89 ReadRegStr $String HKCU "Environment" "TLroot" # the case when installed without admin permissions
91 StrCpy $PathLaTeX "$String\bin\win32"
92 # check if the latex.exe exists in the $PathLaTeX folder
93 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
98 ${if} $PathLaTeX != ""
99 ${andif} $LaTeXName != "MiKTeX 2.7"
100 ${andif} $LaTeXName != "MiKTeX 2.8"
101 ${andif} $LaTeXName != "MiKTeX 2.9"
102 StrCpy $LaTeXName "TeXLive"
107 # -------------------------------------------
109 !if ${SETUPTYPE} == BUNDLE
111 Function InstallMiKTeX
113 # install MiKTeX if not already installed
114 ${if} $PathLaTeX == ""
115 # launch MiKTeX's installer
116 MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
117 ExecWait ${MiKTeXInstall}
118 # test if MiKTeX is installed
119 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
120 StrCpy $Search "miktex"
121 Call LaTeXCheck # function from LyXUtils.nsh
122 ${if} $PathLaTeX != ""
123 StrCpy $MiKTeXUser "HKLM"
125 StrCpy $MiKTeXUser "HKCU"
126 ReadRegStr $String HKCU "Environment" "Path"
127 StrCpy $Search "miktex"
128 Call LaTeXCheck # function from LyXUtils.nsh
130 ${if} $PathLaTeX != ""
131 # set package repository (MiKTeX's primary package repository)
132 WriteRegStr $MiKTeXUser "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}" # special entry to tell the uninstaller that it was installed with LyX
133 StrCpy $LaTeXInstalled "MiKTeX"
134 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
136 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
137 SetOutPath $TEMP # to be able to delete the $INSTDIR
140 ${endif} # endif $PathLaTeX != ""
145 !endif # endif ${SETUPTYPE} == BUNDLE
147 # ------------------------------
149 Function ConfigureMiKTeX
150 # installs the LaTeX class files that are delivered with LyX,
151 # a Perl interpreter for splitindex
152 # and enable MiKTeX's automatic package installation
154 # install LyX's LaTeX class and style files and a Perl interpreter
155 ${if} $PathLaTeX != ""
156 ${if} $MultiUser.Privileges == "Admin"
157 ${orif} $MultiUser.Privileges == "Power"
158 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
160 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
163 # only install the LyX packages if they are not already installed
164 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
166 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
167 File "${FILES_DVIPOST_PKG}\dvipost.sty"
168 # LyX files in Resources\tex
169 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
170 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
173 # only install a Perl interpreter if it is not already installed
174 # this is only possible if miktex and LyX is installed with the same privileges
175 ${if} $MultiUser.Privileges != "Admin"
176 ${andif} $MultiUser.Privileges != "Power"
177 ${if} $PathLaTeX != "$LOCALAPPDATA\MiKTeX\$MiKTeXVersion\miktex\bin"
178 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
179 # FIXME: output a translatable message in this case
180 MessageBox MB_OK "LyX's multiple index feature will not work because MiKTeX was installed with admin privileges but you don't have them."
183 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
184 SetOutPath "$PathLaTeXLocal"
185 File /r ${FILES_MIKTEX}
189 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
190 SetOutPath "$PathLaTeXLocal"
191 File /r ${FILES_MIKTEX}
195 # refresh MiKTeX's file name database (do this always to assure everything is in place)
196 ${if} $MultiUser.Privileges != "Admin"
197 ${andif} $MultiUser.Privileges != "Power"
198 # call the non-admin version
199 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
201 ${if} $MiKTeXUser != "HKCU" # call the admin version
202 nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
204 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
207 Pop $UpdateFNDBReturn # Return value
211 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
212 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
213 ${if} $MiKTeXUser != "HKCU"
214 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
216 # set package repository (MiKTeX's primary package repository)
217 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
218 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
219 ${if} $MiKTeXUser != "HKCU"
220 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
221 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
224 # enable MiKTeX's automatic package installation
225 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
226 # the following feature is planned to be used for a possible CD-version
227 # copy LaTeX-packages needed by LyX
228 # SetOutPath "$INSTDIR"
229 # File /r "${LaTeXPackagesDir}"
233 Function UpdateMiKTeX
234 # ask to update MiKTeX
236 ${if} $LaTeXInstalled == "MiKTeX"
237 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
239 StrCpy $0 $PathLaTeX -4 # remove "\bin"
240 # the update wizard is either started by the copystart_admin.exe
241 # or the miktex-update.exe (since MiKTeX 2.8)
242 ${if} $MultiUser.Privileges != "Admin"
243 ${andif} $MultiUser.Privileges != "Power"
244 # call the non-admin version
245 ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
246 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
248 ${if} $MiKTeXUser != "HKCU" # call the admin version
249 ExecWait '"$PathLaTeX\copystart_admin.exe" "$0\config\update.dat"'
250 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"' # run MiKTeX's update wizard
252 ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
253 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'