]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/LaTeX.nsh
installer: install a Perl interpreter to MiKTeX to fix bug #8181
[features.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 == "" # 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
40    ${endif}
41   ${endif}
42   ${if} $LaTeXName == "" # check for the MiKTeX version
43    StrCpy $0 0
44    loopB:
45     EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
46     StrCmp $1 "" doneB
47     StrCpy $String $1
48     IntOp $0 $0 + 1
49     Goto loopB
50    doneB:
51    ${if} $String == "2.7"
52     StrCpy $MiKTeXVersion "2.7"
53     StrCpy $LaTeXName "MiKTeX 2.7"
54    ${endif}
55    ${if} $String == "2.8"
56     StrCpy $MiKTeXVersion "2.8"
57     StrCpy $LaTeXName "MiKTeX 2.8"
58    ${endif}
59    ${if} $String == "2.9"
60     StrCpy $MiKTeXVersion "2.9"
61     StrCpy $LaTeXName "MiKTeX 2.9"
62    ${endif}
63   ${endif}
64     
65   ${if} $PathLaTeX != ""
66    StrCpy $LaTeXInstalled "MiKTeX"
67   ${endif}
68   
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
75   ${endif}
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"
80    StrCpy $2 "TeXLive"
81    Call LaTeXCheck # function from LyXUtils.nsh
82   ${endif}
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"
86    ${if} $String == ""
87     ReadRegStr $String HKCU "Environment" "TLroot" # the case when installed without admin permissions
88    ${endif}
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
92    ${if} $5 == "False"
93     StrCpy $PathLaTeX ""
94    ${endif}
95   ${endif}
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"
101   ${endif}
102
103 FunctionEnd
104
105 # -------------------------------------------
106
107 !if ${SETUPTYPE} == BUNDLE
108
109  Function InstallMiKTeX
110   
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
125    ${endif}
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}
131    ${else}
132     MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
133     SetOutPath $TEMP # to be able to delete the $INSTDIR
134     RMDir /r $INSTDIR
135     Abort
136    ${endif} # endif $PathLaTeX != ""
137   ${endif}
138
139   FunctionEnd
140
141 !endif # endif ${SETUPTYPE} == BUNDLE
142
143 # ------------------------------
144
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
149  
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"
155   ${else}
156    StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
157   ${endif}
158
159   # only install the LyX packages if they are not already installed
160   ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
161    # dvipost
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"
167   ${endif}
168   
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}
173   ${endif}
174   
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"'
178   ${else} 
179    nsExec::ExecToLog '"$PathLaTeX\initexmf --update-fndb"'
180   ${endif}
181   Pop $UpdateFNDBReturn # Return value
182   
183  ${endif}
184   
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"
189   ${endif}
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"
196   ${endif}
197   
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}" 
204   
205 FunctionEnd
206
207 Function UpdateMiKTeX
208  # ask to update MiKTeX
209
210   ${if} $LaTeXInstalled == "MiKTeX"
211    MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
212    UpdateNow:
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
219     ${else} 
220      ExecWait '"$PathLaTeX\internal\miktex-update.exe"' # run MiKTeX's update wizard
221     ${endif} 
222    UpdateLater:
223   ${endif}
224
225 FunctionEnd
226