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