]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/installer/include/LaTeX.nsh
installer:
[lyx.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  # and enable MiKTeX's automatic package installation
148  
149  # install LyX's LaTeX class and style files
150  ${if} $PathLaTeX != ""
151   ${if} $MultiUser.Privileges != "Admin"
152   ${orif} $MultiUser.Privileges != "Power"
153    StrCpy $PathLaTeXLocal "$PathLaTeX" -11 # delete "\miktex\bin"
154   ${else}
155    StrCpy $PathLaTeXLocal "$APPDATA\MiKTeX\$MiKTeXVersion"
156   ${endif}
157
158   # only install the LyX packages if they are not already installed
159   ${ifnot} ${FileExists} "$PathLaTeXLocal\tex\latex\lyx\broadway.cls"
160    # dvipost
161    SetOutPath "$PathLaTeXLocal\tex\latex\dvipost"
162    File "${FILES_DVIPOST_PKG}\dvipost.sty"
163    # LyX files in Resources\tex
164    SetOutPath "$PathLaTeXLocal\tex\latex\lyx"
165    CopyFiles /SILENT "$INSTDIR\Resources\tex\*.*" "$PathLaTeXLocal\tex\latex\lyx"
166   
167    # refresh MiKTeX's file name database
168    ${if} $MiKTeXUser != "HKCU" # call the admin version when the user is admin
169     nsExec::ExecToLog '"$PathLaTeX\initexmf --admin --update-fndb"'
170    ${else} 
171     nsExec::ExecToLog '"$PathLaTeX\initexmf --update-fndb"'
172    ${endif}
173    Pop $UpdateFNDBReturn # Return value
174   ${endif}
175  ${endif}
176   
177   # enable package installation without asking (1 = Yes, 0 = No, 2 = Ask me first)
178   WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1" # if only for current user
179   ${if} $MiKTeXUser != "HKCU"
180    WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "AutoInstall" "1"
181   ${endif}
182   # set package repository (MiKTeX's primary package repository)
183   WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}" # if only for current user
184   WriteRegStr HKCU "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote" # if only for current user
185   ${if} $MiKTeXUser != "HKCU"
186    WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RemoteRepository" "${MiKTeXRepo}"
187    WriteRegStr SHCTX "SOFTWARE\MiKTeX.org\MiKTeX\$MiKTeXVersion\MPM" "RepositoryType" "remote"
188   ${endif}
189   
190   # enable MiKTeX's automatic package installation
191   ExecWait '$PathLaTeX\mpm.exe --update-fndb'
192   # the following feature is planned to be used for a possible CD-version
193   # copy LaTeX-packages needed by LyX
194   # SetOutPath "$INSTDIR"
195   # File /r "${LaTeXPackagesDir}" 
196   
197 FunctionEnd
198
199 Function UpdateMiKTeX
200  # ask to update MiKTeX
201
202   ${if} $LaTeXInstalled == "MiKTeX"
203    MessageBox MB_YESNO|MB_ICONINFORMATION "$(MiKTeXInfo)" IDYES UpdateNow IDNO UpdateLater
204    UpdateNow:
205     StrCpy $0 $PathLaTeX -4 # remove "\bin"
206     # the update wizard is either started by the copystart_admin.exe
207     # or the miktex-update.exe (since MiKTeX 2.8)
208     ExecWait '"$PathLaTeX\copystart_admin.exe" "$0\config\update.dat"' # run MiKTeX's update wizard
209     ${if} $MiKTeXUser != "HKCU" # call the admin version when the user is admin
210      ExecWait '"$PathLaTeX\internal\miktex-update_admin.exe"' # run MiKTeX's update wizard
211     ${else} 
212      ExecWait '"$PathLaTeX\internal\miktex-update.exe"' # run MiKTeX's update wizard
213     ${endif} 
214    UpdateLater:
215   ${endif}
216
217 FunctionEnd
218