]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/AltInstaller/InstallActions-update.nsh
4087cab2de02e89f72c30ae7f9e5a065701fdac9
[lyx.git] / development / Win32 / packaging / AltInstaller / InstallActions-update.nsh
1 # this file contains the main installer section
2
3 # The '-' makes the section invisible.
4 Section "-Installation actions" SecInstallation
5
6   # dummy actions to avoid NSIS warnings
7   StrCpy $AspellBaseReg ""
8   StrCpy $AspellMessage ""
9   StrCpy $DictCode ""
10   StrCpy $LangCode ""
11   StrCpy $LangCodeSys ""
12   StrCpy $LangName ""
13   StrCpy $LangNameSys ""
14   StrCpy $RunNumber ""
15   
16   # init, this variable is later only set to a value in function InstDirChange
17   # when the $INSTDIR is changed
18   StrCpy $INSTDIR_OLD ""
19   
20   # extract modified files
21   Call UpdateModifiedFiles # macro from Updated.nsh
22   
23   # delete files
24   Call DeleteFiles # macro from Deleted.nsh
25   
26   # delete old uninstaller
27   Delete "${PRODUCT_UNINSTALL_EXE}"
28   
29   # delete old start menu folder
30   ReadRegStr $0 SHCTX "${PRODUCT_UNINST_KEY_OLD}" "StartMenu"
31   RMDir /r $0
32   # delete desktop icon
33   Delete "$DESKTOP\${PRODUCT_VERSION_OLD}.lnk"
34   
35   # delete old registry entries
36   ${if} $CreateFileAssociations == "true"
37    DeleteRegKey SHCTX "${PRODUCT_DIR_REGKEY}"
38    # remove file extension .lyx
39    ReadRegStr $R0 SHCTX "Software\Classes\${PRODUCT_EXT}" ""
40    ${if} $R0 == "${PRODUCT_REGNAME}"
41     DeleteRegKey SHCTX "Software\Classes\${PRODUCT_EXT}"
42     DeleteRegKey SHCTX "Software\Classes\${PRODUCT_REGNAME}"
43    ${endif}
44   ${endif}
45   DeleteRegKey SHCTX "${PRODUCT_UNINST_KEY_OLD}"
46   DeleteRegKey HKCR "Applications\lyx.bat"
47   DeleteRegKey HKCR "${PRODUCT_NAME}"
48   
49   # determine the new name of the install location,
50   # Change the old install path to the new one (currently only when the user
51   # has used the default path settings of the previous LyX-version)
52   Call InstDirChange
53   
54   # Refresh registry setings for the uninstaller
55   Call RefreshRegUninst
56   
57   # register LyX
58   ${if} $CreateFileAssociations == "true"
59    WriteRegStr SHCTX "${PRODUCT_DIR_REGKEY}" "" "${PRODUCT_EXE}"
60   ${endif}
61   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "RootKey" "$ProductRootKey"
62   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "DisplayName" "LyX ${PRODUCT_VERSION}"
63   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "UninstallString" "${PRODUCT_UNINSTALL_EXE}"
64   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "DisplayIcon" "${PRODUCT_EXE}"
65   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
66   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "StartMenu" "$SMPROGRAMS\$StartmenuFolder"
67   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "URLUpdateInfo" "${PRODUCT_INFO_URL}"
68   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_ABOUT_URL}"
69   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "Publisher" "LyX Team"
70   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "HelpLink" "${PRODUCT_HELP_LINK}"
71   WriteRegDWORD SHCTX "${PRODUCT_UNINST_KEY}" "NoModify" 0x00000001
72   WriteRegDWORD SHCTX "${PRODUCT_UNINST_KEY}" "NoRepair" 0x00000001
73   
74   # create start menu entry
75   SetOutPath "$INSTDIR\bin"
76   CreateDirectory "$SMPROGRAMS\$StartmenuFolder"
77   CreateShortCut "$SMPROGRAMS\$StartmenuFolder\${PRODUCT_NAME}.lnk" "${PRODUCT_BAT}" "" "${PRODUCT_EXE}"
78   SetOutPath "$INSTDIR"
79   CreateShortCut "$SMPROGRAMS\$StartmenuFolder\Uninstall.lnk" "${PRODUCT_UNINSTALL_EXE}"
80   
81   # create desktop icon
82   ${if} $CreateDesktopIcon == "true"
83    SetOutPath "$INSTDIR\bin"
84    CreateShortCut "$DESKTOP\LyX ${PRODUCT_VERSION}.lnk" "${PRODUCT_BAT}" "" "${PRODUCT_EXE}"
85   ${endif}
86   
87   # register the extension .lyx
88   ${if} $CreateFileAssociations == "true"
89    # write informations about file type
90    WriteRegStr SHCTX "Software\Classes\${PRODUCT_REGNAME}" "" "${PRODUCT_NAME} Document"
91    WriteRegStr SHCTX "Software\Classes\${PRODUCT_REGNAME}\DefaultIcon" "" "${PRODUCT_EXE}"
92    WriteRegStr SHCTX "Software\Classes\${PRODUCT_REGNAME}\Shell\open\command" "" '"${PRODUCT_BAT}" "%1"'
93    # write informations about file extensions
94    WriteRegStr SHCTX "Software\Classes\${PRODUCT_EXT}" "" "${PRODUCT_REGNAME}"
95    WriteRegStr SHCTX "Software\Classes\${PRODUCT_EXT}" "Content Type" "${PRODUCT_MIME_TYPE}"  
96    # refresh shell
97    System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) (${SHCNE_ASSOCCHANGED}, ${SHCNF_IDLIST}, 0, 0)'
98   ${endif}
99   
100   # create Uninstaller
101   WriteUninstaller "${PRODUCT_UNINSTALL_EXE}"
102   
103   # test if Python is installed
104   # only use an existing python when it is version 2.5 because some Compaq and Dell PC are delivered
105   # with outdated Python interpreters
106   ReadRegStr $PythonPath HKLM "Software\Python\PythonCore\2.5\InstallPath" ""
107   ${if} $PythonPath == ""
108    StrCpy $PythonPath "$INSTDIR\bin"
109   ${else}
110    StrCpy $PythonPath $PythonPath -1 # remove the "\" at the end
111   ${endif}
112   
113   # run LyX's configure script
114   # create a bat-file to start configure in a console window so that the user see the progress
115   # of the configuration and to have a signal when the configuration is ready to start LyX
116   # this is important when LyX is installed together with MiKTeX or when LyX is installed for the first
117   # time on a computer, because the installation of missing LaTeX-files required by LyX could last minutes
118   # a batch file is needed because simply calling ExecWait '"$PythonPath\python.exe" "$INSTDIR\Resources\configure.py"'
119   # creates the config files in $INSTDIR\bin
120   StrCpy $1 $INSTDIR 2 # get drive letter
121   FileOpen $R1 "$INSTDIR\Resources\configLyX.bat" w
122   FileWrite $R1 '$1$\r$\n\
123                  cd $INSTDIR\Resources\$\r$\n\
124                  "$PythonPath\python.exe" configure.py'
125   FileClose $R1
126   MessageBox MB_OK|MB_ICONINFORMATION "$(LatexConfigInfo)"
127   ExecWait '"$INSTDIR\Resources\configLyX.bat"'
128   Delete "$INSTDIR\Resources\configLyX.bat"
129   
130   # there might be the case that python files need to be updated
131   # but this should only be done when Python is not installed
132   ReadRegStr $PythonPath HKLM "Software\Python\PythonCore\2.5\InstallPath" ""
133   ${if} $PythonPath == ""
134    ReadRegStr $PythonPath HKLM "Software\Python\PythonCore\2.6\InstallPath" ""
135   ${endif}
136   ${if} $PythonPath != ""
137    RMDir /r $INSTDIR\bin\Lib
138    RMDir /r $INSTDIR\bin\DLLs
139   ${endif}
140   
141   # for some unknown odd reason the folder $INSTDIR_OLD\Resources\ui
142   # is not deleted in function InstDirChange, so the deletion has to be called
143   # again to make it work
144   ${if} $INSTDIR_OLD != ""
145    RMDir /r $INSTDIR_OLD
146   ${endif}
147
148 SectionEnd
149
150 # -------------------------------------------
151
152 Function InstDirChange
153         
154   # determine the new name of the install location,
155   # Change the old install path to the new one (only when the user
156   # has used the default path settings of the previous LyX-version, otherwise leave the path as is)
157   StrCpy $String $INSTDIR
158   StrCpy $Search "${PRODUCT_VERSION_OLD}"
159   StrLen $3 $String
160   Call StrPoint # search the $INSTDIR for the phrase in ${PRODUCT_VERSION_OLD} ; function from LyXUtils.nsh
161   ${if} $Pointer != "-1" # if something was found
162   
163    IntOp $Pointer $Pointer - 1 # jump before the first "\" of "\${PRODUCT_VERSION_OLD}"
164    StrCpy $String $String "$Pointer" # $String is now the part before "\${PRODUCT_VERSION_OLD}"
165    # rename the installation folder by copying LyX files
166    StrCpy $INSTDIR_NEW "$String\LyX ${PRODUCT_VERSION}"
167    CreateDirectory "$INSTDIR_NEW"
168    CopyFiles "$INSTDIR\*.*" "$INSTDIR_NEW"
169    # delete the old folder
170    RMDir /r $INSTDIR
171    StrCpy $INSTDIR_OLD $INSTDIR
172    StrCpy $INSTDIR $INSTDIR_NEW
173    
174    # set new path_prefix in the file lyxrc.dist
175    StrCpy $OldString "${PRODUCT_VERSION_OLD}"
176    StrCpy $NewString "LyX ${PRODUCT_VERSION}"
177    # following macro from TextFunc.nsh # calls Function ReplaceLineContent from LyXUtils.nsh
178    ${LineFind} "$INSTDIR\Resources\lyxrc.dist" "" "1:-1" "ReplaceLineContent"
179    
180    # set the new path to the preferences file for all users
181    StrCpy $FileName "preferences"
182    StrCpy $OldString "${PRODUCT_VERSION_OLD}"
183    StrCpy $NewString "LyX ${PRODUCT_VERSION}"
184    Call CheckAppPathPreferences # function from LyXUtils.nsh
185    
186    # set the new path to the session file for all users
187    StrCpy $FileName "session"
188    Call CheckAppPathPreferences # function from LyXUtils.nsh
189    
190    # set the new path to the lyx.bat file
191    # following macro from TextFunc.nsh # calls Function ReplaceLineContent from LyXUtils.nsh
192    ${LineFind} "$INSTDIR\bin\lyx.bat" "" "1:-1" "ReplaceLineContent" 
193    
194    # set new path to ImageMagick
195    ReadRegStr $ImageMagickPath SHCTX "SOFTWARE\Classes\Applications" "AutoRun"
196    ${if} $ImageMagickPath != ""
197     ${WordReplace} $ImageMagickPath "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $ImageMagickPath # macro from WordFunc.nsh
198     WriteRegStr SHCTX "SOFTWARE\Classes\Applications" "AutoRun" "$ImageMagickPath"
199    ${endif}
200   
201   ${endif} # end ${if} $Pointer != "-1" (if the folder is renamed)
202   
203 FunctionEnd
204
205 # -------------------------------------------
206
207 Function RefreshRegUninst
208
209   # Refresh registry setings for the uninstaller
210
211   # Aspell
212   ReadRegStr $0 SHCTX "Software\Aspell" "OnlyWithLyX" # special entry to test if it was installed with LyX
213   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
214    WriteRegStr HKLM "SOFTWARE\Aspell" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
215   ${endif}
216   
217   # eLyXer
218   # first test if Python is installed
219   ReadRegStr $PythonPath HKLM "Software\Python\PythonCore\2.5\InstallPath" ""
220   ${if} $PythonPath == ""
221    ReadRegStr $PythonPath HKLM "Software\Python\PythonCore\2.6\InstallPath" ""
222   ${endif}
223   ${if} $PythonPath == ""
224    ReadRegStr $PythonPath HKLM "Software\Python\PythonCore\3.0\InstallPath" ""
225   ${endif}
226   ${if} $PythonPath == ""
227    ReadRegStr $PythonPath HKLM "Software\Python\PythonCore\3.1\InstallPath" ""
228   ${endif}
229   ${if} $PythonPath != ""
230    StrCpy $PythonPath $PythonPath -1 # remove the "\" at the end
231   ${endif}
232   # now install eLyXer as Python module
233   ${if} $PythonPath != ""
234    # a Python module cannot simply started with
235    # ExecWait '$PythonPath\python.exe "$INSTDIR\bin\setup.py" install'
236    # therefore run a script
237    StrCpy $1 $INSTDIR 2 # get drive letter
238    FileOpen $R1 "$INSTDIR\bin\eLyXer.bat" w
239    FileWrite $R1 '$1$\r$\n\
240                   cd "$INSTDIR\bin"$\r$\n\
241                   "$PythonPath\python.exe" setup.py install'
242    FileClose $R1
243    ExecWait '"$INSTDIR\bin\eLyXer.bat"'
244    Delete "$INSTDIR\bin\eLyXer.bat"
245   ${else}
246    ExecWait '"$INSTDIR\bin\python.exe" "$INSTDIR\bin\setup.py" install'
247   ${endif}
248   
249   # Metafile2eps
250   Var /GLOBAL RegLocation
251   StrCpy $RegLocation "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Metafile to EPS Converter"
252   ReadRegStr $0 SHCTX "$RegLocation" "OnlyWithLyX"
253   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
254    WriteRegStr HKLM "$RegLocation" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
255    # set the new path
256    ReadRegStr $0 HKLM "SOFTWARE\InkNote Selector" ""
257    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0 # macro from WordFunc.nsh
258    WriteRegStr HKLM "SOFTWARE\InkNote Selector" "" "$0"
259    ReadRegStr $0 HKLM "$RegLocation" "InstallLocation"
260    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
261    WriteRegStr HKLM "$RegLocation" "InstallLocation" "$0"
262   ${endif}
263   
264   # MiKTeX
265   ReadRegStr $0 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX"
266   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
267    WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
268   ${endif}
269   
270   # JabRef
271   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX"
272   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
273    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
274   ${endif}
275   
276   # Aiksaurus currently not needed
277   #ReadRegStr $0 SHCTX "Software\Aiksaurus" "OnlyWithLyX"
278   #${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
279   # WriteRegStr HKLM "SOFTWARE\Aiksaurus" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
280   #${endif}
281   
282   # ImageMagick
283   ReadRegStr $0 SHCTX "Software\ImageMagick" "OnlyWithLyX"
284   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
285    WriteRegStr HKLM "SOFTWARE\ImageMagick" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
286    # set the new path
287    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "BinPath"
288    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0 # macro from WordFunc.nsh
289    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "BinPath" "$0"
290    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "CoderModulesPath"
291    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
292    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "CoderModulesPath" "$0"
293    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "ConfigurePath"
294    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
295    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "ConfigurePath" "$0"
296    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "FilterModulesPath"
297    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
298    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "FilterModulesPath" "$0"
299    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "LibPath"
300    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
301    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "LibPath" "$0"
302    # set the new path
303    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "BinPath"
304    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
305    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "BinPath" "$0"
306    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "CoderModulesPath"
307    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
308    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "CoderModulesPath" "$0"
309    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "ConfigurePath"
310    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
311    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "ConfigurePath" "$0"
312    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "FilterModulesPath"
313    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
314    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "FilterModulesPath" "$0"
315    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "LibPath"
316    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
317    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "LibPath" "$0"
318   ${endif}
319   
320   # Ghostscript and GSview
321   ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX"
322   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
323    WriteRegStr HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
324    # set the new path
325    ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript\${GhostscriptVersion_Old}" "GS_DLL"
326    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
327    WriteRegStr HKLM "SOFTWARE\GPL Ghostscript\${GhostscriptVersion_Old}" "GS_DLL" "$0"
328    ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript\${GhostscriptVersion_Old}" "GS_LIB"
329    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
330    WriteRegStr HKLM "SOFTWARE\GPL Ghostscript\${GhostscriptVersion_Old}" "GS_LIB" "$0"
331   ${endif}
332
333 FunctionEnd