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