1# NSIS file to create a self-installing exe for Vim. 2# It requires NSIS version 2.0 or later. 3# Last Change: 2010 Jul 30 4 5# WARNING: if you make changes to this script, look out for $0 to be valid, 6# because uninstall deletes most files in $0. 7 8# Location of gvim_ole.exe, vimd32.exe, GvimExt/*, etc. 9!define VIMSRC "..\src" 10 11# Location of runtime files 12!define VIMRT ".." 13 14# Location of extra tools: diff.exe 15!define VIMTOOLS ..\.. 16 17# Comment the next line if you don't have UPX. 18# Get it at http://upx.sourceforge.net 19!define HAVE_UPX 20 21# comment the next line if you do not want to add Native Language Support 22!define HAVE_NLS 23 24!define VER_MAJOR 7 25!define VER_MINOR 3 26 27# ----------- No configurable settings below this line ----------- 28 29!include UpgradeDLL.nsh # for VisVim.dll 30!include LogicLib.nsh 31!include x64.nsh 32 33Name "Vim ${VER_MAJOR}.${VER_MINOR}" 34OutFile gvim${VER_MAJOR}${VER_MINOR}.exe 35CRCCheck force 36SetCompressor lzma 37SetDatablockOptimize on 38RequestExecutionLevel highest 39 40ComponentText "This will install Vim ${VER_MAJOR}.${VER_MINOR} on your computer." 41DirText "Choose a directory to install Vim (must end in 'vim')" 42Icon icons\vim_16c.ico 43# NSIS2 uses a different strategy with six diferent images in a strip... 44#EnabledBitmap icons\enabled.bmp 45#DisabledBitmap icons\disabled.bmp 46UninstallText "This will uninstall Vim ${VER_MAJOR}.${VER_MINOR} from your system." 47UninstallIcon icons\vim_uninst_16c.ico 48 49# On NSIS 2 using the BGGradient causes trouble on Windows 98, in combination 50# with the BringToFront. 51# BGGradient 004000 008200 FFFFFF 52LicenseText "You should read the following before installing:" 53LicenseData ${VIMRT}\doc\uganda.nsis.txt 54 55!ifdef HAVE_UPX 56 !packhdr temp.dat "upx --best --compress-icons=1 temp.dat" 57!endif 58 59# This adds '\vim' to the user choice automagically. The actual value is 60# obtained below with ReadINIStr. 61InstallDir "$PROGRAMFILES\Vim" 62 63# Types of installs we can perform: 64InstType Typical 65InstType Minimal 66InstType Full 67 68SilentInstall normal 69 70# These are the pages we use 71Page license 72Page components 73Page directory "" "" CheckInstallDir 74Page instfiles 75UninstPage uninstConfirm 76UninstPage instfiles 77 78########################################################## 79# Functions 80 81Function .onInit 82 MessageBox MB_YESNO|MB_ICONQUESTION \ 83 "This will install Vim ${VER_MAJOR}.${VER_MINOR} on your computer.$\n Continue?" \ 84 IDYES NoAbort 85 Abort ; causes installer to quit. 86 NoAbort: 87 88 # run the install program to check for already installed versions 89 SetOutPath $TEMP 90 File /oname=install.exe ${VIMSRC}\installw32.exe 91 ExecWait "$TEMP\install.exe -uninstall-check" 92 Delete $TEMP\install.exe 93 94 # We may have been put to the background when uninstall did something. 95 BringToFront 96 97 # Install will have created a file for us that contains the directory where 98 # we should install. This is $VIM if it's set. This appears to be the only 99 # way to get the value of $VIM here!? 100 ReadINIStr $INSTDIR $TEMP\vimini.ini vimini dir 101 Delete $TEMP\vimini.ini 102 103 # If ReadINIStr failed or did not find a path: use the default dir. 104 StrCmp $INSTDIR "" 0 IniOK 105 StrCpy $INSTDIR "$PROGRAMFILES\Vim" 106 IniOK: 107 108 # Should check for the value of $VIM and use it. Unfortunately I don't know 109 # how to obtain the value of $VIM 110 # IfFileExists "$VIM" 0 No_Vim 111 # StrCpy $INSTDIR "$VIM" 112 # No_Vim: 113 114 # User variables: 115 # $0 - holds the directory the executables are installed to 116 # $1 - holds the parameters to be passed to install.exe. Starts with OLE 117 # registration (since a non-OLE gvim will not complain, and we want to 118 # always register an OLE gvim). 119 # $2 - holds the names to create batch files for 120 StrCpy $0 "$INSTDIR\vim${VER_MAJOR}${VER_MINOR}" 121 StrCpy $1 "-register-OLE" 122 StrCpy $2 "gvim evim gview gvimdiff vimtutor" 123 124FunctionEnd 125 126Function .onUserAbort 127 MessageBox MB_YESNO|MB_ICONQUESTION "Abort install?" IDYES NoCancelAbort 128 Abort ; causes installer to not quit. 129 NoCancelAbort: 130FunctionEnd 131 132# We only accept the directory if it ends in "vim". Using .onVerifyInstDir has 133# the disadvantage that the browse dialog is difficult to use. 134Function CheckInstallDir 135 StrCpy $0 $INSTDIR 3 -3 136 StrCmp $0 "vim" PathGood 137 MessageBox MB_OK "The path must end in 'vim'." 138 Abort 139 PathGood: 140FunctionEnd 141 142Function .onInstSuccess 143 WriteUninstaller vim${VER_MAJOR}${VER_MINOR}\uninstall-gui.exe 144 MessageBox MB_YESNO|MB_ICONQUESTION \ 145 "The installation process has been successful. Happy Vimming! \ 146 $\n$\n Do you want to see the README file now?" IDNO NoReadme 147 Exec '$0\gvim.exe -R "$0\README.txt"' 148 NoReadme: 149FunctionEnd 150 151Function .onInstFailed 152 MessageBox MB_OK|MB_ICONEXCLAMATION "Installation failed. Better luck next time." 153FunctionEnd 154 155Function un.onUnInstSuccess 156 MessageBox MB_OK|MB_ICONINFORMATION \ 157 "Vim ${VER_MAJOR}.${VER_MINOR} has been (partly) removed from your system" 158FunctionEnd 159 160Function un.GetParent 161 Exch $0 ; old $0 is on top of stack 162 Push $1 163 Push $2 164 StrCpy $1 -1 165 loop: 166 StrCpy $2 $0 1 $1 167 StrCmp $2 "" exit 168 StrCmp $2 "\" exit 169 IntOp $1 $1 - 1 170 Goto loop 171 exit: 172 StrCpy $0 $0 $1 173 Pop $2 174 Pop $1 175 Exch $0 ; put $0 on top of stack, restore $0 to original value 176FunctionEnd 177 178########################################################## 179Section "Vim executables and runtime files" 180 SectionIn 1 2 3 181 182 # we need also this here if the user changes the instdir 183 StrCpy $0 "$INSTDIR\vim${VER_MAJOR}${VER_MINOR}" 184 185 SetOutPath $0 186 File /oname=gvim.exe ${VIMSRC}\gvim_ole.exe 187 File /oname=install.exe ${VIMSRC}\installw32.exe 188 File /oname=uninstal.exe ${VIMSRC}\uninstalw32.exe 189 File ${VIMSRC}\vimrun.exe 190 File /oname=xxd.exe ${VIMSRC}\xxdw32.exe 191 File ${VIMTOOLS}\diff.exe 192 File ${VIMRT}\vimtutor.bat 193 File ${VIMRT}\README.txt 194 File ..\uninstal.txt 195 File ${VIMRT}\*.vim 196 File ${VIMRT}\rgb.txt 197 198 SetOutPath $0\colors 199 File ${VIMRT}\colors\*.* 200 201 SetOutPath $0\compiler 202 File ${VIMRT}\compiler\*.* 203 204 SetOutPath $0\doc 205 File ${VIMRT}\doc\*.txt 206 File ${VIMRT}\doc\tags 207 208 SetOutPath $0\ftplugin 209 File ${VIMRT}\ftplugin\*.* 210 211 SetOutPath $0\indent 212 File ${VIMRT}\indent\*.* 213 214 SetOutPath $0\macros 215 File ${VIMRT}\macros\*.* 216 217 SetOutPath $0\plugin 218 File ${VIMRT}\plugin\*.* 219 220 SetOutPath $0\autoload 221 File ${VIMRT}\autoload\*.* 222 223 SetOutPath $0\autoload\xml 224 File ${VIMRT}\autoload\xml\*.* 225 226 SetOutPath $0\syntax 227 File ${VIMRT}\syntax\*.* 228 229 SetOutPath $0\spell 230 File ${VIMRT}\spell\*.txt 231 File ${VIMRT}\spell\*.vim 232 File ${VIMRT}\spell\*.spl 233 File ${VIMRT}\spell\*.sug 234 235 SetOutPath $0\tools 236 File ${VIMRT}\tools\*.* 237 238 SetOutPath $0\tutor 239 File ${VIMRT}\tutor\*.* 240SectionEnd 241 242########################################################## 243Section "Vim console program (vim.exe)" 244 SectionIn 1 3 245 246 SetOutPath $0 247 ReadRegStr $R0 HKLM \ 248 "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion 249 IfErrors 0 lbl_winnt 250 # Windows 95/98/ME 251 File /oname=vim.exe ${VIMSRC}\vimd32.exe 252 Goto lbl_done 253 lbl_winnt: 254 # Windows NT/2000/XT 255 File /oname=vim.exe ${VIMSRC}\vimw32.exe 256 lbl_done: 257 StrCpy $2 "$2 vim view vimdiff" 258SectionEnd 259 260########################################################## 261Section "Create .bat files for command line use" 262 SectionIn 3 263 264 StrCpy $1 "$1 -create-batfiles $2" 265SectionEnd 266 267########################################################## 268Section "Create icons on the Desktop" 269 SectionIn 1 3 270 271 StrCpy $1 "$1 -install-icons" 272SectionEnd 273 274########################################################## 275Section "Add Vim to the Start Menu" 276 SectionIn 1 3 277 278 StrCpy $1 "$1 -add-start-menu" 279SectionEnd 280 281########################################################## 282Section "Add an Edit-with-Vim context menu entry" 283 SectionIn 1 3 284 285 # Be aware of this sequence of events: 286 # - user uninstalls Vim, gvimext.dll can't be removed (it's in use) and 287 # is scheduled to be removed at next reboot. 288 # - user installs Vim in same directory, gvimext.dll still exists. 289 # If we now skip installing gvimext.dll, it will disappear at the next 290 # reboot. Thus when copying gvimext.dll fails always schedule it to be 291 # installed at the next reboot. Can't use UpgradeDLL! 292 # We don't ask the user to reboot, the old dll will keep on working. 293 SetOutPath $0 294 ClearErrors 295 SetOverwrite try 296 ${If} ${RunningX64} 297 File /oname=gvimext.dll ${VIMSRC}\GvimExt\gvimext64.dll 298 ${Else} 299 File /oname=gvimext.dll ${VIMSRC}\GvimExt\gvimext.dll 300 ${EndIf} 301 IfErrors 0 GvimExtDone 302 303 # Can't copy gvimext.dll, create it under another name and rename it on 304 # next reboot. 305 GetTempFileName $3 $0 306 ${If} ${RunningX64} 307 File /oname=$3 ${VIMSRC}\GvimExt\gvimext64.dll 308 ${Else} 309 File /oname=$3 ${VIMSRC}\GvimExt\gvimext.dll 310 ${EndIf} 311 Rename /REBOOTOK $3 $0\gvimext.dll 312 313 GvimExtDone: 314 SetOverwrite lastused 315 316 # We don't have a separate entry for the "Open With..." menu, assume 317 # the user wants either both or none. 318 StrCpy $1 "$1 -install-popup -install-openwith" 319SectionEnd 320 321########################################################## 322Section "Create a _vimrc if it doesn't exist" 323 SectionIn 1 3 324 325 StrCpy $1 "$1 -create-vimrc" 326SectionEnd 327 328########################################################## 329Section "Create plugin directories in HOME or VIM" 330 SectionIn 1 3 331 332 StrCpy $1 "$1 -create-directories home" 333SectionEnd 334 335########################################################## 336Section "Create plugin directories in VIM" 337 SectionIn 3 338 339 StrCpy $1 "$1 -create-directories vim" 340SectionEnd 341 342########################################################## 343Section "VisVim Extension for MS Visual Studio" 344 SectionIn 3 345 346 SetOutPath $0 347 !insertmacro UpgradeDLL "${VIMSRC}\VisVim\VisVim.dll" "$0\VisVim.dll" "$0" 348 File ${VIMSRC}\VisVim\README_VisVim.txt 349SectionEnd 350 351########################################################## 352!ifdef HAVE_NLS 353 Section "Native Language Support" 354 SectionIn 1 3 355 356 SetOutPath $0\lang 357 File /r ${VIMRT}\lang\*.* 358 SetOutPath $0\keymap 359 File ${VIMRT}\keymap\README.txt 360 File ${VIMRT}\keymap\*.vim 361 SetOutPath $0 362 File ${VIMRT}\libintl.dll 363 SectionEnd 364!endif 365 366########################################################## 367Section -call_install_exe 368 SetOutPath $0 369 ExecWait "$0\install.exe $1" 370SectionEnd 371 372########################################################## 373Section -post 374 BringToFront 375SectionEnd 376 377########################################################## 378Section Uninstall 379 # Apparently $INSTDIR is set to the directory where the uninstaller is 380 # created. Thus the "vim61" directory is included in it. 381 StrCpy $0 "$INSTDIR" 382 383 # If VisVim was installed, unregister the DLL. 384 IfFileExists "$0\VisVim.dll" Has_VisVim No_VisVim 385 Has_VisVim: 386 ExecWait "regsvr32.exe /u /s $0\VisVim.dll" 387 388 No_VisVim: 389 390 # delete the context menu entry and batch files 391 ExecWait "$0\uninstal.exe -nsis" 392 393 # We may have been put to the background when uninstall did something. 394 BringToFront 395 396 # ask the user if the Vim version dir must be removed 397 MessageBox MB_YESNO|MB_ICONQUESTION \ 398 "Would you like to delete $0?$\n \ 399 $\nIt contains the Vim executables and runtime files." IDNO NoRemoveExes 400 401 Delete /REBOOTOK $0\*.dll 402 ClearErrors 403 # Remove everything but *.dll files. Avoids that 404 # a lot remains when gvimext.dll cannot be deleted. 405 RMDir /r $0\autoload 406 RMDir /r $0\colors 407 RMDir /r $0\compiler 408 RMDir /r $0\doc 409 RMDir /r $0\ftplugin 410 RMDir /r $0\indent 411 RMDir /r $0\macros 412 RMDir /r $0\plugin 413 RMDir /r $0\spell 414 RMDir /r $0\syntax 415 RMDir /r $0\tools 416 RMDir /r $0\tutor 417 RMDir /r $0\VisVim 418 RMDir /r $0\lang 419 RMDir /r $0\keymap 420 Delete $0\*.exe 421 Delete $0\*.bat 422 Delete $0\*.vim 423 Delete $0\*.txt 424 425 IfErrors ErrorMess NoErrorMess 426 ErrorMess: 427 MessageBox MB_OK|MB_ICONEXCLAMATION \ 428 "Some files in $0 have not been deleted!$\nYou must do it manually." 429 NoErrorMess: 430 431 # No error message if the "vim62" directory can't be removed, the 432 # gvimext.dll may still be there. 433 RMDir $0 434 435 NoRemoveExes: 436 # get the parent dir of the installation 437 Push $INSTDIR 438 Call un.GetParent 439 Pop $0 440 StrCpy $1 $0 441 442 # if a plugin dir was created at installation ask the user to remove it 443 # first look in the root of the installation then in HOME 444 IfFileExists $1\vimfiles AskRemove 0 445 ReadEnvStr $1 "HOME" 446 StrCmp $1 "" NoRemove 0 447 448 IfFileExists $1\vimfiles 0 NoRemove 449 450 AskRemove: 451 MessageBox MB_YESNO|MB_ICONQUESTION \ 452 "Remove all files in your $1\vimfiles directory?$\n \ 453 $\nCAREFUL: If you have created something there that you want to keep, click No" IDNO Fin 454 RMDir /r $1\vimfiles 455 NoRemove: 456 457 # ask the user if the Vim root dir must be removed 458 MessageBox MB_YESNO|MB_ICONQUESTION \ 459 "Would you like to remove $0?$\n \ 460 $\nIt contains your Vim configuration files!" IDNO NoDelete 461 RMDir /r $0 ; skipped if no 462 NoDelete: 463 464 Fin: 465 Call un.onUnInstSuccess 466 467SectionEnd 468