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