]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/AltInstaller/LaTeX.nsh
installer: sync to trunk again
[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.5 or 2.6 and 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.5"
21     StrCpy $MiKTeXVersion "2.5"
22     StrCpy $LaTeXName "MiKTeX 2.5"
23    ${endif}
24    ${if} $String == "2.6"
25     StrCpy $MiKTeXVersion "2.6"
26     StrCpy $LaTeXName "MiKTeX 2.6"
27    ${endif}
28    ${if} $String == "2.7"
29     StrCpy $MiKTeXVersion "2.7"
30     StrCpy $LaTeXName "MiKTeX 2.7"
31    ${endif}
32   ${endif}
33   
34   ${if} $LatexPath == "" # 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} $LatexPath != ""
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.5"
52     StrCpy $MiKTeXVersion "2.5"
53     StrCpy $LaTeXName "MiKTeX 2.5"
54    ${endif}
55    ${if} $String == "2.6"
56     StrCpy $MiKTeXVersion "2.6"
57     StrCpy $LaTeXName "MiKTeX 2.6"
58    ${endif}
59    ${if} $String == "2.7"
60     StrCpy $MiKTeXVersion "2.7"
61     StrCpy $LaTeXName "MiKTeX 2.7"
62    ${endif}
63   ${endif}
64     
65   ${if} $LatexPath != ""
66    StrCpy $MiKTeXInstalled "yes"
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} $LatexPath == ""
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} $LatexPath == ""
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} $LatexPath == ""
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 $LatexPath "$String\bin\win32"
90    # check if the latex.exe exists in the $LatexPath folder
91    !insertmacro FileCheck $5 "latex.exe" "$LatexPath" # macro from LyXUtils.nsh
92    ${if} $5 == "False"
93     StrCpy $LatexPath ""
94    ${endif}
95   ${endif}
96   ${if} $LatexPath != ""
97   ${andif} $LaTeXName != "MiKTeX 2.5"
98   ${andif} $LaTeXName != "MiKTeX 2.6"
99   ${andif} $LaTeXName != "MiKTeX 2.7"
100    StrCpy $LaTeXName "TeXLive"
101   ${endif}
102   
103   ${if} $LatexPath == ""
104    StrCpy $MissedProg "True"
105   ${endif}
106
107 FunctionEnd
108
109 # -------------------------------------------
110
111 !if ${INSTALLER_VERSION} == "Complete"
112
113  Function InstallMiKTeX
114   # install MiKTeX if not already installed
115
116   ${if} $LatexPath == ""
117    # launch MiKTeX's installer
118    MessageBox MB_OK|MB_ICONINFORMATION "$(LatexInfo)"
119    ExecWait ${MiKTeXInstall}
120    # test if MiKTeX is installed
121    ReadRegStr $String HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path"
122    StrCpy $Search "miktex"
123    Call LaTeXCheck
124    ${if} $LatexPath == ""
125     StrCpy $MiKTeXUser "HKCU"
126     ReadRegStr $String HKCU "Environment" "Path"
127     StrCpy $Search "miktex"
128     Call LaTeXCheck
129    ${endif}
130    ${if} $LatexPath != ""
131     # set package repository (MiKTeX's primary package repository)
132     WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}" # special entry to tell the uninstaller that it was installed with LyX
133     StrCpy $MiKTeXInstalled "yes"
134     StrCpy $MiKTeXVersion ${MiKTeXDeliveredVersion}
135     ${if} $MiKTeXUser != "HKCU"
136      StrCpy $MiKTeXPath "$LatexPath" -11 # delete "\miktex\bin"
137      #MessageBox MB_OK|MB_ICONINFORMATION "$(MiKTeXPathInfo)" # info that MiKTeX's installation folder must have write permissions for all users to work properly
138     ${endif}
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 $LatexPath != ""
145   ${endif}
146
147   FunctionEnd
148
149 !endif # endif ${INSTALLER_VERSION} == "Complete"
150
151 # ------------------------------
152
153 Function ConfigureMiKTeX
154  # installs the LaTeX class files that are delivered with LyX
155  # and enable MiKTeX's automatic package installation
156  
157   StrCpy $String $LatexPath
158   StrCpy $Search "miktex\bin"
159   StrLen $3 $String
160   Call StrPoint # search the LaTeXPath for the phrase "miktex\bin" (function from LyXUtils.nsh)
161   ${if} $Pointer != "-1" # if something was found
162    IntOp $Pointer $Pointer - 1 # jump before the first "\" of "\miktex\bin"
163    StrCpy $String $String "$Pointer" # $String is now the part before "\miktex\bin"
164    # install LyX's special LaTeX class files
165    CreateDirectory "$String\tex\latex\lyx"
166    SetOutPath "$String\tex\latex\lyx"
167    File "${ClassFileDir}\lyxchess.sty"
168    File "${ClassFileDir}\lyxskak.sty"
169    CreateDirectory "$String\tex\latex\revtex"
170    SetOutPath "$String\tex\latex\revtex"
171    File "${ClassFileDir}\revtex.cls"
172    CreateDirectory "$String\tex\latex\hollywood"
173    SetOutPath "$String\tex\latex\hollywood"
174    File "${ClassFileDir}\hollywood.cls"
175    CreateDirectory "$String\tex\latex\broadway"
176    SetOutPath "$String\tex\latex\broadway"
177    File "${ClassFileDir}\broadway.cls"
178    # install LaTeX-package dvipost (dvipost is not available for MiKTeX)
179    SetOutPath "$String\tex\latex"
180    File /r "${DVIPostFileDir}"
181
182    # refresh MiKTeX's file name database
183    ExecWait "$LaTeXPath\initexmf --update-fndb"
184     
185    ${if} $MiKTeXVersion == "2.5"
186     # enable package installation without asking (t = Yes, f = No)
187     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
188     ${if} $MiKTeXUser != "HKCU"
189      WriteRegStr SHCTX "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_AUTOINSTALL" "t"
190     ${endif}
191     # set package repository (MiKTeX's primary package repository)
192     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
193     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
194     ${if} $MiKTeXUser != "HKCU"
195      WriteRegStr SHCTX "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_REPOSITORY" "${MiKTeXRepo}"
196     ${endif}
197    
198    ${else} # if MiKTeX 2.6 or above
199     # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
200     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
201     ${if} $MiKTeXUser != "HKCU"
202      WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
203     ${endif}
204     # set package repository (MiKTeX's primary package repository)
205     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
206     WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
207     ${if} $MiKTeXUser != "HKCU"
208      WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
209      WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
210     ${endif}
211     
212    ${endif} # end if $MiKTeXVersion == "2.5"
213    
214    # enable MiKTeX's automatic package installation
215    ${if} $MiKTeXVersion == "2.5"
216     ExecWait '$LaTeXPath\mpm.com --update-fndb'
217    ${else} # MiKTeX 2.6 or newer
218     ExecWait '$LaTeXPath\mpm.exe --update-fndb'
219    ${endif}
220    # the following feature is planned to be used for a possible CD-version
221    # copy LaTeX-packages needed by LyX
222    # SetOutPath "$INSTDIR"
223    # File /r "${LaTeXPackagesDir}" 
224   ${endif} # end ${if} $Pointer
225   
226   # save MiKTeX's install path to be able to remove LyX's LaTeX-files in the uninstaller
227   FileOpen $R1 "$INSTDIR\Resources\uninstallPaths.dat" w
228   FileWrite $R1 '$LaTeXPath'
229   FileClose $R1
230   
231 FunctionEnd
232
233 Function UpdateMiKTeX
234  # ask to update MiKTeX
235
236   ${if} $MiKTeXInstalled == "yes"
237    MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
238    UpdateNow:
239     StrCpy $0 $LaTeXPath -4 # remove "\bin"
240     # the update wizard is either started by the copystart.exe or the copystart_admin.exe
241     # the latter replaces copystart.exe since miktex-2.6.2742
242     ExecWait '"$LaTeXPath\copystart.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
243     ExecWait '"$LaTeXPath\copystart_admin.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
244    UpdateLater:
245   ${endif}
246
247 FunctionEnd
248