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 == "" # check if MiKTeX is installed only for the current user
35 ReadRegStr $String HKCU "Environment" "Path"
36 StrCpy $Search "miktex"
37 Call LaTeXCheck # function from LyXUtils.nsh
38 ${if} $PathLaTeX != ""
39 StrCpy $MiKTeXUser "HKCU" # needed later to configure MiKTeX
42 ${if} $LaTeXName == "" # check for the MiKTeX version
45 EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
51 ${if} $String == "2.7"
52 StrCpy $MiKTeXVersion "2.7"
53 StrCpy $LaTeXName "MiKTeX 2.7"
55 ${if} $String == "2.8"
56 StrCpy $MiKTeXVersion "2.8"
57 StrCpy $LaTeXName "MiKTeX 2.8"
59 ${if} $String == "2.9"
60 StrCpy $MiKTeXVersion "2.9"
61 StrCpy $LaTeXName "MiKTeX 2.9"
65 ${if} $PathLaTeX != ""
66 StrCpy $LaTeXInstalled "MiKTeX"
69 # test if TeXLive is installed
70 # as described at TeXLives' homepage there should be an entry in the PATH
71 ${if} $PathLaTeX == ""
72 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
73 StrCpy $Search "TeXLive"
74 Call LaTeXCheck # function from LyXUtils.nsh
76 # check for the current user Path variable (the case when it is a live CD/DVD)
77 ${if} $PathLaTeX == ""
78 ReadRegStr $String HKCU "Environment" "Path"
79 StrCpy $Search "texlive"
81 Call LaTeXCheck # function from LyXUtils.nsh
83 # check if the variable TLroot exists (the case when it is installed using the program "tlpmgui")
84 ${if} $PathLaTeX == ""
85 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "TLroot"
87 ReadRegStr $String HKCU "Environment" "TLroot" # the case when installed without admin permissions
89 StrCpy $PathLaTeX "$String\bin\win32"
90 # check if the latex.exe exists in the $PathLaTeX folder
91 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
96 ${if} $PathLaTeX != ""
97 ${andif} $LaTeXName != "MiKTeX 2.7"
98 ${andif} $LaTeXName != "MiKTeX 2.8"
99 ${andif} $LaTeXName != "MiKTeX 2.9"
100 StrCpy $LaTeXName "TeXLive"
105 # -------------------------------------------
107 !if ${SETUPTYPE} == BUNDLE
109 Function InstallMiKTeX
111 # install MiKTeX if not already installed
112 ${if} $PathLaTeX == ""
113 # launch MiKTeX's installer
114 MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
115 ExecWait ${MiKTeXInstall}
116 # test if MiKTeX is installed
117 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
118 StrCpy $Search "miktex"
119 Call LaTeXCheck # function from LyXUtils.nsh
120 ${if} $PathLaTeX == ""
121 StrCpy $MiKTeXUser "HKCU"
122 ReadRegStr $String HKCU "Environment" "Path"
123 StrCpy $Search "miktex"
124 Call LaTeXCheck # function from LyXUtils.nsh
126 ${if} $PathLaTeX != ""
127 # set package repository (MiKTeX's primary package repository)
128 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}" # special entry to tell the uninstaller that it was installed with LyX
129 StrCpy $LaTeXInstalled "MiKTeX"
130 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
132 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
133 SetOutPath $TEMP # to be able to delete the $INSTDIR
136 ${endif} # endif $PathLaTeX != ""
141 !endif # endif ${SETUPTYPE} == BUNDLE
143 # ------------------------------
145 Function ConfigureMiKTeX
146 # installs the LaTeX class files that are delivered with LyX,
147 # a Perl interpreter for splitindex
148 # and enable MiKTeX's automatic package installation
150 # install LyX's LaTeX class and style files and a Perl interpreter
151 ${if} $PathLaTeX != ""
152 ${if} $MultiUser.Privileges != "Admin"
153 ${orif} $MultiUser.Privileges != "Power"
154 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
156 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
159 # only install the LyX packages if they are not already installed
160 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
162 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
163 File "${FILES_DVIPOST_PKG}\dvipost.sty"
164 # LyX files in Resources\tex
165 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
166 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
169 # only install a Perl interpreter if it is not already installed
170 ${ifnot} ${FileExists} "$PathLaTeXLocal\miktex\bin\perl.exe"
171 SetOutPath "$PathLaTeXLocal"
172 File /r ${FILES_MIKTEX}
175 # refresh MiKTeX's file name database (do this always to assure everything is in place)
176 ${if} $MiKTeXUser != "HKCU" # call the admin version when the user is admin
177 nsExec::ExecToLog '"$PathLaTeX\initexmf --admin --update-fndb"'
179 nsExec::ExecToLog '"$PathLaTeX\initexmf --update-fndb"'
181 Pop $UpdateFNDBReturn # Return value
185 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
186 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
187 ${if} $MiKTeXUser != "HKCU"
188 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
190 # set package repository (MiKTeX's primary package repository)
191 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
192 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
193 ${if} $MiKTeXUser != "HKCU"
194 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
195 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
198 # enable MiKTeX's automatic package installation
199 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
200 # the following feature is planned to be used for a possible CD-version
201 # copy LaTeX-packages needed by LyX
202 # SetOutPath "$INSTDIR"
203 # File /r "${LaTeXPackagesDir}"
207 Function UpdateMiKTeX
208 # ask to update MiKTeX
210 ${if} $LaTeXInstalled == "MiKTeX"
211 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
213 StrCpy $0 $PathLaTeX -4 # remove "\bin"
214 # the update wizard is either started by the copystart_admin.exe
215 # or the miktex-update.exe (since MiKTeX 2.8)
216 ExecWait '"$PathLaTeX\copystart_admin.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
217 ${if} $MiKTeXUser != "HKCU" # call the admin version when the user is admin
218 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"' # run MiKTeX's update wizard
220 ExecWait '"$PathLaTeX\internal\miktex-update.exe"' # run MiKTeX's update wizard