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