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