]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/LaTeX.nsh
Copy over Windows installer updates from stable.
[features.git] / development / Win32 / packaging / installer / include / LaTeX.nsh
1 /*
2 LaTeX.nsh
3
4 Handling of LaTeX distributions
5 */
6
7 # This script contains the following functions:
8 #
9 # - LaTeXActions (checks if MiKTeX or TeXLive is installed)
10 #
11 # - ConfigureMiKTeX
12 #   (installs the LaTeX class files that are delivered with LyX,
13 #    a Perl interpreter for splitindex and pdfcrop
14 #    and enable MiKTeX's automatic package installation)
15 #
16 # - ConfigureTeXLive
17 #   (installs the LaTeX class files that are delivered with LyX)
18
19 # ---------------------------------------
20
21 Function LaTeXActions
22  # checks if MiKTeX or TeXLive is installed
23
24   StrCpy $Is64bit "false"
25   
26   ${if} ${RunningX64}
27    SetRegView 64 # the PATH is in the 64bit registry section
28   ${endif}
29   # test if MiKTeX is installed
30   # reads the PATH variable via the registry because NSIS' "$%Path%" variable is not updated when the PATH changes
31   ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
32   StrCpy $Search "miktex"
33   Call LaTeXCheck # sets the path to the latex.exe to $PathLaTeX # Function from LyXUtils.nsh
34   
35   StrCpy $String $PathLaTeX
36   StrCpy $Search "x64" # search if it is 64bit MiKTeX
37   Call StrPoint # Function from LyXUtils.nsh
38   ${if} $Pointer != "-1" # if something was found
39    StrCpy $Is64bit "true"
40   ${endif}
41   
42   # check for 32bit MiKTeX
43   ${if} $PathLaTeX != ""
44   ${andif} $Is64bit != "true"
45    ${if} ${RunningX64}
46     SetRegView 32
47    ${endif}
48    # check if MiKTeX 2.8 or newer is installed
49    StrCpy $0 0
50    loop32:
51     EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
52     StrCmp $1 "" done32
53     StrCpy $String $1
54     IntOp $0 $0 + 1
55     Goto loop32
56    done32:
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   # check for 64bit MiKTeX
68   ${if} $LaTeXName == ""
69    ${if} ${RunningX64}
70     SetRegView 64
71    ${endif}
72    # check if MiKTeX 2.8 or newer is installed
73    StrCpy $0 0
74    loop64:
75     EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
76     StrCmp $1 "" done64
77     StrCpy $String $1
78     IntOp $0 $0 + 1
79     Goto loop64
80    done64:
81    ${if} $String == "2.8"
82     StrCpy $MiKTeXVersion "2.8"
83     StrCpy $LaTeXName "MiKTeX 2.8"
84    ${endif}
85    ${if} $String == "2.9"
86     StrCpy $MiKTeXVersion "2.9"
87     StrCpy $LaTeXName "MiKTeX 2.9"
88    ${endif}
89   ${endif}
90   
91   ${if} $PathLaTeX != ""
92    StrCpy $MiKTeXUser "HKLM" # needed later to configure MiKTeX
93   ${else} # check if MiKTeX is installed only for the current user
94    ${if} ${RunningX64}
95     SetRegView 64 # the PATH is in the 64bit registry section
96    ${endif}
97    ReadRegStr $String HKCU "Environment" "Path"
98    StrCpy $Search "miktex"
99    Call LaTeXCheck # function from LyXUtils.nsh
100    ${if} $PathLaTeX != ""
101     StrCpy $MiKTeXUser "HKCU"
102    ${endif}
103   ${endif}
104   ${if} $LaTeXName == "" # check for the MiKTeX version
105    StrCpy $0 0
106    loopB:
107     EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
108     StrCmp $1 "" doneB
109     StrCpy $String $1
110     IntOp $0 $0 + 1
111     Goto loopB
112    doneB:
113    ${if} $String == "2.8"
114     StrCpy $MiKTeXVersion "2.8"
115     StrCpy $LaTeXName "MiKTeX 2.8"
116    ${endif}
117    ${if} $String == "2.9"
118     StrCpy $MiKTeXVersion "2.9"
119     StrCpy $LaTeXName "MiKTeX 2.9"
120    ${endif}
121   ${endif}
122   
123   ${if} $PathLaTeX != ""
124    StrCpy $String $PathLaTeX
125    StrCpy $Search "x64" # search if it is 64bit MiKTeX
126    Call StrPoint # Function from LyXUtils.nsh
127    ${if} $Pointer != "-1" # if something was found
128     StrCpy $Is64bit "true"
129    ${endif}
130    StrCpy $LaTeXInstalled "MiKTeX"
131    # on some installations the path ends with a "\" on some not
132    # therefore assure that we remove it if it exists
133    StrCpy $0 $PathLaTeX "" -1
134    ${if} $0 == "\"
135     StrCpy $PathLaTeX "$PathLaTeX" -1 # delete "\"
136    ${endif}
137   ${endif}
138   
139   # test if TeXLive is installed
140   # TeXLive can be installed so that it appears in the PATH variable and/or only as current user.
141   # The safest method is to first check for the PATH because this is independent of the TeXLive version.
142   ${if} ${RunningX64}
143    SetRegView 64 # the PATH is in the 64bit registry section
144   ${endif}
145   ${if} $PathLaTeX == ""
146    ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
147    StrCpy $Search "TeXLive"
148    Call LaTeXCheck # function from LyXUtils.nsh
149   ${endif}
150   # check for the current user Path variable
151   ${if} $PathLaTeX == ""
152    ReadRegStr $String HKCU "Environment" "Path"
153    StrCpy $Search "texlive"
154    StrCpy $2 "TeXLive"
155    Call LaTeXCheck # function from LyXUtils.nsh
156   ${endif}
157   # check if it was installed to the system
158   ${if} ${RunningX64}
159    SetRegView 32 # TeXLive is a 32bit application
160   ${endif}
161   ${if} $PathLaTeX == ""
162    ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "UninstallString"
163    ${if} $String == ""
164     ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "UninstallString"
165    ${endif}
166    ${if} $String != ""
167     StrCpy $String $String -28 # remove '\tlpkg\installer\uninst.bat"'
168     StrCpy $String $String "" 1 # remove the leading quote
169    ${endif}
170    StrCpy $PathLaTeX "$String\bin\win32"
171    # check if the latex.exe exists in the $PathLaTeX folder
172    !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX" # macro from LyXUtils.nsh
173    ${if} $5 == "False"
174     StrCpy $PathLaTeX ""
175    ${endif}
176   ${endif}
177   # finally set the name
178   ${if} $PathLaTeX != ""
179   ${andif} $LaTeXName != "MiKTeX 2.8"
180   ${andif} $LaTeXName != "MiKTeX 2.9"
181    StrCpy $LaTeXInstalled "TeXLive"
182    ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "DisplayVersion"
183    ${if} $String == ""
184     ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2015" "DisplayVersion"
185    ${endif}
186    ${if} $String == ""
187     ReadRegStr $String HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2014" "DisplayVersion"
188    ${endif}
189    ${if} $String == ""
190     ReadRegStr $String HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\TeXLive2014" "DisplayVersion"
191    ${endif}
192    ${if} $String != ""
193     StrCpy $LaTeXName "TeXLive $String"
194    ${else}
195     StrCpy $LaTeXName "TeXLive"
196    ${endif}
197   ${endif}
198
199 FunctionEnd
200
201 # ------------------------------
202
203 Function ConfigureMiKTeX
204  # installs the LaTeX class files that are delivered with LyX,
205  # a Perl interpreter for splitindex and pdfcrop
206  # and enable MiKTeX's automatic package installation
207  
208  # install LyX's LaTeX class and style files and a Perl interpreter
209  ${if} $PathLaTeX != ""
210   ${if} $MultiUser.Privileges == "Admin"
211   ${orif} $MultiUser.Privileges == "Power"
212    ${if} $Is64bit == "true"
213     StrCpy $PathLaTeXLocal "$PathLaTeX" -15 # delete "\miktex\bin\x64"
214    ${else}
215     StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
216    ${endif}
217   ${else}
218    StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
219   ${endif}
220
221   # only install the LyX packages if they are not already installed
222   ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
223    # dvipost
224    SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
225    File "${FILES_DVIPOST_PKG}\dvipost.sty"
226    # files in Resources\tex
227    SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
228    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
229
230    # refresh MiKTeX's file name database (do this always to assure everything is in place)
231    ${if} $MultiUser.Privileges != "Admin"
232    ${andif} $MultiUser.Privileges != "Power"
233     # call the non-admin version
234     nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
235    ${else}
236     ${if} $MiKTeXUser != "HKCU" # call the admin version
237      nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
238     ${else}
239      nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
240     ${endif}
241    ${endif}
242    Pop $UpdateFNDBReturn # Return value
243   ${endif}
244   
245   # install a Perl interpreter for splitindex and pdfcrop
246   SetOutPath "$INSTDIR"
247   # recursively copy all files under Perl
248   File /r "${FILES_PERL}"
249
250   ${endif} # end if $PathLaTeX != ""  
251 FunctionEnd
252
253 # ------------------------------
254
255 Function ConfigureTeXLive
256  # installs the LaTeX class files that are delivered with LyX
257  # (TeXLive comes already with a Perl interpreter.)
258  
259  ${if} $PathLaTeX != ""
260   StrCpy $PathLaTeXLocal "$PathLaTeX" -10 # delete "\bin\win32"
261   
262   # only install the LyX packages if they are not already installed
263   ${ifnot} ${FileExists} "$PathLaTeXLocal\texmf-dist\tex\latex\lyx\broadway.cls"
264    # dvipost
265    SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\dvipost"
266    File "${FILES_DVIPOST_PKG}\dvipost.sty"
267    # files in Resources\tex
268    SetOutPath "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
269    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\texmf-dist\tex\latex\lyx"
270    # update TeXLive's package file list
271    ExecWait '$PathLaTeX\texhash'
272   ${endif}
273  ${endif}
274  
275 FunctionEnd