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 $LatexPath # Function from LyXUtils.nsh
10 ${if} $LatexPath != ""
11 # check if MiKTeX 2.6 or newer is installed
14 EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
20 ${if} $String == "2.6"
21 StrCpy $MiKTeXVersion "2.6"
22 StrCpy $LaTeXName "MiKTeX 2.6"
24 ${if} $String == "2.7"
25 StrCpy $MiKTeXVersion "2.7"
26 StrCpy $LaTeXName "MiKTeX 2.7"
28 ${if} $String == "2.8"
29 StrCpy $MiKTeXVersion "2.8"
30 StrCpy $LaTeXName "MiKTeX 2.8"
34 ${if} $LatexPath == "" # 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} $LatexPath != ""
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.6"
52 StrCpy $MiKTeXVersion "2.6"
53 StrCpy $LaTeXName "MiKTeX 2.6"
55 ${if} $String == "2.7"
56 StrCpy $MiKTeXVersion "2.7"
57 StrCpy $LaTeXName "MiKTeX 2.7"
59 ${if} $String == "2.8"
60 StrCpy $MiKTeXVersion "2.8"
61 StrCpy $LaTeXName "MiKTeX 2.8"
65 ${if} $LatexPath != ""
66 StrCpy $MiKTeXInstalled "yes"
69 # test if TeXLive is installed
70 # as described at TeXLives' homepage there should be an entry in the PATH
71 ${if} $LatexPath == ""
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} $LatexPath == ""
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} $LatexPath == ""
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 $LatexPath "$String\bin\win32"
90 # check if the latex.exe exists in the $LatexPath folder
91 !insertmacro FileCheck $5 "latex.exe" "$LatexPath" # macro from LyXUtils.nsh
96 ${if} $LatexPath != ""
97 ${andif} $LaTeXName != "MiKTeX 2.6"
98 ${andif} $LaTeXName != "MiKTeX 2.7"
99 ${andif} $LaTeXName != "MiKTeX 2.8"
100 StrCpy $LaTeXName "TeXLive"
103 ${if} $LatexPath == ""
104 StrCpy $MissedProg "True"
109 # -------------------------------------------
111 !if ${INSTALLER_VERSION} == "Complete"
113 Function InstallMiKTeX
114 # install MiKTeX if not already installed
116 ${if} $LatexPath == ""
117 # launch MiKTeX's installer
118 MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
119 ExecWait ${MiKTeXInstall}
120 # test if MiKTeX is installed
121 ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
122 StrCpy $Search "miktex"
124 ${if} $LatexPath == ""
125 StrCpy $MiKTeXUser "HKCU"
126 ReadRegStr $String HKCU "Environment" "Path"
127 StrCpy $Search "miktex"
130 ${if} $LatexPath != ""
131 # set package repository (MiKTeX's primary package repository)
132 WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}" # special entry to tell the uninstaller that it was installed with LyX
133 StrCpy $MiKTeXInstalled "yes"
134 StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
135 ${if} $MiKTeXUser != "HKCU"
136 StrCpy $MiKTeXPath "$LatexPath" -11 # delete "\miktex\bin"
137 #MessageBox MB_OK|MB_ICONINFORMATION "$(MiKTeXPathInfo)" # info that MiKTeX's installation folder must have write permissions for all users to work properly
140 MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
141 SetOutPath $TEMP # to be able to delete the $INSTDIR
144 ${endif} # endif $LatexPath != ""
149 !endif # endif ${INSTALLER_VERSION} == "Complete"
151 # ------------------------------
153 Function ConfigureMiKTeX
154 # installs the LaTeX class files that are delivered with LyX
155 # and enable MiKTeX's automatic package installation
157 StrCpy $String $LatexPath
158 StrCpy $Search "miktex\bin"
160 Call StrPoint # search the LaTeXPath for the phrase "miktex\bin" (function from LyXUtils.nsh)
161 ${if} $Pointer != "-1" # if something was found
162 IntOp $Pointer $Pointer - 1 # jump before the first "\" of "\miktex\bin"
163 StrCpy $String $String "$Pointer" # $String is now the part before "\miktex\bin"
164 # install LyX's special LaTeX class files
165 CreateDirectory "$String\tex\latex\lyx"
166 SetOutPath "$String\tex\latex\lyx"
167 File "${ClassFileDir}\lyxchess.sty"
168 File "${ClassFileDir}\lyxskak.sty"
169 CreateDirectory "$String\tex\latex\revtex"
170 SetOutPath "$String\tex\latex\revtex"
171 File "${ClassFileDir}\revtex.cls"
172 CreateDirectory "$String\tex\latex\hollywood"
173 SetOutPath "$String\tex\latex\hollywood"
174 File "${ClassFileDir}\hollywood.cls"
175 CreateDirectory "$String\tex\latex\broadway"
176 SetOutPath "$String\tex\latex\broadway"
177 File "${ClassFileDir}\broadway.cls"
178 # install LaTeX-package dvipost (dvipost is not available for MiKTeX)
179 SetOutPath "$String\tex\latex"
180 File /r "${DVIPostFileDir}"
182 # refresh MiKTeX's file name database
183 ExecWait "$LaTeXPath\initexmf --update-fndb"
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 '$LaTeXPath\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}"
204 ${endif} # end ${if} $Pointer
206 # save MiKTeX's install path to be able to remove LyX's LaTeX-files in the uninstaller
207 FileOpen $R1 "$INSTDIR\Resources\uninstallPaths.dat" w
208 FileWrite $R1 '$LaTeXPath'
213 Function UpdateMiKTeX
214 # ask to update MiKTeX
216 ${if} $MiKTeXInstalled == "yes"
217 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
219 StrCpy $0 $LaTeXPath -4 # remove "\bin"
220 # the update wizard is either started by the copystart.exe or the copystart_admin.exe
221 # (the latter replaces copystart.exe since miktex-2.6.2742) or the miktex-update.exe
223 ExecWait '"$LaTeXPath\copystart.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
224 ExecWait '"$LaTeXPath\copystart_admin.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
225 ${if} $MiKTeXUser != "HKCU" # call the admin version when the user is admin
226 ExecWait '"$LaTeXPath\internal\miktex-update_admin.exe"' # run MiKTeX's update wizard
228 ExecWait '"$LaTeXPath\internal\miktex-update.exe"' # run MiKTeX's update wizard