]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/include/LaTeX.nsh
installer fixes
[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 != ""
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     WriteRegStr $MiKTeXUser "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${APP_SERIES_KEY}" # special entry to tell the uninstaller that it was installed with LyX
133     StrCpy $LaTeXInstalled "MiKTeX"
134     StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
135    ${else}
136     MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
137     SetOutPath $TEMP # to be able to delete the $INSTDIR
138     RMDir /r $INSTDIR
139     Abort
140    ${endif} # endif $PathLaTeX != ""
141   ${endif}
142
143   FunctionEnd
144
145 !endif # endif ${SETUPTYPE} == BUNDLE
146
147 # ------------------------------
148
149 Function ConfigureMiKTeX
150  # installs the LaTeX class files that are delivered with LyX,
151  # a Perl interpreter for splitindex
152  # and enable MiKTeX's automatic package installation
153  
154  # install LyX's LaTeX class and style files and a Perl interpreter
155  ${if} $PathLaTeX != ""
156   ${if} $MultiUser.Privileges == "Admin"
157   ${orif} $MultiUser.Privileges == "Power"
158    StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
159   ${else}
160    StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
161   ${endif}
162
163   # only install the LyX packages if they are not already installed
164   ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
165    # dvipost
166    SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
167    File "${FILES_DVIPOST_PKG}\dvipost.sty"
168    # LyX files in Resources\tex
169    SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
170    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
171   ${endif}
172   
173   # only install a Perl interpreter if it is not already installed
174   # this is only possible if miktex and LyX is installed with the same privileges
175   ${if} $MultiUser.Privileges != "Admin"
176   ${andif} $MultiUser.Privileges != "Power"
177    ${if} $PathLaTeX != "$LOCALAPPDATA\MiKTeX\$MiKTeXVersion\miktex\bin"
178     ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
179      # FIXME: output a translatable message in this case
180      MessageBox MB_OK "LyX's multiple index feature will not work because MiKTeX was installed with admin privileges but you don't have them."
181     ${endif}
182    ${else}
183     ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
184      SetOutPath "$PathLaTeXLocal"
185      File /r ${FILES_MIKTEX}
186     ${endif}
187    ${endif}
188   ${else}
189    ${ifnot} ${FileExists} "$PathLaTeX\perl.exe"
190     SetOutPath "$PathLaTeXLocal"
191     File /r ${FILES_MIKTEX}
192    ${endif}
193   ${endif}
194   
195   # refresh MiKTeX's file name database (do this always to assure everything is in place)
196   ${if} $MultiUser.Privileges != "Admin"
197   ${andif} $MultiUser.Privileges != "Power"
198    # call the non-admin version
199    nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
200   ${else}
201    ${if} $MiKTeXUser != "HKCU" # call the admin version
202     nsExec::ExecToLog "$PathLaTeX\initexmf --admin --update-fndb"
203    ${else}
204     nsExec::ExecToLog "$PathLaTeX\initexmf --update-fndb"
205    ${endif}
206   ${endif}
207   Pop $UpdateFNDBReturn # Return value
208   
209  ${endif}
210   
211   # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
212   WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
213   ${if} $MiKTeXUser != "HKCU"
214    WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
215   ${endif}
216   # set package repository (MiKTeX's primary package repository)
217   WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
218   WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
219   ${if} $MiKTeXUser != "HKCU"
220    WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
221    WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
222   ${endif}
223   
224   # enable MiKTeX's automatic package installation
225   ExecWait '$PathLaTeX\mpm.exe --update-fndb'
226   # the following feature is planned to be used for a possible CD-version
227   # copy LaTeX-packages needed by LyX
228   # SetOutPath "$INSTDIR"
229   # File /r "${LaTeXPackagesDir}" 
230   
231 FunctionEnd
232
233 Function UpdateMiKTeX
234  # ask to update MiKTeX
235
236   ${if} $LaTeXInstalled == "MiKTeX"
237    MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
238    UpdateNow:
239     StrCpy $0 $PathLaTeX -4 # remove "\bin"
240     # the update wizard is either started by the copystart_admin.exe
241     # or the miktex-update.exe (since MiKTeX 2.8)
242     ${if} $MultiUser.Privileges != "Admin"
243     ${andif} $MultiUser.Privileges != "Power"
244      # call the non-admin version
245      ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
246      ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
247     ${else}
248      ${if} $MiKTeXUser != "HKCU" # call the admin version
249       ExecWait '"$PathLaTeX\copystart_admin.exe" "$0\config\update.dat"'
250       ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"' # run MiKTeX's update wizard
251      ${else}
252       ExecWait '"$PathLaTeX\copystart.exe" "$0\config\update.dat"'
253       ExecWait '"$PathLaTeX\internal\miktex-update.exe"'
254      ${endif}
255     ${endif}
256    UpdateLater:
257   ${endif}
258
259 FunctionEnd
260