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 # and enable MiKTeX's automatic package installation
149 # install LyX's LaTeX class and style files
150 ${if} $PathLaTeX != ""
151 ${if} $MultiUser.Privileges != "Admin"
152 ${orif} $MultiUser.Privileges != "Power"
153 StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
155 StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
158 # only install the LyX packages if they are not already installed
159 ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
161 SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
162 File "${FILES_DVIPOST_PKG}\dvipost.sty"
163 # LyX files in Resources\tex
164 SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
165 CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
167 # refresh MiKTeX's file name database
168 ${if} $MiKTeXUser != "HKCU" # call the admin version when the user is admin
169 nsExec::ExecToLog '"$PathLaTeX\initexmf --admin --update-fndb"'
171 nsExec::ExecToLog '"$PathLaTeX\initexmf --update-fndb"'
173 Pop $UpdateFNDBReturn # Return value
177 # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
178 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
179 ${if} $MiKTeXUser != "HKCU"
180 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
182 # set package repository (MiKTeX's primary package repository)
183 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
184 WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
185 ${if} $MiKTeXUser != "HKCU"
186 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
187 WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
190 # enable MiKTeX's automatic package installation
191 ExecWait '$PathLaTeX\mpm.exe --update-fndb'
192 # the following feature is planned to be used for a possible CD-version
193 # copy LaTeX-packages needed by LyX
194 # SetOutPath "$INSTDIR"
195 # File /r "${LaTeXPackagesDir}"
199 Function UpdateMiKTeX
200 # ask to update MiKTeX
202 ${if} $LaTeXInstalled == "MiKTeX"
203 MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
205 StrCpy $0 $PathLaTeX -4 # remove "\bin"
206 # the update wizard is either started by the copystart_admin.exe
207 # or the miktex-update.exe (since MiKTeX 2.8)
208 ExecWait '"$PathLaTeX\copystart_admin.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
209 ${if} $MiKTeXUser != "HKCU" # call the admin version when the user is admin
210 ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"' # run MiKTeX's update wizard
212 ExecWait '"$PathLaTeX\internal\miktex-update.exe"' # run MiKTeX's update wizard