]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/installer/include/LaTeX.nsh
fix 2 more installer issues
[lyx.git] / development / Win32 / packaging / installer / include / LaTeX.nsh
1 Function LaTeXActions
2  # check if MiKTeX or TeXLive is installed
3
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
9   
10   ${if} $PathLaTeX != ""
11    # check if MiKTeX 2.7 or newer is installed
12    StrCpy $0 0
13    loopA:
14     EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
15     StrCmp $1 "" doneA
16     StrCpy $String $1
17     IntOp $0 $0 + 1
18     Goto loopA
19    doneA:
20    ${if} $String == "2.7"
21     StrCpy $MiKTeXVersion "2.7"
22     StrCpy $LaTeXName "MiKTeX 2.7"
23    ${endif}
24    ${if} $String == "2.8"
25     StrCpy $MiKTeXVersion "2.8"
26     StrCpy $LaTeXName "MiKTeX 2.8"
27    ${endif}
28    ${if} $String == "2.9"
29     StrCpy $MiKTeXVersion "2.9"
30     StrCpy $LaTeXName "MiKTeX 2.9"
31    ${endif}
32   ${endif}
33   
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"
42    ${endif}
43   ${endif}
44   ${if} $LaTeXName == "" # check for the MiKTeX version
45    StrCpy $0 0
46    loopB:
47     EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
48     StrCmp $1 "" doneB
49     StrCpy $String $1
50     IntOp $0 $0 + 1
51     Goto loopB
52    doneB:
53    ${if} $String == "2.7"
54     StrCpy $MiKTeXVersion "2.7"
55     StrCpy $LaTeXName "MiKTeX 2.7"
56    ${endif}
57    ${if} $String == "2.8"
58     StrCpy $MiKTeXVersion "2.8"
59     StrCpy $LaTeXName "MiKTeX 2.8"
60    ${endif}
61    ${if} $String == "2.9"
62     StrCpy $MiKTeXVersion "2.9"
63     StrCpy $LaTeXName "MiKTeX 2.9"
64    ${endif}
65   ${endif}
66     
67   ${if} $PathLaTeX != ""
68    StrCpy $LaTeXInstalled "MiKTeX"
69   ${endif}
70   
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
77   ${endif}
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"
82    StrCpy $2 "TeXLive"
83    Call LaTeXCheck # function from LyXUtils.nsh
84   ${endif}
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"
88    ${if} $String == ""
89     ReadRegStr $String HKCU "Environment" "TLroot" # the case when installed without admin permissions
90    ${endif}
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
94    ${if} $5 == "False"
95     StrCpy $PathLaTeX ""
96    ${endif}
97   ${endif}
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"
103   ${endif}
104
105 FunctionEnd
106
107 # -------------------------------------------
108
109 !if ${SETUPTYPE} == BUNDLE
110
111  Function InstallMiKTeX
112   
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"
124    ${else}
125     StrCpy $MiKTeXUser "HKCU"
126     ReadRegStr $String HKCU "Environment" "Path"
127     StrCpy $Search "miktex"
128     Call LaTeXCheck # function from LyXUtils.nsh
129    ${endif}
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
134     ${else}
135      WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
136     ${endif}
137     StrCpy $LaTeXInstalled "MiKTeX"
138     StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
139    ${else}
140     MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
141     SetOutPath $TEMP # to be able to delete the $INSTDIR
142     RMDir /r $INSTDIR
143     Abort
144    ${endif} # endif $PathLaTeX != ""
145   ${endif}
146
147   FunctionEnd
148
149 !endif # endif ${SETUPTYPE} == BUNDLE
150
151 # ------------------------------
152
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
157  
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"
163   ${else}
164    StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
165   ${endif}
166
167   # only install the LyX packages if they are not already installed
168   ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
169    # dvipost
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"
175   ${endif}
176   
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)"
184     ${endif}
185    ${else}
186     ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
187      SetOutPath "$PathLaTeXLocal"
188      File /r ${FILES_MIKTEX}
189     ${endif}
190    ${endif}
191   ${else}
192    ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
193     SetOutPath "$PathLaTeXLocal"
194     File /r ${FILES_MIKTEX}
195    ${endif}
196   ${endif}
197   
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"
203   ${else}
204    ${if} $MiKTeXUser != "HKCU" # call the admin version
205     nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
206    ${else}
207     nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
208    ${endif}
209   ${endif}
210   Pop $UpdateFNDBReturn # Return value
211   
212  ${endif}
213   
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"
218   ${endif}
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"
225   ${endif}
226   
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}" 
233   
234 FunctionEnd
235
236 Function UpdateMiKTeX
237  # ask to update MiKTeX
238
239   ${if} $LaTeXInstalled == "MiKTeX"
240    MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
241    UpdateNow:
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"'
250     ${else}
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
254      ${else}
255       ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
256       ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
257      ${endif}
258     ${endif}
259    UpdateLater:
260   ${endif}
261
262 FunctionEnd
263