1# NSIS file to create a self-installing exe for Vim. 2# It requires NSIS version 3.0 or later. 3# Last Change: 2014 Nov 5 4 5Unicode true 6 7# WARNING: if you make changes to this script, look out for $0 to be valid, 8# because uninstall deletes most files in $0. 9 10# Location of gvim_ole.exe, vimw32.exe, GvimExt/*, etc. 11!ifndef VIMSRC 12 !define VIMSRC "..\src" 13!endif 14 15# Location of runtime files 16!ifndef VIMRT 17 !define VIMRT ".." 18!endif 19 20# Location of extra tools: diff.exe 21!ifndef VIMTOOLS 22 !define VIMTOOLS ..\.. 23!endif 24 25# Location of gettext. 26# It must contain two directories: gettext32 and gettext64. 27# See README.txt for detail. 28!ifndef GETTEXT 29 !define GETTEXT ${VIMRT} 30!endif 31 32# Comment the next line if you don't have UPX. 33# Get it at https://upx.github.io/ 34!define HAVE_UPX 35 36# Comment the next line if you do not want to add Native Language Support 37!define HAVE_NLS 38 39# Uncomment the next line if you want to include VisVim extension: 40#!define HAVE_VIS_VIM 41 42# Comment the following line to create an English-only installer: 43!define HAVE_MULTI_LANG 44 45# Uncomment the next line if you want to create a 64-bit installer. 46#!define WIN64 47 48!include gvim_version.nsh # for version number 49 50# Definition of Patch for Vim 51!ifndef PATCHLEVEL 52 !define PATCHLEVEL 0 53!endif 54 55# ----------- No configurable settings below this line ----------- 56 57!include "Library.nsh" # For DLL install 58!ifdef HAVE_VIS_VIM 59 !include "UpgradeDLL.nsh" # for VisVim.dll 60!endif 61!include "LogicLib.nsh" 62!include "MUI2.nsh" 63!include "nsDialogs.nsh" 64!include "Sections.nsh" 65!include "x64.nsh" 66 67!define PRODUCT "Vim ${VER_MAJOR}.${VER_MINOR}" 68!define UNINST_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall" 69!define UNINST_REG_KEY_VIM "${UNINST_REG_KEY}\${PRODUCT}" 70 71!ifdef WIN64 72Name "${PRODUCT} (x64)" 73!else 74Name "${PRODUCT}" 75!endif 76OutFile gvim${VER_MAJOR}${VER_MINOR}.exe 77CRCCheck force 78SetCompressor /SOLID lzma 79SetCompressorDictSize 64 80ManifestDPIAware true 81SetDatablockOptimize on 82RequestExecutionLevel highest 83 84!ifdef HAVE_UPX 85 !packhdr temp.dat "upx --best --compress-icons=1 temp.dat" 86!endif 87 88!ifdef WIN64 89!define BIT 64 90!else 91!define BIT 32 92!endif 93 94########################################################## 95# MUI2 settings 96 97!define MUI_ABORTWARNING 98!define MUI_UNABORTWARNING 99 100!define MUI_ICON "icons\vim_16c.ico" 101!define MUI_UNICON "icons\vim_uninst_16c.ico" 102 103# Show all languages, despite user's codepage: 104!define MUI_LANGDLL_ALLLANGUAGES 105!define MUI_LANGDLL_REGISTRY_ROOT "HKCU" 106!define MUI_LANGDLL_REGISTRY_KEY "Software\Vim" 107!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language" 108 109!define MUI_WELCOMEFINISHPAGE_BITMAP "icons\welcome.bmp" 110!define MUI_UNWELCOMEFINISHPAGE_BITMAP "icons\uninstall.bmp" 111!define MUI_HEADERIMAGE 112!define MUI_HEADERIMAGE_BITMAP "icons\header.bmp" 113!define MUI_HEADERIMAGE_UNBITMAP "icons\un_header.bmp" 114 115!define MUI_WELCOMEFINISHPAGE_BITMAP_STRETCH "AspectFitHeight" 116!define MUI_UNWELCOMEFINISHPAGE_BITMAP_STRETCH "AspectFitHeight" 117!define MUI_HEADERIMAGE_BITMAP_STRETCH "AspectFitHeight" 118!define MUI_HEADERIMAGE_UNBITMAP_STRETCH "AspectFitHeight" 119 120!define MUI_COMPONENTSPAGE_SMALLDESC 121!define MUI_LICENSEPAGE_CHECKBOX 122!define MUI_FINISHPAGE_RUN 123!define MUI_FINISHPAGE_RUN_FUNCTION LaunchApplication 124!define MUI_FINISHPAGE_RUN_TEXT $(str_show_readme) 125 126# This adds '\Vim' to the user choice automagically. The actual value is 127# obtained below with CheckOldVim. 128!ifdef WIN64 129 !define DEFAULT_INSTDIR "$PROGRAMFILES64\Vim" 130!else 131 !define DEFAULT_INSTDIR "$PROGRAMFILES\Vim" 132!endif 133InstallDir ${DEFAULT_INSTDIR} 134 135# Types of installs we can perform: 136InstType $(str_type_typical) 137InstType $(str_type_minimal) 138InstType $(str_type_full) 139 140SilentInstall normal 141 142# General custom functions for MUI2: 143#!define MUI_CUSTOMFUNCTION_ABORT VimOnUserAbort 144#!define MUI_CUSTOMFUNCTION_UNABORT un.VimOnUserAbort 145 146# Installer pages 147!insertmacro MUI_PAGE_WELCOME 148!insertmacro MUI_PAGE_LICENSE "${VIMRT}\doc\uganda.nsis.txt" 149!insertmacro MUI_PAGE_COMPONENTS 150Page custom SetCustom ValidateCustom 151#!define MUI_PAGE_CUSTOMFUNCTION_LEAVE VimFinalCheck 152!insertmacro MUI_PAGE_DIRECTORY 153!insertmacro MUI_PAGE_INSTFILES 154!define MUI_FINISHPAGE_NOREBOOTSUPPORT 155!insertmacro MUI_PAGE_FINISH 156 157# Uninstaller pages: 158!insertmacro MUI_UNPAGE_CONFIRM 159#!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.VimCheckRunning 160!insertmacro MUI_UNPAGE_COMPONENTS 161!insertmacro MUI_UNPAGE_INSTFILES 162!define MUI_FINISHPAGE_NOREBOOTSUPPORT 163!insertmacro MUI_UNPAGE_FINISH 164 165########################################################## 166# Languages Files 167 168!insertmacro MUI_RESERVEFILE_LANGDLL 169!include "lang\english.nsi" 170 171# Include support for other languages: 172!ifdef HAVE_MULTI_LANG 173 !include "lang\danish.nsi" 174 !include "lang\dutch.nsi" 175 !include "lang\german.nsi" 176 !include "lang\italian.nsi" 177 !include "lang\japanese.nsi" 178 !include "lang\russian.nsi" 179 !include "lang\simpchinese.nsi" 180 !include "lang\tradchinese.nsi" 181 !include "lang\turkish.nsi" 182!endif 183 184########################################################## 185# Version resources 186 187VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "Vim" 188VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "Vim Developers" 189VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" "Vim" 190VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright (C) 1996" 191VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "Vi Improved - A Text Editor" 192VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${VER_MAJOR}.${VER_MINOR}.${PATCHLEVEL}.0" 193VIProductVersion "${VER_MAJOR}.${VER_MINOR}.${PATCHLEVEL}.0" 194 195# Global variables 196Var vim_dialog 197Var vim_nsd_compat 198Var vim_nsd_keymap 199Var vim_nsd_mouse 200Var vim_compat_stat 201Var vim_keymap_stat 202Var vim_mouse_stat 203 204 205# Reserve files 206ReserveFile ${VIMSRC}\installw32.exe 207 208########################################################## 209# Functions 210 211# Get parent directory 212# Share this function both on installer and uninstaller 213!macro GetParent un 214Function ${un}GetParent 215 Exch $0 ; old $0 is on top of stack 216 Push $1 217 Push $2 218 StrCpy $1 -1 219 ${Do} 220 StrCpy $2 $0 1 $1 221 ${If} $2 == "" 222 ${OrIf} $2 == "\" 223 ${ExitDo} 224 ${EndIf} 225 IntOp $1 $1 - 1 226 ${Loop} 227 StrCpy $0 $0 $1 228 Pop $2 229 Pop $1 230 Exch $0 ; put $0 on top of stack, restore $0 to original value 231FunctionEnd 232!macroend 233 234!insertmacro GetParent "" 235!insertmacro GetParent "un." 236 237# Check if Vim is already installed. 238# return: Installed directory. If not found, it will be empty. 239Function CheckOldVim 240 Push $0 241 Push $R0 242 Push $R1 243 Push $R2 244 245 ${If} ${RunningX64} 246 SetRegView 64 247 ${EndIf} 248 249 ClearErrors 250 StrCpy $0 "" # Installed directory 251 StrCpy $R0 0 # Sub-key index 252 StrCpy $R1 "" # Sub-key 253 ${Do} 254 # Eumerate the sub-key: 255 EnumRegKey $R1 HKLM ${UNINST_REG_KEY} $R0 256 257 # Stop if no more sub-key: 258 ${If} ${Errors} 259 ${OrIf} $R1 == "" 260 ${ExitDo} 261 ${EndIf} 262 263 # Move to the next sub-key: 264 IntOp $R0 $R0 + 1 265 266 # Check if the key is Vim uninstall key or not: 267 StrCpy $R2 $R1 4 268 ${If} $R2 S!= "Vim " 269 ${Continue} 270 ${EndIf} 271 272 # Verifies required sub-keys: 273 ReadRegStr $R2 HKLM "${UNINST_REG_KEY}\$R1" "DisplayName" 274 ${If} ${Errors} 275 ${OrIf} $R2 == "" 276 ${Continue} 277 ${EndIf} 278 279 ReadRegStr $R2 HKLM "${UNINST_REG_KEY}\$R1" "UninstallString" 280 ${If} ${Errors} 281 ${OrIf} $R2 == "" 282 ${Continue} 283 ${EndIf} 284 285 # Found 286 Push $R2 287 call GetParent 288 call GetParent 289 Pop $0 # Vim directory 290 ${ExitDo} 291 292 ${Loop} 293 294 ${If} ${RunningX64} 295 SetRegView lastused 296 ${EndIf} 297 298 Pop $R2 299 Pop $R1 300 Pop $R0 301 Exch $0 # put $0 on top of stack, restore $0 to original value 302FunctionEnd 303 304Function LaunchApplication 305 SetOutPath $0 306 ShellExecAsUser::ShellExecAsUser "" "$0\gvim.exe" '-R "$0\README.txt"' 307FunctionEnd 308 309########################################################## 310Section "$(str_section_old_ver)" id_section_old_ver 311 SectionIn 1 2 3 RO 312 313 # run the install program to check for already installed versions 314 SetOutPath $TEMP 315 File /oname=install.exe ${VIMSRC}\installw32.exe 316 DetailPrint "$(str_msg_uninstalling)" 317 ${Do} 318 nsExec::Exec "$TEMP\install.exe -uninstall-check" 319 Pop $3 320 321 call CheckOldVim 322 Pop $3 323 ${If} $3 == "" 324 ${ExitDo} 325 ${Else} 326 # It seems that the old version is still remaining. 327 # TODO: Should we show a warning and run the uninstaller again? 328 329 ${ExitDo} # Just ignore for now. 330 ${EndIf} 331 ${Loop} 332 Delete $TEMP\install.exe 333 Delete $TEMP\vimini.ini # install.exe creates this, but we don't need it. 334 335 # We may have been put to the background when uninstall did something. 336 BringToFront 337SectionEnd 338 339########################################################## 340Section "$(str_section_exe)" id_section_exe 341 SectionIn 1 2 3 RO 342 343 # we need also this here if the user changes the instdir 344 StrCpy $0 "$INSTDIR\vim${VER_MAJOR}${VER_MINOR}" 345 346 SetOutPath $0 347 File /oname=gvim.exe ${VIMSRC}\gvim_ole.exe 348!if /FileExists "${VIMSRC}\vim${BIT}.dll" 349 File ${VIMSRC}\vim${BIT}.dll 350!endif 351 File /oname=install.exe ${VIMSRC}\installw32.exe 352 File /oname=uninstall.exe ${VIMSRC}\uninstallw32.exe 353 File ${VIMSRC}\vimrun.exe 354 File /oname=tee.exe ${VIMSRC}\teew32.exe 355 File /oname=xxd.exe ${VIMSRC}\xxdw32.exe 356 File ..\vimtutor.bat 357 File ..\README.txt 358 File ..\uninstall.txt 359 File ${VIMRT}\*.vim 360 361 File ${VIMTOOLS}\diff.exe 362 File ${VIMTOOLS}\winpty${BIT}.dll 363 File ${VIMTOOLS}\winpty-agent.exe 364 365 SetOutPath $0\colors 366 File ${VIMRT}\colors\*.* 367 SetOutPath $0\colors\tools 368 File ${VIMRT}\colors\tools\*.* 369 SetOutPath $0\colors\lists 370 File ${VIMRT}\colors\lists\*.* 371 372 SetOutPath $0\compiler 373 File ${VIMRT}\compiler\*.* 374 375 SetOutPath $0\doc 376 File ${VIMRT}\doc\*.txt 377 File ${VIMRT}\doc\tags 378 379 SetOutPath $0\ftplugin 380 File ${VIMRT}\ftplugin\*.* 381 382 SetOutPath $0\indent 383 File ${VIMRT}\indent\*.* 384 385 SetOutPath $0\macros 386 File /r ${VIMRT}\macros\*.* 387 388 SetOutPath $0\pack 389 File /r ${VIMRT}\pack\*.* 390 391 SetOutPath $0\plugin 392 File ${VIMRT}\plugin\*.* 393 394 SetOutPath $0\autoload 395 File ${VIMRT}\autoload\*.* 396 397 SetOutPath $0\autoload\dist 398 File ${VIMRT}\autoload\dist\*.* 399 400 SetOutPath $0\autoload\xml 401 File ${VIMRT}\autoload\xml\*.* 402 403 SetOutPath $0\syntax 404 File ${VIMRT}\syntax\*.* 405 406 SetOutPath $0\spell 407 File ${VIMRT}\spell\*.txt 408 File ${VIMRT}\spell\*.vim 409 File ${VIMRT}\spell\*.spl 410 File ${VIMRT}\spell\*.sug 411 412 SetOutPath $0\tools 413 File ${VIMRT}\tools\*.* 414 415 SetOutPath $0\tutor 416 File ${VIMRT}\tutor\*.* 417SectionEnd 418 419########################################################## 420Section "$(str_section_console)" id_section_console 421 SectionIn 1 3 422 423 SetOutPath $0 424 File /oname=vim.exe ${VIMSRC}\vimw32.exe 425 StrCpy $2 "$2 vim view vimdiff" 426SectionEnd 427 428########################################################## 429Section "$(str_section_batch)" id_section_batch 430 SectionIn 3 431 432 StrCpy $1 "$1 -create-batfiles $2" 433SectionEnd 434 435########################################################## 436SectionGroup $(str_group_icons) id_group_icons 437 Section "$(str_section_desktop)" id_section_desktop 438 SectionIn 1 3 439 440 StrCpy $1 "$1 -install-icons" 441 SectionEnd 442 443 Section "$(str_section_start_menu)" id_section_startmenu 444 SectionIn 1 3 445 446 StrCpy $1 "$1 -add-start-menu" 447 SectionEnd 448SectionGroupEnd 449 450########################################################## 451Section "$(str_section_edit_with)" id_section_editwith 452 SectionIn 1 3 453 454 SetOutPath $0 455 456 ${If} ${RunningX64} 457 # Install 64-bit gvimext.dll into the GvimExt64 directory. 458 SetOutPath $0\GvimExt64 459 ClearErrors 460 !define LIBRARY_SHELL_EXTENSION 461 !define LIBRARY_X64 462 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 463 "${VIMSRC}\GvimExt\gvimext64.dll" \ 464 "$0\GvimExt64\gvimext.dll" "$0" 465 !undef LIBRARY_X64 466 !undef LIBRARY_SHELL_EXTENSION 467 ${EndIf} 468 469 # Install 32-bit gvimext.dll into the GvimExt32 directory. 470 SetOutPath $0\GvimExt32 471 ClearErrors 472 !define LIBRARY_SHELL_EXTENSION 473 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 474 "${VIMSRC}\GvimExt\gvimext.dll" \ 475 "$0\GvimExt32\gvimext.dll" "$0" 476 !undef LIBRARY_SHELL_EXTENSION 477 478 # We don't have a separate entry for the "Open With..." menu, assume 479 # the user wants either both or none. 480 StrCpy $1 "$1 -install-popup -install-openwith" 481SectionEnd 482 483########################################################## 484Section "$(str_section_vim_rc)" id_section_vimrc 485 SectionIn 1 3 486 487 StrCpy $1 "$1 -create-vimrc" 488 489 ${If} ${RunningX64} 490 SetRegView 64 491 ${EndIf} 492 WriteRegStr HKLM "${UNINST_REG_KEY_VIM}" "vim_compat" "$vim_compat_stat" 493 WriteRegStr HKLM "${UNINST_REG_KEY_VIM}" "vim_keyremap" "$vim_keymap_stat" 494 WriteRegStr HKLM "${UNINST_REG_KEY_VIM}" "vim_mouse" "$vim_mouse_stat" 495 ${If} ${RunningX64} 496 SetRegView lastused 497 ${EndIf} 498 499 ${If} $vim_compat_stat == "vi" 500 StrCpy $1 "$1 -vimrc-compat vi" 501 ${ElseIf} $vim_compat_stat == "vim" 502 StrCpy $1 "$1 -vimrc-compat vim" 503 ${ElseIf} $vim_compat_stat == "defaults" 504 StrCpy $1 "$1 -vimrc-compat defaults" 505 ${Else} 506 StrCpy $1 "$1 -vimrc-compat all" 507 ${EndIf} 508 509 ${If} $vim_keymap_stat == "default" 510 StrCpy $1 "$1 -vimrc-remap no" 511 ${Else} 512 StrCpy $1 "$1 -vimrc-remap win" 513 ${EndIf} 514 515 ${If} $vim_mouse_stat == "default" 516 StrCpy $1 "$1 -vimrc-behave default" 517 ${ElseIf} $vim_mouse_stat == "windows" 518 StrCpy $1 "$1 -vimrc-behave mswin" 519 ${Else} 520 StrCpy $1 "$1 -vimrc-behave unix" 521 ${EndIf} 522 523SectionEnd 524 525########################################################## 526SectionGroup $(str_group_plugin) id_group_plugin 527 Section "$(str_section_plugin_home)" id_section_pluginhome 528 SectionIn 1 3 529 530 StrCpy $1 "$1 -create-directories home" 531 SectionEnd 532 533 Section "$(str_section_plugin_vim)" id_section_pluginvim 534 SectionIn 3 535 536 StrCpy $1 "$1 -create-directories vim" 537 SectionEnd 538SectionGroupEnd 539 540########################################################## 541!ifdef HAVE_VIS_VIM 542Section "$(str_section_vis_vim)" id_section_visvim 543 SectionIn 3 544 545 SetOutPath $0 546 !insertmacro UpgradeDLL "${VIMSRC}\VisVim\VisVim.dll" "$0\VisVim.dll" "$0" 547 File ${VIMSRC}\VisVim\README_VisVim.txt 548SectionEnd 549!endif 550 551########################################################## 552!ifdef HAVE_NLS 553Section "$(str_section_nls)" id_section_nls 554 SectionIn 1 3 555 556 SetOutPath $0\lang 557 File /r ${VIMRT}\lang\*.* 558 SetOutPath $0\keymap 559 File ${VIMRT}\keymap\README.txt 560 File ${VIMRT}\keymap\*.vim 561 SetOutPath $0 562 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 563 "${GETTEXT}\gettext${BIT}\libintl-8.dll" \ 564 "$0\libintl-8.dll" "$0" 565 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 566 "${GETTEXT}\gettext${BIT}\libiconv-2.dll" \ 567 "$0\libiconv-2.dll" "$0" 568 !if /FileExists "${GETTEXT}\gettext${BIT}\libgcc_s_sjlj-1.dll" 569 # Install libgcc_s_sjlj-1.dll only if it is needed. 570 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 571 "${GETTEXT}\gettext${BIT}\libgcc_s_sjlj-1.dll" \ 572 "$0\libgcc_s_sjlj-1.dll" "$0" 573 !endif 574 575 ${If} ${SectionIsSelected} ${id_section_editwith} 576 ${If} ${RunningX64} 577 # Install DLLs for 64-bit gvimext.dll into the GvimExt64 directory. 578 SetOutPath $0\GvimExt64 579 ClearErrors 580 !define LIBRARY_X64 581 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 582 "${GETTEXT}\gettext64\libintl-8.dll" \ 583 "$0\GvimExt64\libintl-8.dll" "$0\GvimExt64" 584 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 585 "${GETTEXT}\gettext64\libiconv-2.dll" \ 586 "$0\GvimExt64\libiconv-2.dll" "$0\GvimExt64" 587 !undef LIBRARY_X64 588 ${EndIf} 589 590 # Install DLLs for 32-bit gvimext.dll into the GvimExt32 directory. 591 SetOutPath $0\GvimExt32 592 ClearErrors 593 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 594 "${GETTEXT}\gettext32\libintl-8.dll" \ 595 "$0\GvimExt32\libintl-8.dll" "$0\GvimExt32" 596 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 597 "${GETTEXT}\gettext32\libiconv-2.dll" \ 598 "$0\GvimExt32\libiconv-2.dll" "$0\GvimExt32" 599 !if /FileExists "${GETTEXT}\gettext32\libgcc_s_sjlj-1.dll" 600 # Install libgcc_s_sjlj-1.dll only if it is needed. 601 !insertmacro InstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 602 "${GETTEXT}\gettext32\libgcc_s_sjlj-1.dll" \ 603 "$0\GvimExt32\libgcc_s_sjlj-1.dll" "$0\GvimExt32" 604 !endif 605 ${EndIf} 606SectionEnd 607!endif 608 609########################################################## 610Section -call_install_exe 611 SetOutPath $0 612 DetailPrint "$(str_msg_registering)" 613 nsExec::Exec "$0\install.exe $1" 614 Pop $3 615SectionEnd 616 617########################################################## 618!macro SaveSectionSelection section_id reg_value 619 ${If} ${SectionIsSelected} ${section_id} 620 WriteRegDWORD HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} 1 621 ${Else} 622 WriteRegDWORD HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} 0 623 ${EndIf} 624!macroend 625 626Section -post 627 628 # Get estimated install size 629 SectionGetSize ${id_section_exe} $3 630 ${If} ${SectionIsSelected} ${id_section_console} 631 SectionGetSize ${id_section_console} $4 632 IntOp $3 $3 + $4 633 ${EndIf} 634 ${If} ${SectionIsSelected} ${id_section_editwith} 635 SectionGetSize ${id_section_editwith} $4 636 IntOp $3 $3 + $4 637 ${EndIf} 638!ifdef HAVE_VIS_VIM 639 ${If} ${SectionIsSelected} ${id_section_visvim} 640 SectionGetSize ${id_section_visvim} $4 641 IntOp $3 $3 + $4 642 ${EndIf} 643!endif 644!ifdef HAVE_NLS 645 ${If} ${SectionIsSelected} ${id_section_nls} 646 SectionGetSize ${id_section_nls} $4 647 IntOp $3 $3 + $4 648 ${EndIf} 649!endif 650 651 # Register EstimatedSize and AllowSilent. 652 # Other information will be set by the install.exe (dosinst.c). 653 ${If} ${RunningX64} 654 SetRegView 64 655 ${EndIf} 656 WriteRegDWORD HKLM "${UNINST_REG_KEY_VIM}" "EstimatedSize" $3 657 WriteRegDWORD HKLM "${UNINST_REG_KEY_VIM}" "AllowSilent" 1 658 ${If} ${RunningX64} 659 SetRegView lastused 660 ${EndIf} 661 662 # Store the selections to the registry. 663 ${If} ${RunningX64} 664 SetRegView 64 665 ${EndIf} 666 !insertmacro SaveSectionSelection ${id_section_console} "select_console" 667 !insertmacro SaveSectionSelection ${id_section_batch} "select_batch" 668 !insertmacro SaveSectionSelection ${id_section_desktop} "select_desktop" 669 !insertmacro SaveSectionSelection ${id_section_startmenu} "select_startmenu" 670 !insertmacro SaveSectionSelection ${id_section_editwith} "select_editwith" 671 !insertmacro SaveSectionSelection ${id_section_vimrc} "select_vimrc" 672 !insertmacro SaveSectionSelection ${id_section_pluginhome} "select_pluginhome" 673 !insertmacro SaveSectionSelection ${id_section_pluginvim} "select_pluginvim" 674!ifdef HAVE_VIS_VIM 675 !insertmacro SaveSectionSelection ${id_section_visvim} "select_visvim" 676!endif 677!ifdef HAVE_NLS 678 !insertmacro SaveSectionSelection ${id_section_nls} "select_nls" 679!endif 680 ${If} ${RunningX64} 681 SetRegView lastused 682 ${EndIf} 683 684 BringToFront 685SectionEnd 686 687########################################################## 688!macro LoadSectionSelection section_id reg_value 689 ClearErrors 690 ReadRegDWORD $3 HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} 691 ${IfNot} ${Errors} 692 ${If} $3 = 1 693 !insertmacro SelectSection ${section_id} 694 ${Else} 695 !insertmacro UnselectSection ${section_id} 696 ${EndIf} 697 ${EndIf} 698!macroend 699 700!macro LoadDefaultVimrc out_var reg_value default_value 701 ClearErrors 702 ReadRegStr ${out_var} HKLM "${UNINST_REG_KEY_VIM}" ${reg_value} 703 ${If} ${Errors} 704 ${OrIf} ${out_var} == "" 705 StrCpy ${out_var} ${default_value} 706 ${EndIf} 707!macroend 708 709Function .onInit 710!ifdef HAVE_MULTI_LANG 711 # Select a language (or read from the registry). 712 !insertmacro MUI_LANGDLL_DISPLAY 713!endif 714 715 ${If} $INSTDIR == ${DEFAULT_INSTDIR} 716 # Check $VIM 717 ReadEnvStr $3 "VIM" 718 ${If} $3 != "" 719 StrCpy $INSTDIR $3 720 ${EndIf} 721 ${EndIf} 722 723 call CheckOldVim 724 Pop $3 725 ${If} $3 == "" 726 # No old versions of Vim found. Unselect and hide the section. 727 !insertmacro UnselectSection ${id_section_old_ver} 728 SectionSetInstTypes ${id_section_old_ver} 0 729 SectionSetText ${id_section_old_ver} "" 730 ${Else} 731 ${If} $INSTDIR == ${DEFAULT_INSTDIR} 732 StrCpy $INSTDIR $3 733 ${EndIf} 734 ${EndIf} 735 736 ${If} ${RunningX64} 737 SetRegView 64 738 ${EndIf} 739 # Load the selections from the registry (if any). 740 !insertmacro LoadSectionSelection ${id_section_console} "select_console" 741 !insertmacro LoadSectionSelection ${id_section_batch} "select_batch" 742 !insertmacro LoadSectionSelection ${id_section_desktop} "select_desktop" 743 !insertmacro LoadSectionSelection ${id_section_startmenu} "select_startmenu" 744 !insertmacro LoadSectionSelection ${id_section_editwith} "select_editwith" 745 !insertmacro LoadSectionSelection ${id_section_vimrc} "select_vimrc" 746 !insertmacro LoadSectionSelection ${id_section_pluginhome} "select_pluginhome" 747 !insertmacro LoadSectionSelection ${id_section_pluginvim} "select_pluginvim" 748!ifdef HAVE_VIS_VIM 749 !insertmacro LoadSectionSelection ${id_section_visvim} "select_visvim" 750!endif 751!ifdef HAVE_NLS 752 !insertmacro LoadSectionSelection ${id_section_nls} "select_nls" 753!endif 754 # Load the default _vimrc settings from the registry (if any). 755 !insertmacro LoadDefaultVimrc $vim_compat_stat "vim_compat" "all" 756 !insertmacro LoadDefaultVimrc $vim_keymap_stat "vim_keyremap" "default" 757 !insertmacro LoadDefaultVimrc $vim_mouse_stat "vim_mouse" "default" 758 ${If} ${RunningX64} 759 SetRegView lastused 760 ${EndIf} 761 762 # User variables: 763 # $0 - holds the directory the executables are installed to 764 # $1 - holds the parameters to be passed to install.exe. Starts with OLE 765 # registration (since a non-OLE gvim will not complain, and we want to 766 # always register an OLE gvim). 767 # $2 - holds the names to create batch files for 768 StrCpy $0 "$INSTDIR\vim${VER_MAJOR}${VER_MINOR}" 769 StrCpy $1 "-register-OLE" 770 StrCpy $2 "gvim evim gview gvimdiff vimtutor" 771FunctionEnd 772 773Function .onInstSuccess 774 WriteUninstaller vim${VER_MAJOR}${VER_MINOR}\uninstall-gui.exe 775FunctionEnd 776 777Function .onInstFailed 778 MessageBox MB_OK|MB_ICONEXCLAMATION "$(str_msg_install_fail)" /SD IDOK 779FunctionEnd 780 781########################################################## 782Function SetCustom 783 # Display the _vimrc setting dialog using nsDialogs. 784 785 # Check if a _vimrc should be created 786 ${IfNot} ${SectionIsSelected} ${id_section_vimrc} 787 Abort 788 ${EndIf} 789 790 !insertmacro MUI_HEADER_TEXT \ 791 $(str_vimrc_page_title) $(str_vimrc_page_subtitle) 792 793 nsDialogs::Create 1018 794 Pop $vim_dialog 795 796 ${If} $vim_dialog == error 797 Abort 798 ${EndIf} 799 800 ${If} ${RunningX64} 801 SetRegView 64 802 ${EndIf} 803 804 GetFunctionAddress $3 ValidateCustom 805 nsDialogs::OnBack $3 806 807 808 # 1st group - Compatibility 809 ${NSD_CreateGroupBox} 0 0 100% 32% $(str_msg_compat_title) 810 Pop $3 811 812 ${NSD_CreateLabel} 5% 10% 35% 8% $(str_msg_compat_desc) 813 Pop $3 814 ${NSD_CreateDropList} 18% 19% 75% 8% "" 815 Pop $vim_nsd_compat 816 ${NSD_CB_AddString} $vim_nsd_compat $(str_msg_compat_vi) 817 ${NSD_CB_AddString} $vim_nsd_compat $(str_msg_compat_vim) 818 ${NSD_CB_AddString} $vim_nsd_compat $(str_msg_compat_defaults) 819 ${NSD_CB_AddString} $vim_nsd_compat $(str_msg_compat_all) 820 821 ${If} $vim_compat_stat == "defaults" 822 StrCpy $4 2 823 ${ElseIf} $vim_compat_stat == "vim" 824 StrCpy $4 1 825 ${ElseIf} $vim_compat_stat == "vi" 826 StrCpy $4 0 827 ${Else} # default 828 StrCpy $4 3 829 ${EndIf} 830 ${NSD_CB_SetSelectionIndex} $vim_nsd_compat $4 831 832 833 # 2nd group - Key remapping 834 ${NSD_CreateGroupBox} 0 35% 100% 31% $(str_msg_keymap_title) 835 Pop $3 836 837 ${NSD_CreateLabel} 5% 45% 90% 8% $(str_msg_keymap_desc) 838 Pop $3 839 ${NSD_CreateDropList} 38% 54% 55% 8% "" 840 Pop $vim_nsd_keymap 841 ${NSD_CB_AddString} $vim_nsd_keymap $(str_msg_keymap_default) 842 ${NSD_CB_AddString} $vim_nsd_keymap $(str_msg_keymap_windows) 843 844 ${If} $vim_keymap_stat == "windows" 845 StrCpy $4 1 846 ${Else} # default 847 StrCpy $4 0 848 ${EndIf} 849 ${NSD_CB_SetSelectionIndex} $vim_nsd_keymap $4 850 851 852 # 3rd group - Mouse behavior 853 ${NSD_CreateGroupBox} 0 69% 100% 31% $(str_msg_mouse_title) 854 Pop $3 855 856 ${NSD_CreateLabel} 5% 79% 90% 8% $(str_msg_mouse_desc) 857 Pop $3 858 ${NSD_CreateDropList} 23% 87% 70% 8% "" 859 Pop $vim_nsd_mouse 860 ${NSD_CB_AddString} $vim_nsd_mouse $(str_msg_mouse_default) 861 ${NSD_CB_AddString} $vim_nsd_mouse $(str_msg_mouse_windows) 862 ${NSD_CB_AddString} $vim_nsd_mouse $(str_msg_mouse_unix) 863 864 ${If} $vim_mouse_stat == "xterm" 865 StrCpy $4 2 866 ${ElseIf} $vim_mouse_stat == "windows" 867 StrCpy $4 1 868 ${Else} # default 869 StrCpy $4 0 870 ${EndIf} 871 ${NSD_CB_SetSelectionIndex} $vim_nsd_mouse $4 872 873 ${If} ${RunningX64} 874 SetRegView lastused 875 ${EndIf} 876 877 nsDialogs::Show 878FunctionEnd 879 880Function ValidateCustom 881 ${NSD_CB_GetSelectionIndex} $vim_nsd_compat $3 882 ${If} $3 = 0 883 StrCpy $vim_compat_stat "vi" 884 ${ElseIf} $3 = 1 885 StrCpy $vim_compat_stat "vim" 886 ${ElseIf} $3 = 2 887 StrCpy $vim_compat_stat "defaults" 888 ${Else} 889 StrCpy $vim_compat_stat "all" 890 ${EndIf} 891 892 ${NSD_CB_GetSelectionIndex} $vim_nsd_keymap $3 893 ${If} $3 = 0 894 StrCpy $vim_keymap_stat "default" 895 ${Else} 896 StrCpy $vim_keymap_stat "windows" 897 ${EndIf} 898 899 ${NSD_CB_GetSelectionIndex} $vim_nsd_mouse $3 900 ${If} $3 = 0 901 StrCpy $vim_mouse_stat "default" 902 ${ElseIf} $3 = 1 903 StrCpy $vim_mouse_stat "windows" 904 ${Else} 905 StrCpy $vim_mouse_stat "xterm" 906 ${EndIf} 907FunctionEnd 908 909########################################################## 910# Description for Installer Sections 911 912!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN 913 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_old_ver} $(str_desc_old_ver) 914 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_exe} $(str_desc_exe) 915 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_console} $(str_desc_console) 916 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_batch} $(str_desc_batch) 917 !insertmacro MUI_DESCRIPTION_TEXT ${id_group_icons} $(str_desc_icons) 918 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_desktop} $(str_desc_desktop) 919 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_startmenu} $(str_desc_start_menu) 920 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_editwith} $(str_desc_edit_with) 921 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_vimrc} $(str_desc_vim_rc) 922 !insertmacro MUI_DESCRIPTION_TEXT ${id_group_plugin} $(str_desc_plugin) 923 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_pluginhome} $(str_desc_plugin_home) 924 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_pluginvim} $(str_desc_plugin_vim) 925!ifdef HAVE_VIS_VIM 926 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_visvim} $(str_desc_vis_vim) 927!endif 928!ifdef HAVE_NLS 929 !insertmacro MUI_DESCRIPTION_TEXT ${id_section_nls} $(str_desc_nls) 930!endif 931!insertmacro MUI_FUNCTION_DESCRIPTION_END 932 933 934########################################################## 935# Uninstaller Functions and Sections 936 937Function un.onInit 938!ifdef HAVE_MULTI_LANG 939 # Get the language from the registry. 940 !insertmacro MUI_UNGETLANGUAGE 941!endif 942FunctionEnd 943 944Section "un.$(str_unsection_register)" id_unsection_register 945 SectionIn RO 946 947 # Apparently $INSTDIR is set to the directory where the uninstaller is 948 # created. Thus the "vim61" directory is included in it. 949 StrCpy $0 "$INSTDIR" 950 951!ifdef HAVE_VIS_VIM 952 # If VisVim was installed, unregister the DLL. 953 ${If} ${FileExists} "$0\VisVim.dll" 954 ExecWait "regsvr32.exe /u /s $0\VisVim.dll" 955 ${EndIf} 956!endif 957 958 # delete the context menu entry and batch files 959 DetailPrint "$(str_msg_unregistering)" 960 nsExec::Exec "$0\uninstall.exe -nsis" 961 Pop $3 962 963 # We may have been put to the background when uninstall did something. 964 BringToFront 965 966 # Delete the installer language setting. 967 DeleteRegKey ${MUI_LANGDLL_REGISTRY_ROOT} ${MUI_LANGDLL_REGISTRY_KEY} 968SectionEnd 969 970Section "un.$(str_unsection_exe)" id_unsection_exe 971 972 StrCpy $0 "$INSTDIR" 973 974 # Delete gettext and iconv DLLs 975 ${If} ${FileExists} "$0\libiconv-2.dll" 976 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 977 "$0\libiconv-2.dll" 978 ${EndIf} 979 ${If} ${FileExists} "$0\libintl-8.dll" 980 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 981 "$0\libintl-8.dll" 982 ${EndIf} 983 ${If} ${FileExists} "$0\libgcc_s_sjlj-1.dll" 984 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 985 "$0\libgcc_s_sjlj-1.dll" 986 ${EndIf} 987 988 # Delete other DLLs 989 Delete /REBOOTOK $0\*.dll 990 991 # Delete 64-bit GvimExt 992 ${If} ${RunningX64} 993 !define LIBRARY_X64 994 ${If} ${FileExists} "$0\GvimExt64\gvimext.dll" 995 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 996 "$0\GvimExt64\gvimext.dll" 997 ${EndIf} 998 ${If} ${FileExists} "$0\GvimExt64\libiconv-2.dll" 999 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 1000 "$0\GvimExt64\libiconv-2.dll" 1001 ${EndIf} 1002 ${If} ${FileExists} "$0\GvimExt64\libintl-8.dll" 1003 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 1004 "$0\GvimExt64\libintl-8.dll" 1005 ${EndIf} 1006 ${If} ${FileExists} "$0\GvimExt64\libwinpthread-1.dll" 1007 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 1008 "$0\GvimExt64\libwinpthread-1.dll" 1009 ${EndIf} 1010 !undef LIBRARY_X64 1011 RMDir /r $0\GvimExt64 1012 ${EndIf} 1013 1014 # Delete 32-bit GvimExt 1015 ${If} ${FileExists} "$0\GvimExt32\gvimext.dll" 1016 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 1017 "$0\GvimExt32\gvimext.dll" 1018 ${EndIf} 1019 ${If} ${FileExists} "$0\GvimExt32\libiconv-2.dll" 1020 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 1021 "$0\GvimExt32\libiconv-2.dll" 1022 ${EndIf} 1023 ${If} ${FileExists} "$0\GvimExt32\libintl-8.dll" 1024 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 1025 "$0\GvimExt32\libintl-8.dll" 1026 ${EndIf} 1027 ${If} ${FileExists} "$0\GvimExt32\libgcc_s_sjlj-1.dll" 1028 !insertmacro UninstallLib DLL NOTSHARED REBOOT_NOTPROTECTED \ 1029 "$0\GvimExt32\libgcc_s_sjlj-1.dll" 1030 ${EndIf} 1031 RMDir /r $0\GvimExt32 1032 1033 ClearErrors 1034 # Remove everything but *.dll files. Avoids that 1035 # a lot remains when gvimext.dll cannot be deleted. 1036 RMDir /r $0\autoload 1037 RMDir /r $0\colors 1038 RMDir /r $0\compiler 1039 RMDir /r $0\doc 1040 RMDir /r $0\ftplugin 1041 RMDir /r $0\indent 1042 RMDir /r $0\macros 1043 RMDir /r $0\pack 1044 RMDir /r $0\plugin 1045 RMDir /r $0\spell 1046 RMDir /r $0\syntax 1047 RMDir /r $0\tools 1048 RMDir /r $0\tutor 1049!ifdef HAVE_VIS_VIM 1050 RMDir /r $0\VisVim 1051!endif 1052 RMDir /r $0\lang 1053 RMDir /r $0\keymap 1054 Delete $0\*.exe 1055 Delete $0\*.bat 1056 Delete $0\*.vim 1057 Delete $0\*.txt 1058 1059 ${If} ${Errors} 1060 MessageBox MB_OK|MB_ICONEXCLAMATION $(str_msg_rm_exe_fail) /SD IDOK 1061 ${EndIf} 1062 1063 # No error message if the "vim62" directory can't be removed, the 1064 # gvimext.dll may still be there. 1065 RMDir $0 1066SectionEnd 1067 1068# Remove "vimfiles" directory under the specified directory. 1069!macro RemoveVimfiles dir 1070 ${If} ${FileExists} ${dir}\vimfiles 1071 RMDir ${dir}\vimfiles\colors 1072 RMDir ${dir}\vimfiles\compiler 1073 RMDir ${dir}\vimfiles\doc 1074 RMDir ${dir}\vimfiles\ftdetect 1075 RMDir ${dir}\vimfiles\ftplugin 1076 RMDir ${dir}\vimfiles\indent 1077 RMDir ${dir}\vimfiles\keymap 1078 RMDir ${dir}\vimfiles\plugin 1079 RMDir ${dir}\vimfiles\syntax 1080 RMDir ${dir}\vimfiles 1081 ${EndIf} 1082!macroend 1083 1084SectionGroup "un.$(str_ungroup_plugin)" id_ungroup_plugin 1085 Section /o "un.$(str_unsection_plugin_home)" id_unsection_plugin_home 1086 # get the home dir 1087 ReadEnvStr $0 "HOME" 1088 ${If} $0 == "" 1089 ReadEnvStr $0 "HOMEDRIVE" 1090 ReadEnvStr $1 "HOMEPATH" 1091 StrCpy $0 "$0$1" 1092 ${If} $0 == "" 1093 ReadEnvStr $0 "USERPROFILE" 1094 ${EndIf} 1095 ${EndIf} 1096 1097 ${If} $0 != "" 1098 !insertmacro RemoveVimfiles $0 1099 ${EndIf} 1100 SectionEnd 1101 1102 Section "un.$(str_unsection_plugin_vim)" id_unsection_plugin_vim 1103 # get the parent dir of the installation 1104 Push $INSTDIR 1105 Call un.GetParent 1106 Pop $0 1107 1108 # if a plugin dir was created at installation remove it 1109 !insertmacro RemoveVimfiles $0 1110 SectionEnd 1111SectionGroupEnd 1112 1113Section "un.$(str_unsection_rootdir)" id_unsection_rootdir 1114 # get the parent dir of the installation 1115 Push $INSTDIR 1116 Call un.GetParent 1117 Pop $0 1118 1119 ${IfNot} ${Silent} 1120 Delete $0\_vimrc 1121 ${Endif} 1122 RMDir $0 1123SectionEnd 1124 1125########################################################## 1126# Description for Uninstaller Sections 1127 1128!insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN 1129 !insertmacro MUI_DESCRIPTION_TEXT ${id_unsection_register} $(str_desc_unregister) 1130 !insertmacro MUI_DESCRIPTION_TEXT ${id_unsection_exe} $(str_desc_rm_exe) 1131 !insertmacro MUI_DESCRIPTION_TEXT ${id_ungroup_plugin} $(str_desc_rm_plugin) 1132 !insertmacro MUI_DESCRIPTION_TEXT ${id_unsection_plugin_home} $(str_desc_rm_plugin_home) 1133 !insertmacro MUI_DESCRIPTION_TEXT ${id_unsection_plugin_vim} $(str_desc_rm_plugin_vim) 1134 !insertmacro MUI_DESCRIPTION_TEXT ${id_unsection_rootdir} $(str_desc_rm_rootdir) 1135!insertmacro MUI_UNFUNCTION_DESCRIPTION_END 1136