]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/installer/setup/install.nsh
installer: fix potential serious bug
[lyx.git] / development / Win32 / packaging / installer / setup / install.nsh
1 /*
2
3 install.nsh
4
5 Installation of program files, dictionaries and external components
6
7 */
8
9 #--------------------------------
10 # Program files
11
12 Var PythonCompileFile
13 Var PythonCompileReturn
14
15 Section -ProgramFiles SecProgramFiles
16
17   # if the $INSTDIR does not contain "LyX" we must add a subfolder to avoid that LyX will e.g.
18   # be installed directly to C:\programs - the uninstaller will then delete the whole
19   # C:\programs directory
20   StrCpy $String $INSTDIR
21   StrCpy $Search "LyX"
22   Call StrPoint # function from LyXUtils.nsh
23   ${if} $Pointer == "-1"
24    StrCpy $INSTDIR "$INSTDIR\${APP_DIR}"
25   ${endif}
26
27  !if ${SETUPTYPE} != BUNDLE
28   # abort the installation if no LaTeX was found but should be used
29   ${if} $PathLaTeX == ""
30   ${andif} $State == "0"
31    SetOutPath $TEMP # to be able to delete the $INSTDIR
32    RMDir /r $INSTDIR
33    Abort
34   ${endif}
35  !endif # end if != BUNDLE
36
37   # Install and register the core LyX files
38   
39   # The macros are defined in filelists.nsh
40   # the parameters are COMMAND DIRECTORY that form command '${COMMAND} "${DIRECTORY}files"  
41   
42   # Initializes the plug-ins dir ($PLUGINSDIR) if not already initialized.
43   # $PLUGINSDIR is automatically deleted when the installer exits.
44   InitPluginsDir
45   
46   # Binaries
47   SetOutPath "$INSTDIR\bin"
48   !insertmacro FileListLyXBin File "${FILES_LYX}\bin\"
49   !insertmacro FileListQtBin File "${FILES_QT}\bin\"
50   !insertmacro FileListQtImageformats File "${FILES_QT}\plugins\imageformats\"
51   !insertmacro FileListDll File "${FILES_DEPS}\bin\"
52   !insertmacro FileListMSVC File "${FILES_MSVC}\"
53   !insertmacro FileListNetpbmBin File "${FILES_NETPBM}\"
54   !insertmacro FileListDTLBin File "${FILES_DTL}\"
55   !insertmacro FileListDvipostBin File "${FILES_DVIPOST}\"
56   !insertmacro FileListPDFViewBin File "${FILES_PDFVIEW}\"
57   !insertmacro FileListPDFToolsBin File "${FILES_PDFTOOLS}\"
58   !insertmacro FileListMetaFile2EPS File "${FILES_METAFILE2EPS}\"
59   
60   # Resources
61   SetOutPath "$INSTDIR"
62   # recursively copy all files under Resources
63   File /r "${FILES_LYX}\Resources"
64   
65   !if ${SETUPTYPE} == BUNDLE
66    
67    # extract the Jabref and MiKTeX installer
68    File /r "${FILES_LYX}\external"
69
70    # install MiKTeX if not already installed
71    Call InstallMiKTeX # function from LaTeX.nsh
72    
73   !endif # end if BUNDLE
74   
75   # Python
76   SetOutPath "$INSTDIR"
77   # recursively copy all files under Python
78   File /r "${FILES_PYTHON}"
79   
80   # Compile all Pyton files to byte-code
81   # The user using the scripts may not have write access
82   FileOpen $PythonCompileFile "$INSTDIR\compilepy.py" w
83   FileWrite $PythonCompileFile "import compileall$\r$\n"
84   FileWrite $PythonCompileFile "compileall.compile_dir('$INSTDIR\python\Lib')$\r$\n"
85   FileWrite $PythonCompileFile "compileall.compile_dir('$INSTDIR\Resources')$\r$\n"
86   FileClose $PythonCompileFile
87   DetailPrint $(TEXT_CONFIGURE_PYTHON)
88   nsExec::ExecToLog '"$INSTDIR\python\python.exe" "$INSTDIR\compilepy.py"'
89   Pop $PythonCompileReturn # Return value
90   Delete "$INSTDIR\compilepy.py"
91   
92   # Components of ImageMagick
93   SetOutPath "$INSTDIR\imagemagick"
94   File /r "${FILES_IMAGEMAGICK}\"
95   !insertmacro FileListMSVC File "${FILES_MSVC}\"
96   # register ImageMagick
97   WriteRegStr SHCTX "SOFTWARE\Classes\Applications" "AutoRun" "$INSTDIR\imagemagick\convert.exe $$"
98   WriteRegStr SHCTX "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "BinPath" "$INSTDIR\imagemagick"
99   WriteRegStr SHCTX "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "CoderModulesPath" "$INSTDIR\imagemagick\modules\coders"
100   WriteRegStr SHCTX "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "ConfigurePath" "$INSTDIR\imagemagick"
101   WriteRegStr SHCTX "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "FilterModulesPath" "$INSTDIR\imagemagick\modules\filters"
102   WriteRegStr SHCTX "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "LibPath" "$INSTDIR\imagemagick"
103   WriteRegStr SHCTX "SOFTWARE\ImageMagick\Current" "BinPath" "$INSTDIR\imagemagick"
104   WriteRegStr SHCTX "SOFTWARE\ImageMagick\Current" "CoderModulesPath" "$INSTDIR\imagemagick\modules\coders"
105   WriteRegStr SHCTX "SOFTWARE\ImageMagick\Current" "ConfigurePath" "$INSTDIR\imagemagick"
106   WriteRegStr SHCTX "SOFTWARE\ImageMagick\Current" "FilterModulesPath" "$INSTDIR\imagemagick\modules\filters"
107   WriteRegStr SHCTX "SOFTWARE\ImageMagick\Current" "LibPath" "$INSTDIR\imagemagick"
108   WriteRegDWORD SHCTX "SOFTWARE\ImageMagick\Current" "QuantumDepth" 0x00000010
109   WriteRegStr SHCTX "SOFTWARE\ImageMagick\Current" "Version" "${ImageMagickVersion}"
110   WriteRegStr SHCTX "SOFTWARE\ImageMagick" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
111   
112   # Components of Ghostscript
113   ${if} $GhostscriptPath == ""
114    SetOutPath "$INSTDIR\ghostscript"
115    File /r "${FILES_GHOSTSCRIPT}\"
116    !insertmacro FileListMSVC File "${FILES_MSVC}\"
117    StrCpy $GhostscriptPath "$INSTDIR\ghostscript\bin"
118   ${endif}
119   
120   !if ${SETUPTYPE} == BUNDLE
121    
122    # install JabRef if not already installed and the user selected it
123    # if no BibTeX editor is installed
124    ${if} $PathBibTeXEditor == ""
125    ${andif} $InstallJabRef == "true"
126     # launch installer
127     MessageBox MB_OK|MB_ICONINFORMATION "$(JabRefInfo)" /SD IDOK
128     IfSilent 0 +2
129     ExecWait "$INSTDIR\${JabRefInstall} /S"
130     ExecWait "$INSTDIR\${JabRefInstall}"
131     # test if JabRef is now installed
132     StrCpy $PathBibTeXEditor ""
133     ${if} $MultiUser.Privileges == "Admin"
134      ${orif} $MultiUser.Privileges == "Power"
135      ReadRegStr $PathBibTeXEditor HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "UninstallString"
136      StrCpy $PathBibTeXEditor $PathBibTeXEditor -14 # remove "\uninstall.exe"
137     ${else}
138      # for non-admin users we can only check if it is in the start menu
139      ReadRegStr $PathBibTeXEditor HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "StartMenu"
140     ${endif}
141     ${if} $PathBibTeXEditor == ""
142      MessageBox MB_OK|MB_ICONEXCLAMATION "$(JabRefError)" /SD IDOK
143     ${else}
144      # special entry that it was installed together with LyX
145      # so that we can later uninstall it together with LyX
146      ${if} $MultiUser.Privileges == "Admin"
147      ${orif} $MultiUser.Privileges == "Power"
148       WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
149      ${else}
150       WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX" "Yes${APP_SERIES_KEY}"
151      ${endif}
152     ${endif} 
153    ${endif} # end if PathBibTeXEditor
154   !endif # end if BUNDLE
155   
156    # install eLyXer
157    SetOutPath "$INSTDIR\Python\Lib"
158    !insertmacro FileListeLyXer File "${FILES_ELYXER}\"
159    
160    # install unoconv
161    SetOutPath "$INSTDIR\Python\Lib"
162    !insertmacro FileListUnoConv File "${FILES_UNOCONV}\"
163
164   # install the LaTeX class files that are delivered with LyX to MiKTeX
165   # and enable MiKTeX's automatic package installation
166   ${if} $LaTeXInstalled == "MiKTeX"
167    Call ConfigureMiKTeX # Function from LaTeX.nsh
168   ${endif}
169   # install the LaTeX class files that are delivered with LyX to TeXLive
170   ${if} $LaTeXInstalled == "TeXLive"
171    Call ConfigureTeXLive # Function from LaTeX.nsh
172   ${endif}
173   
174   # download dictionaries and thesaurus
175   ${if} $DictCodes != ""
176    Call InstallHunspellDictionaries # Function from dictionaries.nsh
177   ${endif}
178   ${if} $ThesCodes != ""
179    Call InstallThesaurusDictionaries # Function from dictionaries.nsh
180   ${endif}
181   # finally delete the list of mirrors
182   Delete "$INSTDIR\Resources\DictionaryMirrors.txt"
183   
184   # Create uninstaller
185   WriteUninstaller "$INSTDIR\${SETUP_UNINSTALLER}"
186
187 SectionEnd
188
189 #--------------------------------
190 # Support code for file downloads
191
192 !macro DOWNLOAD_FILE RET ID FILENAME APPEND
193
194   # Downloads a file
195   
196   # RET = Return value (OK if succesful)
197   # ID = Name of the download in settings.nsh
198   # FILENAME = Location to store file
199   # APPEND = Filename to append to server location in settings.nsh
200
201   # Try first time
202   NSISdl::download "${DOWNLOAD_${ID}}${APPEND}" "$PLUGINSDIR\${FILENAME}"
203   Pop ${RET} # Return value (OK if succesful)
204
205   ${If} ${RET} != "success"
206     ${AndIf} ${RET} != "cancel"
207     # Download failed, try once again before giving up
208     # (usally we get a different mirror)
209     NSISdl::download "${DOWNLOAD_${ID}}${APPEND}" "$PLUGINSDIR\${FILENAME}"
210     Pop ${RET}
211   ${EndIf}
212
213 !macroend
214
215 #--------------------------------
216 # External components
217
218 #Var PathAllUsers
219 #Var PathCurrentUser
220
221 !macro EXTERNAL COMPONENT
222
223   # Download/Install the component
224   
225   ${If} $Setup${COMPONENT} == ${TRUE}
226   
227     StrCpy $Path${COMPONENT} "" ;A new one will be installed
228   
229     !ifndef BUNDLESETUP_${COMPONENT}
230       !insertmacro EXTERNAL_DOWNLOAD ${COMPONENT}
231     !else
232       !insertmacro EXTERNAL_INSTALL ${COMPONENT}
233     !endif
234     
235   ${EndIf}
236
237 !macroend
238
239 !macro EXTERNAL_RUNINSTALLER COMPONENT
240
241   # Run the installer application of the component that does the actual installation.
242
243   install_${COMPONENT}:
244       
245     ExecWait '"$PLUGINSDIR\${COMPONENT}Setup.exe"'
246     
247     # Updates the path environment variable of the installer process to the latest system value
248 #    ReadRegStr $PathAllUsers HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path
249 #    ReadRegStr $PathCurrentUser HKCU "Environment" Path
250 #    System::Call 'kernel32::SetEnvironmentVariableA(t, t) i("Path", "$PathAllUsers;$PathCurrentUser").'
251
252     Call Search${COMPONENT}
253     
254     ${If} $Path${COMPONENT} == ""  
255       MessageBox MB_YESNO|MB_ICONEXCLAMATION $(TEXT_NOTINSTALLED_${COMPONENT}) IDYES install_${COMPONENT}
256     ${EndIf}
257       
258     Delete "$PLUGINSDIR\${COMPONENT}Setup.exe"
259      
260 !macroend
261
262 !macro EXTERNAL_DOWNLOAD COMPONENT
263
264   download_${COMPONENT}:
265
266     !insertmacro DOWNLOAD_FILE $DownloadResult "${COMPONENT}" "${COMPONENT}Setup.exe" ""
267  
268     ${If} $DownloadResult != "success"
269       ${AndIf} $DownloadResult != "cancel"
270       # Download failed after trying twice - ask user
271       MessageBox MB_YESNO|MB_ICONEXCLAMATION "$(TEXT_DOWNLOAD_FAILED_${COMPONENT}) ($DownloadResult)" IDYES download_${COMPONENT}
272       Goto noinstall_${COMPONENT}
273     ${EndIf}
274       
275     !insertmacro EXTERNAL_RUNINSTALLER ${COMPONENT}
276       
277   noinstall_${COMPONENT}:
278
279 !macroend
280
281 !macro EXTERNAL_INSTALL COMPONENT
282
283   # Extract
284   File /oname=$PLUGINSDIR\${COMPONENT}Setup.exe ${FILES_BUNDLE}\${INSTALL_${COMPONENT}}
285     
286   !insertmacro EXTERNAL_RUNINSTALLER ${COMPONENT}
287     
288 !macroend
289
290
291 # Sections for external components
292
293 #Section -LaTeX ExternalLaTeX
294 #  !insertmacro EXTERNAL LaTeX
295 #SectionEnd
296
297 /*Function InitExternal
298
299   # Get sizes of external component installers
300   
301   #SectionGetSize ${ExternalLaTeX} $SizeLaTeX
302   
303   # Add download size
304   
305   !ifndef BUNDLESETUP_MIKTEX
306     IntOp $SizeLaTeX $SizeLaTeX + ${SIZE_DOWNLOAD_LATEX}
307   !endif
308
309 FunctionEnd*/