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