installer: sync with branch
[lyx.git] / development / Win32 / packaging / AltInstaller / InstallActions-update.nsh
blob846711e246ce6a94aba1d942151d1a156d9ff625
1 # this file contains the main installer section
3 # The '-' makes the section invisible.
4 Section "-Installation actions" SecInstallation
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}
148 SectionEnd
150 # -------------------------------------------
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
205 # -------------------------------------------
207 Function RefreshRegUninst
209   # Refresh registry setings for the uninstaller
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   # install eLyXer as Python module
218   Call eLyXer # function from InstallThirdPartyProgs.nsh
219   
220   # Metafile2eps
221   Var /GLOBAL RegLocation
222   StrCpy $RegLocation "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Metafile to EPS Converter"
223   ReadRegStr $0 SHCTX "$RegLocation" "OnlyWithLyX"
224   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
225    WriteRegStr HKLM "$RegLocation" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
226    # set the new path
227    ReadRegStr $0 HKLM "SOFTWARE\InkNote Selector" ""
228    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0 # macro from WordFunc.nsh
229    WriteRegStr HKLM "SOFTWARE\InkNote Selector" "" "$0"
230    ReadRegStr $0 HKLM "$RegLocation" "InstallLocation"
231    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
232    WriteRegStr HKLM "$RegLocation" "InstallLocation" "$0"
233   ${endif}
234   
235   # MiKTeX
236   ReadRegStr $0 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX"
237   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
238    WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
239   ${endif}
240   
241   # JabRef
242   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX"
243   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
244    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
245   ${endif}
246   
247   # Aiksaurus currently not needed
248   #ReadRegStr $0 SHCTX "Software\Aiksaurus" "OnlyWithLyX"
249   #${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
250   # WriteRegStr HKLM "SOFTWARE\Aiksaurus" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
251   #${endif}
252   
253   # ImageMagick
254   ReadRegStr $0 SHCTX "Software\ImageMagick" "OnlyWithLyX"
255   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
256    WriteRegStr HKLM "SOFTWARE\ImageMagick" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
257    # set the new path
258    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "BinPath"
259    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0 # macro from WordFunc.nsh
260    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "BinPath" "$0"
261    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "CoderModulesPath"
262    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
263    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "CoderModulesPath" "$0"
264    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "ConfigurePath"
265    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
266    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "ConfigurePath" "$0"
267    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "FilterModulesPath"
268    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
269    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "FilterModulesPath" "$0"
270    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\Current" "LibPath"
271    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
272    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "LibPath" "$0"
273    # set the new path
274    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "BinPath"
275    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
276    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "BinPath" "$0"
277    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "CoderModulesPath"
278    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
279    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "CoderModulesPath" "$0"
280    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "ConfigurePath"
281    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
282    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "ConfigurePath" "$0"
283    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "FilterModulesPath"
284    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
285    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "FilterModulesPath" "$0"
286    ReadRegStr $0 HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "LibPath"
287    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
288    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion_Old}\Q:16" "LibPath" "$0"
289   ${endif}
290   
291   # Ghostscript and GSview
292   ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX"
293   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
294    WriteRegStr HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
295    # set the new path
296    ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript\${GhostscriptVersion_Old}" "GS_DLL"
297    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
298    WriteRegStr HKLM "SOFTWARE\GPL Ghostscript\${GhostscriptVersion_Old}" "GS_DLL" "$0"
299    ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript\${GhostscriptVersion_Old}" "GS_LIB"
300    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
301    WriteRegStr HKLM "SOFTWARE\GPL Ghostscript\${GhostscriptVersion_Old}" "GS_LIB" "$0"
302   ${endif}
304 FunctionEnd