blob: 1a169f3e00ddccb3e74d3a8bc512d871869fbe09 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001# NSIS file to create a self-installing exe for Vim.
2# It requires NSIS version 2.0 or later.
Bram Moolenaar04344822014-11-05 18:18:17 +01003# Last Change: 2014 Nov 5
Bram Moolenaar071d4272004-06-13 20:20:40 +00004
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
Bram Moolenaarba460752013-07-04 22:35:01 +02008# Location of gvim_ole.exe, vimw32.exe, GvimExt/*, etc.
Bram Moolenaar286eacd2016-01-16 18:05:50 +01009!ifndef VIMSRC
10 !define VIMSRC "..\src"
11!endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012
13# Location of runtime files
Bram Moolenaar286eacd2016-01-16 18:05:50 +010014!ifndef VIMRT
15 !define VIMRT ".."
16!endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000017
18# Location of extra tools: diff.exe
Bram Moolenaar286eacd2016-01-16 18:05:50 +010019!ifndef VIMTOOLS
20 !define VIMTOOLS ..\..
21!endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000022
23# Comment the next line if you don't have UPX.
24# Get it at http://upx.sourceforge.net
25!define HAVE_UPX
26
27# comment the next line if you do not want to add Native Language Support
28!define HAVE_NLS
29
Bram Moolenaar6c7b4442016-01-02 15:44:32 +010030!include gvim_version.nsh # for version number
Bram Moolenaar071d4272004-06-13 20:20:40 +000031
32# ----------- No configurable settings below this line -----------
33
34!include UpgradeDLL.nsh # for VisVim.dll
Bram Moolenaar442b4222010-05-24 21:34:22 +020035!include LogicLib.nsh
36!include x64.nsh
Bram Moolenaar071d4272004-06-13 20:20:40 +000037
38Name "Vim ${VER_MAJOR}.${VER_MINOR}"
39OutFile gvim${VER_MAJOR}${VER_MINOR}.exe
40CRCCheck force
Bram Moolenaar286eacd2016-01-16 18:05:50 +010041SetCompressor /SOLID lzma
Bram Moolenaar071d4272004-06-13 20:20:40 +000042SetDatablockOptimize on
Bram Moolenaar442b4222010-05-24 21:34:22 +020043RequestExecutionLevel highest
Bram Moolenaar286eacd2016-01-16 18:05:50 +010044XPStyle on
Bram Moolenaar071d4272004-06-13 20:20:40 +000045
46ComponentText "This will install Vim ${VER_MAJOR}.${VER_MINOR} on your computer."
Bram Moolenaar04344822014-11-05 18:18:17 +010047DirText "Choose a directory to install Vim (should contain 'vim')"
Bram Moolenaar071d4272004-06-13 20:20:40 +000048Icon icons\vim_16c.ico
Bram Moolenaar266411a2013-07-05 20:01:32 +020049# NSIS2 uses a different strategy with six different images in a strip...
Bram Moolenaar071d4272004-06-13 20:20:40 +000050#EnabledBitmap icons\enabled.bmp
51#DisabledBitmap icons\disabled.bmp
52UninstallText "This will uninstall Vim ${VER_MAJOR}.${VER_MINOR} from your system."
53UninstallIcon icons\vim_uninst_16c.ico
54
55# On NSIS 2 using the BGGradient causes trouble on Windows 98, in combination
56# with the BringToFront.
57# BGGradient 004000 008200 FFFFFF
58LicenseText "You should read the following before installing:"
59LicenseData ${VIMRT}\doc\uganda.nsis.txt
60
61!ifdef HAVE_UPX
62 !packhdr temp.dat "upx --best --compress-icons=1 temp.dat"
63!endif
64
65# This adds '\vim' to the user choice automagically. The actual value is
66# obtained below with ReadINIStr.
67InstallDir "$PROGRAMFILES\Vim"
68
69# Types of installs we can perform:
70InstType Typical
71InstType Minimal
72InstType Full
73
74SilentInstall normal
75
76# These are the pages we use
77Page license
78Page components
79Page directory "" "" CheckInstallDir
80Page instfiles
81UninstPage uninstConfirm
82UninstPage instfiles
83
84##########################################################
85# Functions
86
87Function .onInit
88 MessageBox MB_YESNO|MB_ICONQUESTION \
89 "This will install Vim ${VER_MAJOR}.${VER_MINOR} on your computer.$\n Continue?" \
Bram Moolenaara1bd86e2017-06-24 15:11:01 +020090 /SD IDYES \
91 IDYES NoAbort
Bram Moolenaar071d4272004-06-13 20:20:40 +000092 Abort ; causes installer to quit.
93 NoAbort:
94
95 # run the install program to check for already installed versions
96 SetOutPath $TEMP
97 File /oname=install.exe ${VIMSRC}\installw32.exe
98 ExecWait "$TEMP\install.exe -uninstall-check"
99 Delete $TEMP\install.exe
100
101 # We may have been put to the background when uninstall did something.
102 BringToFront
103
104 # Install will have created a file for us that contains the directory where
105 # we should install. This is $VIM if it's set. This appears to be the only
106 # way to get the value of $VIM here!?
107 ReadINIStr $INSTDIR $TEMP\vimini.ini vimini dir
108 Delete $TEMP\vimini.ini
109
110 # If ReadINIStr failed or did not find a path: use the default dir.
111 StrCmp $INSTDIR "" 0 IniOK
112 StrCpy $INSTDIR "$PROGRAMFILES\Vim"
113 IniOK:
114
115 # Should check for the value of $VIM and use it. Unfortunately I don't know
116 # how to obtain the value of $VIM
117 # IfFileExists "$VIM" 0 No_Vim
118 # StrCpy $INSTDIR "$VIM"
119 # No_Vim:
120
121 # User variables:
122 # $0 - holds the directory the executables are installed to
123 # $1 - holds the parameters to be passed to install.exe. Starts with OLE
124 # registration (since a non-OLE gvim will not complain, and we want to
125 # always register an OLE gvim).
126 # $2 - holds the names to create batch files for
127 StrCpy $0 "$INSTDIR\vim${VER_MAJOR}${VER_MINOR}"
128 StrCpy $1 "-register-OLE"
Bram Moolenaar7fcab2a2006-03-25 21:46:12 +0000129 StrCpy $2 "gvim evim gview gvimdiff vimtutor"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130
131FunctionEnd
132
133Function .onUserAbort
134 MessageBox MB_YESNO|MB_ICONQUESTION "Abort install?" IDYES NoCancelAbort
135 Abort ; causes installer to not quit.
136 NoCancelAbort:
137FunctionEnd
138
139# We only accept the directory if it ends in "vim". Using .onVerifyInstDir has
140# the disadvantage that the browse dialog is difficult to use.
141Function CheckInstallDir
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142FunctionEnd
143
144Function .onInstSuccess
145 WriteUninstaller vim${VER_MAJOR}${VER_MINOR}\uninstall-gui.exe
146 MessageBox MB_YESNO|MB_ICONQUESTION \
Bram Moolenaarf2330482008-06-24 20:19:36 +0000147 "The installation process has been successful. Happy Vimming! \
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148 $\n$\n Do you want to see the README file now?" IDNO NoReadme
149 Exec '$0\gvim.exe -R "$0\README.txt"'
150 NoReadme:
151FunctionEnd
152
153Function .onInstFailed
154 MessageBox MB_OK|MB_ICONEXCLAMATION "Installation failed. Better luck next time."
155FunctionEnd
156
157Function un.onUnInstSuccess
158 MessageBox MB_OK|MB_ICONINFORMATION \
159 "Vim ${VER_MAJOR}.${VER_MINOR} has been (partly) removed from your system"
160FunctionEnd
161
162Function un.GetParent
163 Exch $0 ; old $0 is on top of stack
164 Push $1
165 Push $2
166 StrCpy $1 -1
167 loop:
168 StrCpy $2 $0 1 $1
169 StrCmp $2 "" exit
170 StrCmp $2 "\" exit
171 IntOp $1 $1 - 1
172 Goto loop
173 exit:
174 StrCpy $0 $0 $1
175 Pop $2
176 Pop $1
177 Exch $0 ; put $0 on top of stack, restore $0 to original value
178FunctionEnd
179
180##########################################################
181Section "Vim executables and runtime files"
Bram Moolenaar49150a42017-09-17 21:00:03 +0200182 SectionIn 1 2 3 RO
Bram Moolenaar071d4272004-06-13 20:20:40 +0000183
184 # we need also this here if the user changes the instdir
185 StrCpy $0 "$INSTDIR\vim${VER_MAJOR}${VER_MINOR}"
186
187 SetOutPath $0
188 File /oname=gvim.exe ${VIMSRC}\gvim_ole.exe
189 File /oname=install.exe ${VIMSRC}\installw32.exe
190 File /oname=uninstal.exe ${VIMSRC}\uninstalw32.exe
191 File ${VIMSRC}\vimrun.exe
Bram Moolenaarfec246d2016-08-28 18:47:14 +0200192 File /oname=tee.exe ${VIMSRC}\teew32.exe
Bram Moolenaar071d4272004-06-13 20:20:40 +0000193 File /oname=xxd.exe ${VIMSRC}\xxdw32.exe
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194 File ${VIMRT}\vimtutor.bat
195 File ${VIMRT}\README.txt
196 File ..\uninstal.txt
197 File ${VIMRT}\*.vim
198 File ${VIMRT}\rgb.txt
199
Bram Moolenaar98ebd2b2017-08-19 13:29:19 +0200200 File ${VIMTOOLS}\diff.exe
201 File ${VIMTOOLS}\winpty32.dll
202 File ${VIMTOOLS}\winpty-agent.exe
203
Bram Moolenaar071d4272004-06-13 20:20:40 +0000204 SetOutPath $0\colors
205 File ${VIMRT}\colors\*.*
206
207 SetOutPath $0\compiler
208 File ${VIMRT}\compiler\*.*
209
210 SetOutPath $0\doc
211 File ${VIMRT}\doc\*.txt
212 File ${VIMRT}\doc\tags
213
214 SetOutPath $0\ftplugin
215 File ${VIMRT}\ftplugin\*.*
216
217 SetOutPath $0\indent
218 File ${VIMRT}\indent\*.*
219
220 SetOutPath $0\macros
221 File ${VIMRT}\macros\*.*
Bram Moolenaarc35e4cb2017-09-06 21:43:10 +0200222 SetOutPath $0\macros\hanoi
223 File ${VIMRT}\macros\hanoi\*.*
224 SetOutPath $0\macros\life
225 File ${VIMRT}\macros\life\*.*
226 SetOutPath $0\macros\maze
227 File ${VIMRT}\macros\maze\*.*
228 SetOutPath $0\macros\urm
229 File ${VIMRT}\macros\urm\*.*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230
Bram Moolenaarc7baa432016-04-26 17:34:44 +0200231 SetOutPath $0\pack\dist\opt\dvorak\dvorak
232 File ${VIMRT}\pack\dist\opt\dvorak\dvorak\*.*
233 SetOutPath $0\pack\dist\opt\dvorak\plugin
234 File ${VIMRT}\pack\dist\opt\dvorak\plugin\*.*
235
236 SetOutPath $0\pack\dist\opt\editexisting\plugin
237 File ${VIMRT}\pack\dist\opt\editexisting\plugin\*.*
238
239 SetOutPath $0\pack\dist\opt\justify\plugin
240 File ${VIMRT}\pack\dist\opt\justify\plugin\*.*
241
242 SetOutPath $0\pack\dist\opt\matchit\doc
243 File ${VIMRT}\pack\dist\opt\matchit\doc\*.*
244 SetOutPath $0\pack\dist\opt\matchit\plugin
245 File ${VIMRT}\pack\dist\opt\matchit\plugin\*.*
246
247 SetOutPath $0\pack\dist\opt\shellmenu\plugin
248 File ${VIMRT}\pack\dist\opt\shellmenu\plugin\*.*
249
250 SetOutPath $0\pack\dist\opt\swapmouse\plugin
251 File ${VIMRT}\pack\dist\opt\swapmouse\plugin\*.*
252
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253 SetOutPath $0\plugin
254 File ${VIMRT}\plugin\*.*
255
Bram Moolenaar7fcab2a2006-03-25 21:46:12 +0000256 SetOutPath $0\autoload
257 File ${VIMRT}\autoload\*.*
258
Bram Moolenaar18144c82006-04-12 21:52:12 +0000259 SetOutPath $0\autoload\xml
260 File ${VIMRT}\autoload\xml\*.*
261
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262 SetOutPath $0\syntax
263 File ${VIMRT}\syntax\*.*
264
Bram Moolenaarc01140a2006-03-24 22:21:52 +0000265 SetOutPath $0\spell
266 File ${VIMRT}\spell\*.txt
267 File ${VIMRT}\spell\*.vim
268 File ${VIMRT}\spell\*.spl
269 File ${VIMRT}\spell\*.sug
270
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271 SetOutPath $0\tools
272 File ${VIMRT}\tools\*.*
273
274 SetOutPath $0\tutor
275 File ${VIMRT}\tutor\*.*
276SectionEnd
277
278##########################################################
279Section "Vim console program (vim.exe)"
280 SectionIn 1 3
281
282 SetOutPath $0
283 ReadRegStr $R0 HKLM \
284 "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
285 IfErrors 0 lbl_winnt
Bram Moolenaarba460752013-07-04 22:35:01 +0200286 # Windows 95/98/ME: not supported
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287 Goto lbl_done
288 lbl_winnt:
Bram Moolenaar266411a2013-07-05 20:01:32 +0200289 # Windows NT/2000/XP and later
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290 File /oname=vim.exe ${VIMSRC}\vimw32.exe
291 lbl_done:
292 StrCpy $2 "$2 vim view vimdiff"
293SectionEnd
294
295##########################################################
296Section "Create .bat files for command line use"
297 SectionIn 3
298
299 StrCpy $1 "$1 -create-batfiles $2"
300SectionEnd
301
302##########################################################
303Section "Create icons on the Desktop"
304 SectionIn 1 3
305
306 StrCpy $1 "$1 -install-icons"
307SectionEnd
308
309##########################################################
310Section "Add Vim to the Start Menu"
311 SectionIn 1 3
312
313 StrCpy $1 "$1 -add-start-menu"
314SectionEnd
315
316##########################################################
317Section "Add an Edit-with-Vim context menu entry"
318 SectionIn 1 3
319
320 # Be aware of this sequence of events:
321 # - user uninstalls Vim, gvimext.dll can't be removed (it's in use) and
322 # is scheduled to be removed at next reboot.
323 # - user installs Vim in same directory, gvimext.dll still exists.
324 # If we now skip installing gvimext.dll, it will disappear at the next
325 # reboot. Thus when copying gvimext.dll fails always schedule it to be
326 # installed at the next reboot. Can't use UpgradeDLL!
327 # We don't ask the user to reboot, the old dll will keep on working.
328 SetOutPath $0
329 ClearErrors
330 SetOverwrite try
Bram Moolenaar442b4222010-05-24 21:34:22 +0200331 ${If} ${RunningX64}
332 File /oname=gvimext.dll ${VIMSRC}\GvimExt\gvimext64.dll
333 ${Else}
334 File /oname=gvimext.dll ${VIMSRC}\GvimExt\gvimext.dll
335 ${EndIf}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000336 IfErrors 0 GvimExtDone
337
338 # Can't copy gvimext.dll, create it under another name and rename it on
339 # next reboot.
340 GetTempFileName $3 $0
Bram Moolenaar442b4222010-05-24 21:34:22 +0200341 ${If} ${RunningX64}
342 File /oname=$3 ${VIMSRC}\GvimExt\gvimext64.dll
343 ${Else}
344 File /oname=$3 ${VIMSRC}\GvimExt\gvimext.dll
345 ${EndIf}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346 Rename /REBOOTOK $3 $0\gvimext.dll
347
348 GvimExtDone:
349 SetOverwrite lastused
350
351 # We don't have a separate entry for the "Open With..." menu, assume
352 # the user wants either both or none.
353 StrCpy $1 "$1 -install-popup -install-openwith"
354SectionEnd
355
356##########################################################
357Section "Create a _vimrc if it doesn't exist"
358 SectionIn 1 3
359
360 StrCpy $1 "$1 -create-vimrc"
361SectionEnd
362
363##########################################################
364Section "Create plugin directories in HOME or VIM"
365 SectionIn 1 3
366
367 StrCpy $1 "$1 -create-directories home"
368SectionEnd
369
370##########################################################
371Section "Create plugin directories in VIM"
372 SectionIn 3
373
374 StrCpy $1 "$1 -create-directories vim"
375SectionEnd
376
377##########################################################
378Section "VisVim Extension for MS Visual Studio"
379 SectionIn 3
380
381 SetOutPath $0
382 !insertmacro UpgradeDLL "${VIMSRC}\VisVim\VisVim.dll" "$0\VisVim.dll" "$0"
383 File ${VIMSRC}\VisVim\README_VisVim.txt
384SectionEnd
385
386##########################################################
387!ifdef HAVE_NLS
388 Section "Native Language Support"
389 SectionIn 1 3
390
391 SetOutPath $0\lang
392 File /r ${VIMRT}\lang\*.*
393 SetOutPath $0\keymap
394 File ${VIMRT}\keymap\README.txt
395 File ${VIMRT}\keymap\*.vim
396 SetOutPath $0
Bram Moolenaar286eacd2016-01-16 18:05:50 +0100397 File ${VIMRT}\libintl-8.dll
398 File ${VIMRT}\libiconv-2.dll
399 File /nonfatal ${VIMRT}\libwinpthread-1.dll
Bram Moolenaara54d2fc2017-03-04 20:09:34 +0100400 File /nonfatal ${VIMRT}\libgcc_s_sjlj-1.dll
Bram Moolenaar071d4272004-06-13 20:20:40 +0000401 SectionEnd
402!endif
403
404##########################################################
405Section -call_install_exe
406 SetOutPath $0
407 ExecWait "$0\install.exe $1"
408SectionEnd
409
410##########################################################
411Section -post
412 BringToFront
413SectionEnd
414
415##########################################################
416Section Uninstall
417 # Apparently $INSTDIR is set to the directory where the uninstaller is
418 # created. Thus the "vim61" directory is included in it.
419 StrCpy $0 "$INSTDIR"
420
421 # If VisVim was installed, unregister the DLL.
422 IfFileExists "$0\VisVim.dll" Has_VisVim No_VisVim
423 Has_VisVim:
424 ExecWait "regsvr32.exe /u /s $0\VisVim.dll"
425
426 No_VisVim:
427
428 # delete the context menu entry and batch files
429 ExecWait "$0\uninstal.exe -nsis"
430
431 # We may have been put to the background when uninstall did something.
432 BringToFront
433
434 # ask the user if the Vim version dir must be removed
435 MessageBox MB_YESNO|MB_ICONQUESTION \
436 "Would you like to delete $0?$\n \
437 $\nIt contains the Vim executables and runtime files." IDNO NoRemoveExes
438
439 Delete /REBOOTOK $0\*.dll
440 ClearErrors
441 # Remove everything but *.dll files. Avoids that
442 # a lot remains when gvimext.dll cannot be deleted.
Bram Moolenaar408b5852006-05-13 10:44:07 +0000443 RMDir /r $0\autoload
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444 RMDir /r $0\colors
445 RMDir /r $0\compiler
446 RMDir /r $0\doc
447 RMDir /r $0\ftplugin
448 RMDir /r $0\indent
449 RMDir /r $0\macros
450 RMDir /r $0\plugin
Bram Moolenaar408b5852006-05-13 10:44:07 +0000451 RMDir /r $0\spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452 RMDir /r $0\syntax
453 RMDir /r $0\tools
454 RMDir /r $0\tutor
455 RMDir /r $0\VisVim
456 RMDir /r $0\lang
457 RMDir /r $0\keymap
458 Delete $0\*.exe
459 Delete $0\*.bat
460 Delete $0\*.vim
461 Delete $0\*.txt
462
463 IfErrors ErrorMess NoErrorMess
464 ErrorMess:
465 MessageBox MB_OK|MB_ICONEXCLAMATION \
466 "Some files in $0 have not been deleted!$\nYou must do it manually."
467 NoErrorMess:
468
469 # No error message if the "vim62" directory can't be removed, the
470 # gvimext.dll may still be there.
471 RMDir $0
472
473 NoRemoveExes:
474 # get the parent dir of the installation
475 Push $INSTDIR
476 Call un.GetParent
477 Pop $0
478 StrCpy $1 $0
479
480 # if a plugin dir was created at installation ask the user to remove it
481 # first look in the root of the installation then in HOME
482 IfFileExists $1\vimfiles AskRemove 0
483 ReadEnvStr $1 "HOME"
484 StrCmp $1 "" NoRemove 0
485
486 IfFileExists $1\vimfiles 0 NoRemove
487
488 AskRemove:
489 MessageBox MB_YESNO|MB_ICONQUESTION \
Bram Moolenaare04abda2010-08-01 22:35:43 +0200490 "Remove all files in your $1\vimfiles directory?$\n \
Bram Moolenaar760d14a2010-07-31 22:03:44 +0200491 $\nCAREFUL: If you have created something there that you want to keep, click No" IDNO Fin
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492 RMDir /r $1\vimfiles
493 NoRemove:
494
495 # ask the user if the Vim root dir must be removed
496 MessageBox MB_YESNO|MB_ICONQUESTION \
497 "Would you like to remove $0?$\n \
498 $\nIt contains your Vim configuration files!" IDNO NoDelete
499 RMDir /r $0 ; skipped if no
500 NoDelete:
501
502 Fin:
503 Call un.onUnInstSuccess
504
505SectionEnd