]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/AltInstaller/LaTeX.nsh
update installer: update also lyx.bat file (needed for new launcher)
[lyx.git] / development / Win32 / packaging / AltInstaller / 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 $LatexPath # Function from LyXUtils.nsh
9   
10   ${if} $LatexPath != ""
11    # check if MiKTeX 2.4, 2.5 or 2.6 is installed
12    ReadRegStr $String HKLM "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Install Root"
13    ${if} $String != ""
14     StrCpy $MiKTeXVersion "2.4" # needed later for the configuration of MiKTeX
15     StrCpy $LaTeXName "MiKTeX 2.4"
16    ${endif}
17    # check if MiKTeX 2.5 or 2.6 is installed
18    StrCpy $0 0
19    loopA:
20     EnumRegKey $1 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
21     StrCmp $1 "" doneA
22     StrCpy $String $1
23     IntOp $0 $0 + 1
24     Goto loopA
25    doneA:
26    ${if} $String == "2.5"
27     StrCpy $MiKTeXVersion "2.5"
28     StrCpy $LaTeXName "MiKTeX 2.5"
29    ${endif}
30    ${if} $String == "2.6"
31     StrCpy $MiKTeXVersion "2.6"
32     StrCpy $LaTeXName "MiKTeX 2.6"
33    ${endif}
34   ${endif}
35   
36   ${if} $LatexPath == "" # 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} $LatexPath != ""
41     StrCpy $MiKTeXUser "HKCU" # needed later to configure MiKTeX
42    ${endif}
43    # check for MiKTeX 2.4
44    StrCpy $String ""
45    ReadRegStr $String HKCU "Software\MiK\MiKTeX\CurrentVersion\MiKTeX" "Install Root"
46    ${if} $String != ""
47     StrCpy $MiKTeXVersion "2.4"
48     StrCpy $LaTeXName "MiKTeX 2.4"
49    ${endif}
50    # check for MiKTeX 2.5 and 2.6
51    StrCpy $0 0
52    loopB:
53     EnumRegKey $1 HKCU "SOFTWARE\MiKTeX.org\MiKTeX" $0 # check the last subkey
54     StrCmp $1 "" doneB
55     StrCpy $String $1
56     IntOp $0 $0 + 1
57     Goto loopB
58    doneB:
59    ${if} $String == "2.5"
60     StrCpy $MiKTeXVersion "2.5"
61     StrCpy $LaTeXName "MiKTeX 2.5"
62    ${endif}
63    ${if} $String == "2.6"
64     StrCpy $MiKTeXVersion "2.6"
65     StrCpy $LaTeXName "MiKTeX 2.6"
66    ${endif}
67   ${endif}
68   
69   ${if} $LatexPath != ""
70    StrCpy $MiKTeXInstalled "yes"
71   ${endif}
72   
73   # test if TeXLive is installed
74   # as described at TeXLives' homepage there should be an entry in the PATH
75   ${if} $LatexPath == ""
76    ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
77    StrCpy $Search "TeXLive"
78    Call LaTeXCheck # function from LyXUtils.nsh
79   ${endif}
80   # check for the current user Path variable (the case when it is a live CD/DVD)
81   ${if} $LatexPath == ""
82    ReadRegStr $String HKCU "Environment" "Path"
83    StrCpy $Search "texlive"
84    StrCpy $2 "TeXLive"
85    Call LaTeXCheck # function from LyXUtils.nsh
86   ${endif}
87   # check if the variable TLroot exists (the case when it is installed using the program "tlpmgui")
88   ${if} $LatexPath == ""
89    ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "TLroot"
90    ${if} $String == ""
91     ReadRegStr $String HKCU "Environment" "TLroot" # the case when installed without admin permissions
92    ${endif}
93    StrCpy $LatexPath "$String\bin\win32"
94    # check if the latex.exe exists in the $LatexPath folder
95    !insertmacro FileCheck $5 "latex.exe" "$LatexPath" # macro from LyXUtils.nsh
96    ${if} $5 == "False"
97     StrCpy $LatexPath ""
98    ${endif}
99   ${endif}
100   ${if} $LatexPath != ""
101   ${andif} $LaTeXName != "MiKTeX 2.4"
102   ${andif} $LaTeXName != "MiKTeX 2.5"
103   ${andif} $LaTeXName != "MiKTeX 2.6"
104    StrCpy $LaTeXName "TeXLive"
105   ${endif}
106   
107   ${if} $LatexPath == ""
108    StrCpy $MissedProg "True"
109   ${endif}
110
111 FunctionEnd
112
113 # -------------------------------------------
114
115 !if ${INSTALLER_VERSION} == "Complete"
116
117  Function InstallMiKTeX
118   # install MiKTeX if not already installed
119
120   ${if} $LatexPath == ""
121    # launch MiKTeX's installer
122    MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
123    ExecWait ${MiKTeXInstall}
124    # test if MiKTeX is installed
125    ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
126    StrCpy $Search "miktex"
127    Call LaTeXCheck
128    ${if} $LatexPath == ""
129     StrCpy $MiKTeXUser "HKCU"
130     ReadRegStr $String HKCU "Environment" "Path"
131     StrCpy $Search "miktex"
132     Call LaTeXCheck
133    ${endif}
134    ${if} $LatexPath != ""
135     # set package repository (MiKTeX's primary package repository)
136     WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}" # special entry to tell the uninstaller that it was installed with LyX
137     StrCpy $MiKTeXInstalled "yes"
138     StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
139     ${if} $MiKTeXUser != "HKCU"
140      StrCpy $MiKTeXPath "$LatexPath" -11 # delete "\miktex\bin"
141      #MessageBox MB_OK|MB_ICONINFORMATION "$(MiKTeXPathInfo)" # info that MiKTeX's installation folder must have write permissions for all users to work properly
142     ${endif}
143    ${else}
144     MessageBox MB_OK|MB_ICONSTOP "$(LatexError1)"
145     SetOutPath $TEMP # to be able to delete the $INSTDIR
146     RMDir /r $INSTDIR
147     Abort
148    ${endif} # endif $LatexPath != ""
149   ${endif}
150
151   FunctionEnd
152
153 !endif # endif ${INSTALLER_VERSION} == "Complete"
154
155 # ------------------------------
156
157 Function ConfigureMiKTeX
158  # installs the LaTeX class files that are delivered with LyX
159  # and enable MiKTeX's automatic package installation
160  
161   StrCpy $String $LatexPath
162   StrCpy $Search "miktex\bin"
163   StrLen $3 $String
164   Call StrPoint # search the LaTeXPath for the phrase "miktex\bin" (function from LyXUtils.nsh)
165   ${if} $Pointer != "-1" # if something was found
166    IntOp $Pointer $Pointer - 1 # jump before the first "\" of "\miktex\bin"
167    StrCpy $String $String "$Pointer" # $String is now the part before "\miktex\bin"
168    # install LyX's special LaTeX class files
169    CreateDirectory "$String\tex\latex\lyx"
170    SetOutPath "$String\tex\latex\lyx"
171    File "${ClassFileDir}\lyxchess.sty"
172    File "${ClassFileDir}\lyxskak.sty"
173    CreateDirectory "$String\tex\latex\revtex"
174    SetOutPath "$String\tex\latex\revtex"
175    File "${ClassFileDir}\revtex.cls"
176    CreateDirectory "$String\tex\latex\hollywood"
177    SetOutPath "$String\tex\latex\hollywood"
178    File "${ClassFileDir}\hollywood.cls"
179    CreateDirectory "$String\tex\latex\broadway"
180    SetOutPath "$String\tex\latex\broadway"
181    File "${ClassFileDir}\broadway.cls"
182    # install LaTeX-package dvipost (dvipost is not available for MiKTeX)
183    SetOutPath "$String\tex\latex\"      # Should there be a final \ before "?
184    File /r "${DVIPostFileDir}"
185
186    # refresh MiKTeX's file name database
187    ExecWait "$LaTeXPath\initexmf --update-fndb"
188     
189    ${if} $MiKTeXVersion == "2.4"
190     # delete MiKTeX 2.4's dvipng executable as it is an old broken version. Then install a working one.
191     Delete "$String\miktex\bin\dvipng.exe"
192     # Install a new one
193     SetOutPath "$String\miktex\bin"
194     File "${PRODUCT_DIR}\LyX\external\dvipng.exe"
195     # enable package installation without asking (1=Yes, 0=No, 2=Always Ask Before Installing)                                              
196     WriteRegStr HKCU "SOFTWARE\MiK\MiKTeX\CurrentVersion\MiKTeX" "InstallPackagesOnTheFly" "1"
197     WriteRegStr HKCU "SOFTWARE\MiK\MiKTeX\CurrentVersion\MPM\Settings" "" ""
198     # Setting package repository (MiKTeX's primary package repository)
199     WriteRegStr HKCU "SOFTWARE\MiK\MiKTeX\CurrentVersion\MPM" "RemotePackageRepository" "${MiKTeXRepo}"
200    ${endif}
201    
202    ${if} $MiKTeXVersion == "2.5"
203     # enable package installation without asking (t = Yes, f = No)
204     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for curent user
205     ${if} $MiKTeXUser != "HKCU"
206      WriteRegStr SHCTX "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_AUTOINSTALL" "t"
207     ${endif}
208     # set package repository (MiKTeX's primary package repository)
209     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for curent user
210     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for curent user
211     ${if} $MiKTeXUser != "HKCU"
212      WriteRegStr SHCTX "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_REPOSITORY" "${MiKTeXRepo}"
213     ${endif}
214    ${endif}
215    
216    ${if} $MiKTeXVersion == "2.6"
217     # enable package installation without asking (t = Yes, f = No)
218     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for curent user
219     ${if} $MiKTeXUser != "HKCU"
220      WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for curent user
221     ${endif}
222     # set package repository (MiKTeX's primary package repository)
223     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for curent user
224     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for curent user
225     ${if} $MiKTeXUser != "HKCU"
226      WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for curent user
227      WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for curent user
228     ${endif}
229    ${endif}
230    
231    # enable MiKTeX's automatic package installation
232    ${if} $MiKTeXVersion == "2.4"
233    ${orif} $MiKTeXVersion == "2.5"
234     ExecWait '$LaTeXPath\mpm.com --update-fndb'
235    ${else} # if MiKTeX 2.6
236     ExecWait '$LaTeXPath\mpm.exe --update-fndb'
237    ${endif}
238    # the following feature is planned to be used for a possible CD-version
239    # copy LaTeX-packages needed by LyX
240    # SetOutPath "$INSTDIR"
241    # File /r "${LaTeXPackagesDir}" 
242   ${endif} # end ${if} $Pointer
243   
244   # save MiKTeX's install path to be able to remove LyX's LaTeX-files in the uninstaller
245   FileOpen $R1 "$INSTDIR\Resources\uninstallPaths.dat" w
246   FileWrite $R1 '$LaTeXPath'
247   FileClose $R1
248   
249 FunctionEnd
250
251 Function UpdateMiKTeX
252  # ask to update MiKTeX
253
254   ${if} $MiKTeXInstalled == "yes"
255    MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
256    UpdateNow:
257     StrCpy $0 $LaTeXPath -4 # remove "\bin"
258     ExecWait '"$LaTeXPath\copystart.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
259    UpdateLater:
260   ${endif}
261
262 FunctionEnd
263