]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/installer/LyXWinInstaller/InstallActions-update.nsh
Changed comment character from ';' to '#*
[lyx.git] / development / Win32 / packaging / installer / LyXWinInstaller / 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 $LangCode ""
9   StrCpy $LangCodeSys ""
10   StrCpy $LangName ""
11   StrCpy $LangNameSys ""
12   
13   # init, this variable is later only set to a value in function InstDirChange
14   # when the $INSTDIR is changed
15   StrCpy $INSTDIR_OLD ""
16   
17   # extract modified files
18   Call UpdateModifiedFiles # macro from Updated.nsh
19   
20   # delete files
21   Call DeleteFiles # macro from Deleted.nsh
22   
23   # delete old uninstaller
24   Delete "${PRODUCT_UNINSTALL_EXE}"
25   
26   # delete old start menu folder
27   ReadRegStr $0 SHCTX "${PRODUCT_UNINST_KEY_OLD}" "StartMenu"
28   RMDir /r $0
29   # delete desktop icon
30   Delete "$DESKTOP\${PRODUCT_VERSION_OLD}.lnk"
31   
32   # delete old registry entries
33   ${if} $CreateFileAssociations == "true"
34    DeleteRegKey SHCTX "${PRODUCT_DIR_REGKEY}"
35    # remove file extension .lyx
36    ReadRegStr $R0 SHCTX "Software\Classes\${PRODUCT_EXT}" ""
37    ${if} $R0 == "${PRODUCT_REGNAME}"
38     DeleteRegKey SHCTX "Software\Classes\${PRODUCT_EXT}"
39     DeleteRegKey SHCTX "Software\Classes\${PRODUCT_REGNAME}"
40    ${endif}
41   ${endif}
42   DeleteRegKey SHCTX "${PRODUCT_UNINST_KEY_OLD}"
43   DeleteRegKey HKCR "Applications\lyx.bat"
44   DeleteRegKey HKCR "${PRODUCT_NAME}"
45   
46   # determine the new name of the install location,
47   # Change the old install path to the new one (currently only when the user
48   # has used the default path settings of the previous LyX-version)
49   Call InstDirChange
50   
51   # Refresh registry setings for the uninstaller
52   Call RefreshRegUninst
53   
54   # Create a batch file to start LyX with the environment variables set
55   # !only needed in this version! remove it for the next release
56   ClearErrors
57   Delete "${PRODUCT_BAT}"
58   FileOpen $R1 "${PRODUCT_BAT}" w
59   FileWrite $R1 '@echo off$\r$\n\
60                  SET LANG=$LangCode$\r$\n\
61                  SET AIK_DATA_DIR=${AiksaurusDir}$\r$\n\
62                  start "${PRODUCT_NAME}" "${LAUNCHER_NAME}" %*$\r$\n'
63   FileClose $R1
64   IfErrors 0 +2
65    MessageBox MB_OK|MB_ICONEXCLAMATION "$(CreateCmdFilesFailed)"
66   
67   # register LyX
68   ${if} $CreateFileAssociations == "true"
69    WriteRegStr SHCTX "${PRODUCT_DIR_REGKEY}" "" "${PRODUCT_EXE}"
70   ${endif}
71   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "RootKey" "$ProductRootKey"
72   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "DisplayName" "LyX ${PRODUCT_VERSION}"
73   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "UninstallString" "${PRODUCT_UNINSTALL_EXE}"
74   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "DisplayIcon" "${PRODUCT_EXE}"
75   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
76   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "StartMenu" "$SMPROGRAMS\$StartmenuFolder"
77   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "URLUpdateInfo" "${PRODUCT_INFO_URL}"
78   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_ABOUT_URL}"
79   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "Publisher" "LyX Team"
80   WriteRegStr SHCTX "${PRODUCT_UNINST_KEY}" "HelpLink" "${PRODUCT_HELP_LINK}"
81   WriteRegDWORD SHCTX "${PRODUCT_UNINST_KEY}" "NoModify" 0x00000001
82   WriteRegDWORD SHCTX "${PRODUCT_UNINST_KEY}" "NoRepair" 0x00000001
83   
84   # create start menu entry
85   SetOutPath "$INSTDIR\bin"
86   CreateDirectory "$SMPROGRAMS\$StartmenuFolder"
87   CreateShortCut "$SMPROGRAMS\$StartmenuFolder\${PRODUCT_NAME}.lnk" "${PRODUCT_BAT}" "" "${PRODUCT_EXE}"
88   SetOutPath "$INSTDIR"
89   CreateShortCut "$SMPROGRAMS\$StartmenuFolder\Uninstall.lnk" "${PRODUCT_UNINSTALL_EXE}"
90   
91   # create desktop icon
92   ${if} $CreateDesktopIcon == "true"
93    SetOutPath "$INSTDIR\bin"
94    CreateShortCut "$DESKTOP\LyX ${PRODUCT_VERSION}.lnk" "${PRODUCT_BAT}" "" "${PRODUCT_EXE}"
95   ${endif}
96   
97   # register the extension .lyx
98   ${if} $CreateFileAssociations == "true"
99    # write informations about file type
100    WriteRegStr SHCTX "Software\Classes\${PRODUCT_REGNAME}" "" "${PRODUCT_NAME} Document"
101    WriteRegStr SHCTX "Software\Classes\${PRODUCT_REGNAME}\DefaultIcon" "" "${PRODUCT_EXE}"
102    WriteRegStr SHCTX "Software\Classes\${PRODUCT_REGNAME}\Shell\open\command" "" '"${LAUNCHER_EXE}" "%1"'
103    # write informations about file extensions
104    WriteRegStr SHCTX "Software\Classes\${PRODUCT_EXT}" "" "${PRODUCT_REGNAME}"
105    WriteRegStr SHCTX "Software\Classes\${PRODUCT_EXT}" "Content Type" "${PRODUCT_MIME_TYPE}"  
106    # refresh shell
107    System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) (${SHCNE_ASSOCCHANGED}, ${SHCNF_IDLIST}, 0, 0)'
108   ${endif}
109   
110   # create Uninstaller
111   WriteUninstaller "${PRODUCT_UNINSTALL_EXE}"
112   
113   # test if Python is installed
114   # only use an existing python when it is version 2.5 because many Compaq and Dell PC are delivered
115   # with outdated Python interpreters
116   ReadRegStr $PythonPath HKLM "Software\Python\PythonCore\2.5\InstallPath" ""
117   ${if} $PythonPath == ""
118    StrCpy $PythonPath "$INSTDIR\bin"
119   ${else}
120    StrCpy $PythonPath $PythonPath -1 # remove the "\" at the end
121   ${endif}
122   
123   # run LyX's configure script
124   # create a bat-file to start configure in a console window so that the user see the progress
125   # of the configuration and to have a signal when the configuration is ready to start LyX
126   # this is important when LyX is installed together with MiKTeX or when LyX is installed for the first
127   # time on a computer, because the installation of missing LaTeX-files required by LyX could last minutes
128   # a batch file is needed because simply calling ExecWait '"$PythonPath\python.exe" "$INSTDIR\Resources\configure.py"'
129   # creates the config files in $INSTDIR\bin
130   StrCpy $1 $INSTDIR 2 # get drive letter
131   FileOpen $R1 "$INSTDIR\Resources\configLyX.bat" w
132   FileWrite $R1 '$1$\r$\n\
133                  cd $INSTDIR\Resources\$\r$\n\
134                  "$PythonPath\python.exe" configure.py'
135   FileClose $R1
136   MessageBox MB_OK|MB_ICONINFORMATION "$(LatexConfigInfo)"
137   ExecWait '"$INSTDIR\Resources\configLyX.bat"'
138   Delete "$INSTDIR\Resources\configLyX.bat"
139   
140   # for some unknown odd reason the folder $INSTDIR_OLD\Resources\ui
141   # is not deleted in function InstDirChange, so the deletion has to be called
142   # again to make it work
143   ${if} $INSTDIR_OLD != ""
144    RMDir /r $INSTDIR_OLD
145   ${endif}
146
147 SectionEnd
148
149 # -------------------------------------------
150
151 Function InstDirChange
152         
153   # determine the new name of the install location,
154   # Change the old install path to the new one (currently only when the user
155   # has used the default path settings of the previous LyX-version)
156   StrCpy $String $INSTDIR
157   StrCpy $Search "${PRODUCT_VERSION_OLD}"
158   StrLen $3 $String
159   Call StrPoint # search the $INSTDIR for the phrase in ${PRODUCT_VERSION_OLD} ; function from LyXUtils.nsh
160   ${if} $Pointer != "-1" # if something was found
161   
162    IntOp $Pointer $Pointer - 1 # jump before the first "\" of "\${PRODUCT_VERSION_OLD}"
163    StrCpy $String $String "$Pointer" # $String is now the part before "\${PRODUCT_VERSION_OLD}"
164    # rename the installation folder by copying LyX files
165    StrCpy $INSTDIR_NEW "$String\LyX ${PRODUCT_VERSION}"
166    CreateDirectory "$INSTDIR_NEW"
167    CopyFiles "$INSTDIR\*.*" "$INSTDIR_NEW"
168    # delete the old folder
169    RMDir /r $INSTDIR
170    StrCpy $INSTDIR_OLD $INSTDIR
171    StrCpy $INSTDIR $INSTDIR_NEW
172    
173    # set new PATH_PREFIX in the file lyxrc.dist
174    FileOpen $R1 "$INSTDIR\Resources\lyxrc.dist" a
175    FileRead $R1 $PathPrefix
176    ${WordReplace} $PathPrefix "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $PathPrefix
177    FileSeek $R1 0 # set file pointer to the beginning
178    FileWrite $R1 '$PathPrefix' # overwrite the existing path with the actual one
179    FileClose $R1
180    
181    # set the new path to the preferences file for all users
182    StrCpy $FileName "preferences"
183    StrCpy $OldString "${PRODUCT_VERSION_OLD}"
184    StrCpy $NewString "LyX ${PRODUCT_VERSION}"
185    Call CheckAppPathPreferences # function from LyXUtils.nsh
186    
187    # set the new path to the session file for all users
188    StrCpy $FileName "session"
189    Call CheckAppPathPreferences # function from LyXUtils.nsh
190    
191    # set new path to ImageMagick
192    ReadRegStr $ImageMagickPath SHCTX "SOFTWARE\Classes\Applications" "AutoRun"
193    ${if} $ImageMagickPath != ""
194     ${WordReplace} $ImageMagickPath "${PRODUCT_VERSION_OLD}" "LyX ${PRODUCT_VERSION}" "+" $ImageMagickPath # macro from WordFunc.nsh
195     WriteRegStr SHCTX "SOFTWARE\Classes\Applications" "AutoRun" "$ImageMagickPath"
196    ${endif}
197   
198   ${endif} # end ${if} $Pointer != "-1" (if the folder is renamed)
199   
200 FunctionEnd
201
202 # -------------------------------------------
203
204 Function RefreshRegUninst
205
206   # Refresh registry setings for the uninstaller
207
208   # Aspell
209   ReadRegStr $0 SHCTX "Software\Aspell" "OnlyWithLyX" # special entry to test if it was installed with LyX
210   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
211    WriteRegStr HKLM "SOFTWARE\Aspell" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
212   ${endif}
213   
214   # MiKTeX
215   ReadRegStr $0 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX"
216   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
217    WriteRegStr HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
218    StrCpy $MiKTeXVersionVar ${MiKTeXDeliveredVersionOld}
219   ${endif}
220   
221   # JabRef
222   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${JabRefVersionOld}" "OnlyWithLyX"
223   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
224    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${JabRefVersionOld}" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
225    StrCpy $JabRefVersionVar ${JabRefVersionOld}
226   ${endif}
227   
228   # Aiksaurus
229   ReadRegStr $0 SHCTX "Software\Aiksaurus" "OnlyWithLyX" # special entry to test if it was installed with LyX
230   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
231    WriteRegStr HKLM "SOFTWARE\Aiksaurus" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
232   ${endif}
233   
234   # ImageMagick
235   ReadRegStr $0 SHCTX "Software\ImageMagick" "OnlyWithLyX"
236   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
237    WriteRegStr HKLM "SOFTWARE\ImageMagick" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
238   ${endif}
239   
240   # Ghostscript and GSview
241   ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX"
242   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT_OLD}"
243    WriteRegStr HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX" "Yes${PRODUCT_VERSION_SHORT}"
244   ${endif}
245
246 FunctionEnd