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