]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/AltInstaller/InstallActions-update.nsh
installer: sync with 1.5.X branch
[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   # for some unknown odd reason the folder $INSTDIR_OLD\Resources\ui
131   # is not deleted in function InstDirChange, so the deletion has to be called
132   # again to make it work
133   ${if} $INSTDIR_OLD != ""
134    RMDir /r $INSTDIR_OLD
135   ${endif}
136
137 SectionEnd
138
139 # -------------------------------------------
140
141 Function InstDirChange
142         
143   # determine the new name of the install location,
144   # Change the old install path to the new one (currently only when the user
145   # has used the default path settings of the previous LyX-version)
146   StrCpy $String $INSTDIR
147   StrCpy $Search "${PRODUCT_VERSION_OLD}"
148   StrLen $3 $String
149   Call StrPoint # search the $INSTDIR for the phrase in ${PRODUCT_VERSION_OLD} ; function from LyXUtils.nsh
150   ${if} $Pointer != "-1" # if something was found
151   
152    IntOp $Pointer $Pointer - 1 # jump before the first "\" of "\${PRODUCT_VERSION_OLD}"
153    StrCpy $String $String "$Pointer" # $String is now the part before "\${PRODUCT_VERSION_OLD}"
154    # rename the installation folder by copying LyX files
155    StrCpy $INSTDIR_NEW "$String\LyX ${PRODUCT_VERSION}"
156    CreateDirectory "$INSTDIR_NEW"
157    CopyFiles "$INSTDIR\*.*" "$INSTDIR_NEW"
158    # delete the old folder
159    RMDir /r $INSTDIR
160    StrCpy $INSTDIR_OLD $INSTDIR
161    StrCpy $INSTDIR $INSTDIR_NEW
162    
163    # set new PATH_PREFIX in the file lyxrc.dist
164    FileOpen $R1 "$INSTDIR\Resources\lyxrc.dist" a
165    FileRead $R1 $PathPrefix # the whole file content is now in $PathPrefix
166    ${WordReplace} $PathPrefix "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $PathPrefix
167    FileSeek $R1 0 # set file pointer to the beginning
168    FileWrite $R1 '$PathPrefix' # overwrite the existing path with the actual one
169    FileClose $R1
170    
171    # set the new path to the preferences file for all users
172    StrCpy $FileName "preferences"
173    StrCpy $OldString "${PRODUCT_VERSION_OLD}"
174    StrCpy $NewString "LyX ${PRODUCT_VERSION}"
175    Call CheckAppPathPreferences # function from LyXUtils.nsh
176    
177    # set the new path to the session file for all users
178    StrCpy $FileName "session"
179    Call CheckAppPathPreferences # function from LyXUtils.nsh
180    
181    # set the new path to the lyx.bat file
182    # following macro from TextFunc.nsh # calls Function ReplaceLineContent from LyXUtils.nsh
183    ${LineFind} "$INSTDIR\bin\lyx.bat" "" "1:-1" "ReplaceLineContent" 
184    
185    # set new path to ImageMagick
186    ReadRegStr $ImageMagickPath SHCTX "SOFTWARE\Classes\Applications" "AutoRun"
187    ${if} $ImageMagickPath != ""
188     ${WordReplace} $ImageMagickPath "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $ImageMagickPath # macro from WordFunc.nsh
189     WriteRegStr SHCTX "SOFTWARE\Classes\Applications" "AutoRun" "$ImageMagickPath"
190    ${endif}
191   
192   ${endif} # end ${if} $Pointer != "-1" (if the folder is renamed)
193   
194 FunctionEnd
195
196 # -------------------------------------------
197
198 Function RefreshRegUninst
199
200   # Refresh registry setings for the uninstaller
201
202   # Aspell
203   ReadRegStr $0 SHCTX "Software\Aspell" "OnlyWithLyX" # special entry to test if it was installed with LyX
204   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
205    WriteRegStr HKLM "SOFTWARE\Aspell" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
206   ${endif}
207   
208   # MiKTeX
209   ReadRegStr $0 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX"
210   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
211    WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
212   ${endif}
213   
214   # JabRef
215   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX"
216   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
217    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
218   ${endif}
219   
220   # Aiksaurus
221   ReadRegStr $0 SHCTX "Software\Aiksaurus" "OnlyWithLyX" # special entry to test if it was installed with LyX
222   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
223    WriteRegStr HKLM "SOFTWARE\Aiksaurus" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
224   ${endif}
225   
226   # ImageMagick
227   ReadRegStr $0 SHCTX "Software\ImageMagick" "OnlyWithLyX"
228   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
229    # set the new path
230    WriteRegStr HKLM "SOFTWARE\ImageMagick" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
231    ReadRegStr $0 HKLM "Software\ImageMagick\Current" "BinPath"
232    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0 # macro from WordFunc.nsh
233    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "BinPath" "$0"
234    ReadRegStr $0 HKLM "Software\ImageMagick\Current" "CoderModulesPath"
235    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
236    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "CoderModulesPath" "$0"
237    ReadRegStr $0 HKLM "Software\ImageMagick\Current" "ConfigurePath"
238    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
239    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "ConfigurePath" "$0"
240    ReadRegStr $0 HKLM "Software\ImageMagick\Current" "FilterModulesPath"
241    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
242    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "FilterModulesPath" "$0"
243    ReadRegStr $0 HKLM "Software\ImageMagick\Current" "LibPath"
244    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
245    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "LibPath" "$0"
246    WriteRegStr HKLM "SOFTWARE\ImageMagick\Current" "Version" "${ImageMagickVersion}"
247    
248    ${COPY_REGISTRY_KEY} HKLM "Software\ImageMagick\${ImageMagickVersion_Old}" \
249                         HKLM "Software\ImageMagick\${ImageMagickVersion}" # macro from registry.nsh
250    DeleteRegKey HKLM "Software\ImageMagick\${ImageMagickVersion_Old}"
251    # set the new path
252    ReadRegStr $0 HKLM "Software\ImageMagick\${ImageMagickVersion}\Q:16" "BinPath"
253    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
254    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "BinPath" "$0"
255    ReadRegStr $0 HKLM "Software\ImageMagick\${ImageMagickVersion}\Q:16" "CoderModulesPath"
256    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}\Q:16" "+" $0
257    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "CoderModulesPath" "$0"
258    ReadRegStr $0 HKLM "Software\ImageMagick\${ImageMagickVersion}\Q:16" "ConfigurePath"
259    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
260    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "ConfigurePath" "$0"
261    ReadRegStr $0 HKLM "Software\ImageMagick\${ImageMagickVersion}\Q:16" "FilterModulesPath"
262    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
263    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "FilterModulesPath" "$0"
264    ReadRegStr $0 HKLM "Software\ImageMagick\${ImageMagickVersion}\Q:16" "LibPath"
265    ${WordReplace} $0 "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $0
266    WriteRegStr HKLM "SOFTWARE\ImageMagick\${ImageMagickVersion}\Q:16" "LibPath" "$0"
267   ${endif}
268   
269   # Ghostscript and GSview
270   ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX"
271   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
272    WriteRegStr HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
273   ${endif}
274
275 FunctionEnd