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 ${if} $MiKTeXUser == "HKCU"
133 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}" # special entry to tell the uninstaller that it was installed with LyX
135 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
137 StrCpy $LaTeXInstalled "MiKTeX"
138 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
140 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
141 SetOutPath $TEMP # to be able to delete the $INSTDIR
144 ${endif} # endif $PathLaTeX != ""
149 !endif # endif ${SETUPTYPE} == BUNDLE
151 # ------------------------------
153 Function ConfigureMiKTeX
154 # installs the LaTeX class files that are delivered with LyX,
155 # a Perl interpreter for splitindex
156 # and enable MiKTeX's automatic package installation
158 # install LyX's LaTeX class and style files and a Perl interpreter
159 ${if} $PathLaTeX != ""
160 ${if} $MultiUser.Privileges == "Admin"
161 ${orif} $MultiUser.Privileges == "Power"
162 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
164 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
167 # only install the LyX packages if they are not already installed
168 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
170 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
171 File "${FILES_DVIPOST_PKG}\dvipost.sty"
172 # LyX files in Resources\tex
173 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
174 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
177 # only install a Perl interpreter if it is not already installed
178 # this is only possible if miktex and LyX is installed with the same privileges
179 ${if} $MultiUser.Privileges != "Admin"
180 ${andif} $MultiUser.Privileges != "Power"
181 ${if} $PathLaTeX != "$LOCALAPPDATA\MiKTeX\$MiKTeXVersion\miktex\bin"
182 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
183 MessageBox MB_OK|MB_ICONINFORMATION "$(MultipleIndexesNotAvailable)"
186 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
187 SetOutPath "$PathLaTeXLocal"
188 File /r ${FILES_MIKTEX}
192 ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
193 SetOutPath "$PathLaTeXLocal"
194 File /r ${FILES_MIKTEX}
198 # refresh MiKTeX's file name database (do this always to assure everything is in place)
199 ${if} $MultiUser.Privileges != "Admin"
200 ${andif} $MultiUser.Privileges != "Power"
201 # call the non-admin version
202 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
204 ${if} $MiKTeXUser != "HKCU" # call the admin version
205 nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
207 nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
210 Pop $UpdateFNDBReturn # Return value
214 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
215 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
216 ${if} $MiKTeXUser != "HKCU"
217 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
219 # set package repository (MiKTeX's primary package repository)
220 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
221 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
222 ${if} $MiKTeXUser != "HKCU"
223 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
224 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
227 # enable MiKTeX's automatic package installation
228 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
229 # the following feature is planned to be used for a possible CD-version
230 # copy LaTeX-packages needed by LyX
231 # SetOutPath "$INSTDIR"
232 # File /r "${LaTeXPackagesDir}"
236 Function UpdateMiKTeX
237 # ask to update MiKTeX
239 ${if} $LaTeXInstalled == "MiKTeX"
240 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
242 StrCpy $0 $PathLaTeX -4 # remove "\bin"
243 # the update wizard is either started by the copystart_admin.exe
244 # or the miktex-update.exe (since MiKTeX 2.8)
245 ${if} $MultiUser.Privileges != "Admin"
246 ${andif} $MultiUser.Privileges != "Power"
247 # call the non-admin version
248 ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
249 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
251 ${if} $MiKTeXUser != "HKCU" # call the admin version
252 ExecWait '"$PathLaTeX\copystart_admin.exe" "$0\config\update.dat"'
253 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"' # run MiKTeX's update wizard
255 ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
256 ExecWait '"$PathLaTeX\internal\miktex-update.exe"'