1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
11 * uninstal.c: Minimalistic uninstall program for Vim on MS-Windows
13 * - the "Edit with Vim" popup menu entry
14 * - the Vim "Open With..." popup menu entry
15 * - any Vim Batch files in the path
16 * - icons for Vim on the Desktop
17 * - the Vim entry in the Start Menu
20 /* Include common code for dosinst.c and uninstal.c. */
24 * Return TRUE if the user types a 'y' or 'Y', FALSE otherwise.
32 return (scanf(" %c", answer
) == 1 && toupper(answer
[0]) == 'Y');
37 * Check if the popup menu entry exists and what gvim it refers to.
38 * Returns non-zero when it's found.
41 popup_gvim_path(char *buf
)
45 DWORD bufsize
= BUFSIZE
;
48 /* Open the key where the path to gvim.exe is stored. */
49 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
, "Software\\Vim\\Gvim", 0, KEY_READ
,
50 &key_handle
) != ERROR_SUCCESS
)
53 /* get the DisplayName out of it to show the user */
54 r
= RegQueryValueEx(key_handle
, "path", 0,
55 &value_type
, (LPBYTE
)buf
, &bufsize
);
56 RegCloseKey(key_handle
);
58 return (r
== ERROR_SUCCESS
);
62 * Check if the "Open With..." menu entry exists and what gvim it refers to.
63 * Returns non-zero when it's found.
66 openwith_gvim_path(char *buf
)
70 DWORD bufsize
= BUFSIZE
;
73 /* Open the key where the path to gvim.exe is stored. */
74 if (RegOpenKeyEx(HKEY_CLASSES_ROOT
,
75 "Applications\\gvim.exe\\shell\\edit\\command", 0, KEY_READ
,
76 &key_handle
) != ERROR_SUCCESS
)
79 /* get the DisplayName out of it to show the user */
80 r
= RegQueryValueEx(key_handle
, "", 0, &value_type
, (LPBYTE
)buf
, &bufsize
);
81 RegCloseKey(key_handle
);
83 return (r
== ERROR_SUCCESS
);
92 if (RegDeleteKey(HKEY_CLASSES_ROOT
, "CLSID\\{51EEE242-AD87-11d3-9C1E-0090278BBD99}\\InProcServer32") != ERROR_SUCCESS
)
94 if (RegDeleteKey(HKEY_CLASSES_ROOT
, "CLSID\\{51EEE242-AD87-11d3-9C1E-0090278BBD99}") != ERROR_SUCCESS
)
96 if (RegDeleteKey(HKEY_CLASSES_ROOT
, "*\\shellex\\ContextMenuHandlers\\gvim") != ERROR_SUCCESS
)
98 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", 0, KEY_ALL_ACCESS
, &kh
) != ERROR_SUCCESS
)
102 if (RegDeleteValue(kh
, "{51EEE242-AD87-11d3-9C1E-0090278BBD99}") != ERROR_SUCCESS
)
106 if (RegDeleteKey(HKEY_LOCAL_MACHINE
, "Software\\Vim\\Gvim") != ERROR_SUCCESS
)
108 if (RegDeleteKey(HKEY_LOCAL_MACHINE
, "Software\\Vim") != ERROR_SUCCESS
)
112 printf("No Vim popup registry entries could be removed\n");
114 printf("Some Vim popup registry entries could not be removed\n");
116 printf("The Vim popup registry entries have been removed\n");
120 remove_openwith(void)
124 if (RegDeleteKey(HKEY_CLASSES_ROOT
, "Applications\\gvim.exe\\shell\\edit\\command") != ERROR_SUCCESS
)
126 if (RegDeleteKey(HKEY_CLASSES_ROOT
, "Applications\\gvim.exe\\shell\\edit") != ERROR_SUCCESS
)
128 if (RegDeleteKey(HKEY_CLASSES_ROOT
, "Applications\\gvim.exe\\shell") != ERROR_SUCCESS
)
130 if (RegDeleteKey(HKEY_CLASSES_ROOT
, "Applications\\gvim.exe") != ERROR_SUCCESS
)
132 if (RegDeleteKey(HKEY_CLASSES_ROOT
, ".htm\\OpenWithList\\gvim.exe") != ERROR_SUCCESS
)
134 if (RegDeleteKey(HKEY_CLASSES_ROOT
, ".vim\\OpenWithList\\gvim.exe") != ERROR_SUCCESS
)
136 if (RegDeleteKey(HKEY_CLASSES_ROOT
, "*\\OpenWithList\\gvim.exe") != ERROR_SUCCESS
)
140 printf("No Vim open-with registry entries could be removed\n");
142 printf("Some Vim open-with registry entries could not be removed\n");
144 printf("The Vim open-with registry entries have been removed\n");
149 * Check if a batch file is really for the current version. Don't delete a
150 * batch file that was written for another (possibly newer) version.
153 batfile_thisversion(char *path
)
158 int ver_len
= strlen(VIM_VERSION_NODOT
);
161 fd
= fopen(path
, "r");
164 while (fgets(line
, BUFSIZE
, fd
) != NULL
)
166 for (p
= line
; *p
!= 0; ++p
)
167 /* don't accept "vim60an" when looking for "vim60". */
168 if (strnicmp(p
, VIM_VERSION_NODOT
, ver_len
) == 0
169 && !isdigit(p
[ver_len
])
170 && !isalpha(p
[ver_len
]))
184 remove_batfiles(int doit
)
190 for (i
= 1; i
< TARGET_COUNT
; ++i
)
192 batfile_path
= searchpath_save(targets
[i
].batname
);
193 if (batfile_path
!= NULL
&& batfile_thisversion(batfile_path
))
198 printf("removing %s\n", batfile_path
);
199 remove(batfile_path
);
202 printf(" - the batch file %s\n", batfile_path
);
211 remove_if_exists(char *path
, char *filename
)
216 sprintf(buf
, "%s\\%s", path
, filename
);
218 fd
= fopen(buf
, "r");
222 printf("removing %s\n", buf
);
233 if (get_shell_folder_path(path
, "desktop"))
234 for (i
= 0; i
< ICON_COUNT
; ++i
)
235 remove_if_exists(path
, icon_link_names
[i
]);
239 remove_start_menu(void)
245 if (get_shell_folder_path(path
, VIM_STARTMENU
))
247 for (i
= 1; i
< TARGET_COUNT
; ++i
)
248 remove_if_exists(path
, targets
[i
].lnkname
);
249 remove_if_exists(path
, "uninstall.lnk");
250 remove_if_exists(path
, "Help.lnk");
251 /* Win95 uses .pif, WinNT uses .lnk */
252 remove_if_exists(path
, "Vim tutor.pif");
253 remove_if_exists(path
, "Vim tutor.lnk");
254 remove_if_exists(path
, "Vim online.url");
255 if (stat(path
, &st
) == 0)
257 printf("removing %s\n", path
);
264 #if 0 /* currently not used */
266 * Return TRUE when we're on Windows 95/98/ME.
271 static int done
= FALSE
;
272 static DWORD PlatformId
;
278 ovi
.dwOSVersionInfoSize
= sizeof(ovi
);
280 PlatformId
= ovi
.dwPlatformId
;
283 /* Win NT/2000/XP is VER_PLATFORM_WIN32_NT */
284 return PlatformId
== VER_PLATFORM_WIN32_WINDOWS
;
289 delete_uninstall_key(void)
292 RegDeleteKey(HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Vim " VIM_VERSION_SHORT
);
298 * On DJGPP we delete registry entries by creating a .inf file and
301 fd
= fopen("vim.inf", "w");
304 fprintf(fd
, "[version]\n");
305 fprintf(fd
, "signature=\"$CHICAGO$\"\n\n");
306 fprintf(fd
, "[DefaultInstall]\n");
307 fprintf(fd
, "DelReg=DeleteMe\n\n");
308 fprintf(fd
, "[DeleteMe]\n");
309 fprintf(fd
, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Vim " VIM_VERSION_SHORT
"\"\n");
312 /* Don't know how to detect Win NT with DJGPP. Hack: Just try the Win
313 * 95/98/ME method, since the DJGPP version can't use long filenames
314 * on Win NT anyway. */
315 sprintf(buf
, "rundll setupx.dll,InstallHinfSection DefaultInstall 132 %s\\vim.inf", installdir
);
318 /* Windows NT method (untested). */
319 sprintf(buf
, "rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128 %s\\vim.inf", installdir
);
329 main(int argc
, char *argv
[])
338 char popup_path
[BUFSIZE
];
340 /* The nsis uninstaller calls us with a "-nsis" argument. */
341 if (argc
== 2 && stricmp(argv
[1], "-nsis") == 0)
347 /* Initialize this program. */
350 printf("This program will remove the following items:\n");
353 if (popup_gvim_path(popup_path
))
355 printf(" - the \"Edit with Vim\" entry in the popup menu\n");
356 printf(" which uses \"%s\"\n", popup_path
);
357 printf("\nRemove it (y/n)? ");
361 /* Assume the "Open With" entry can be removed as well, don't
362 * bother the user with asking him again. */
366 else if (openwith_gvim_path(popup_path
))
368 printf(" - the Vim \"Open With...\" entry in the popup menu\n");
369 printf(" which uses \"%s\"\n", popup_path
);
370 printf("\nRemove it (y/n)? ");
375 if (get_shell_folder_path(path
, "desktop"))
378 for (i
= 0; i
< ICON_COUNT
; ++i
)
380 sprintf(icon
, "%s\\%s", path
, icon_link_names
[i
]);
381 if (stat(icon
, &st
) == 0)
383 printf(" - the \"%s\" icon on the desktop\n", icon_names
[i
]);
390 printf("\nRemove %s (y/n)? ", found
> 1 ? "them" : "it");
391 if (!interactive
|| confirm())
396 if (get_shell_folder_path(path
, VIM_STARTMENU
)
397 && stat(path
, &st
) == 0)
399 printf("\n - the \"%s\" entry in the Start Menu\n", VIM_STARTMENU
);
401 printf("\nRemove it (y/n)? ");
402 if (!interactive
|| confirm())
408 found
= remove_batfiles(0);
412 printf("\nRemove %s (y/n)? ", found
> 1 ? "them" : "it");
413 if (!interactive
|| confirm())
417 fd
= fopen("gvim.exe", "r");
421 printf("gvim.exe detected. Attempting to unregister gvim with OLE\n");
422 system("gvim.exe -silent -unregister");
425 delete_uninstall_key();
429 printf("\nYou may now want to delete the Vim executables and runtime files.\n");
430 printf("(They are still where you unpacked them.)\n");
434 printf("\nPress Enter to exit...");