comparison src/dosinst.c @ 14921:b2308693cb87 v8.1.0472

patch 8.1.0472: dosinst command has a few flaws commit https://github.com/vim/vim/commit/6cdb2c9811c33dbd312a5a2b711ee83f512ae7b2 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 13 17:25:27 2018 +0200 patch 8.1.0472: dosinst command has a few flaws Problem: Dosinst command has a few flaws. Solution: Register DisplayIcon, DisplayVersion and Publisher for the uninstaller. (closes #3485) Don't set 'diffexpr' if internal diff is supported. Allow for using Vi compatible from the command line. Remove needless sleeps. Add comments in the generated _vimrc. (Ken Takata, closes #3525)
author Bram Moolenaar <Bram@vim.org>
date Sat, 13 Oct 2018 17:30:05 +0200
parents 43de18e870c4
children c1be7c8bb602
comparison
equal deleted inserted replaced
14920:1a2b8e0e9eb2 14921:b2308693cb87
16 /* 16 /*
17 * Include common code for dosinst.c and uninstal.c. 17 * Include common code for dosinst.c and uninstal.c.
18 */ 18 */
19 #define DOSINST 19 #define DOSINST
20 #include "dosinst.h" 20 #include "dosinst.h"
21 #include <io.h>
21 22
22 #define GVIMEXT64_PATH "GvimExt64\\gvimext.dll" 23 #define GVIMEXT64_PATH "GvimExt64\\gvimext.dll"
23 #define GVIMEXT32_PATH "GvimExt32\\gvimext.dll" 24 #define GVIMEXT32_PATH "GvimExt32\\gvimext.dll"
24 25
25 /* Macro to do an error check I was typing over and over */ 26 /* Macro to do an error check I was typing over and over */
61 #define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s)) 62 #define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s))
62 63
63 enum 64 enum
64 { 65 {
65 compat_vi = 1, 66 compat_vi = 1,
67 compat_vim,
66 compat_some_enhancements, 68 compat_some_enhancements,
67 compat_all_enhancements 69 compat_all_enhancements
68 }; 70 };
69 char *(compat_choices[]) = 71 char *(compat_choices[]) =
70 { 72 {
71 "\nChoose the default way to run Vim:", 73 "\nChoose the default way to run Vim:",
72 "Vi compatible", 74 "Vi compatible",
75 "Vim default",
73 "with some Vim enhancements", 76 "with some Vim enhancements",
74 "with syntax highlighting and other features switched on", 77 "with syntax highlighting and other features switched on",
75 }; 78 };
76 int compat_choice = (int)compat_all_enhancements; 79 int compat_choice = (int)compat_all_enhancements;
77 char *compat_text = "- run Vim %s"; 80 char *compat_text = "- run Vim %s";
565 * and exits, thus we can't wait for the process to 568 * and exits, thus we can't wait for the process to
566 * finish. */ 569 * finish. */
567 sleep(1); /* wait for uninstaller to start up */ 570 sleep(1); /* wait for uninstaller to start up */
568 num_windows = 0; 571 num_windows = 0;
569 EnumWindows(window_cb, 0); 572 EnumWindows(window_cb, 0);
570 sleep(1); /* wait for windows to be counted */
571 if (num_windows == 0) 573 if (num_windows == 0)
572 { 574 {
573 /* Did not find the uninstaller, ask user to press 575 /* Did not find the uninstaller, ask user to press
574 * Enter when done. Just in case. */ 576 * Enter when done. Just in case. */
575 printf("Press Enter when the uninstaller is finished\n"); 577 printf("Press Enter when the uninstaller is finished\n");
581 printf("Waiting for the uninstaller to finish (press CTRL-C to abort)."); 583 printf("Waiting for the uninstaller to finish (press CTRL-C to abort).");
582 do 584 do
583 { 585 {
584 printf("."); 586 printf(".");
585 fflush(stdout); 587 fflush(stdout);
588 sleep(1); /* wait for the uninstaller to finish */
586 num_windows = 0; 589 num_windows = 0;
587 EnumWindows(window_cb, 0); 590 EnumWindows(window_cb, 0);
588 sleep(1); /* wait for windows to be counted */
589 } while (num_windows > 0); 591 } while (num_windows > 0);
590 } 592 }
591 printf("\nDone!\n"); 593 printf("\nDone!\n");
592 594
593 /* Check if an uninstall reg key was deleted. 595 /* Check if an uninstall reg key was deleted.
1157 return; 1159 return;
1158 } 1160 }
1159 switch (compat_choice) 1161 switch (compat_choice)
1160 { 1162 {
1161 case compat_vi: 1163 case compat_vi:
1164 fprintf(fd, "\" Vi compatible\n");
1162 fprintf(fd, "set compatible\n"); 1165 fprintf(fd, "set compatible\n");
1163 break; 1166 break;
1167 case compat_vim:
1168 fprintf(fd, "\" Vim's default behavior\n");
1169 fprintf(fd, "if &compatible\n");
1170 fprintf(fd, " set nocompatible\n");
1171 fprintf(fd, "endif\n");
1172 break;
1164 case compat_some_enhancements: 1173 case compat_some_enhancements:
1174 fprintf(fd, "\" Vim with some enhancements\n");
1165 fprintf(fd, "source $VIMRUNTIME/defaults.vim\n"); 1175 fprintf(fd, "source $VIMRUNTIME/defaults.vim\n");
1166 break; 1176 break;
1167 case compat_all_enhancements: 1177 case compat_all_enhancements:
1178 fprintf(fd, "\" Vim with all enhancements\n");
1168 fprintf(fd, "source $VIMRUNTIME/vimrc_example.vim\n"); 1179 fprintf(fd, "source $VIMRUNTIME/vimrc_example.vim\n");
1169 break; 1180 break;
1170 } 1181 }
1171 switch (remap_choice) 1182 switch (remap_choice)
1172 { 1183 {
1173 case remap_no: 1184 case remap_no:
1174 break; 1185 break;
1175 case remap_win: 1186 case remap_win:
1187 fprintf(fd, "\n");
1188 fprintf(fd, "\" Remap a few keys for Windows behavior\n");
1176 fprintf(fd, "source $VIMRUNTIME/mswin.vim\n"); 1189 fprintf(fd, "source $VIMRUNTIME/mswin.vim\n");
1177 break; 1190 break;
1178 } 1191 }
1179 switch (mouse_choice) 1192 switch (mouse_choice)
1180 { 1193 {
1181 case mouse_xterm: 1194 case mouse_xterm:
1195 fprintf(fd, "\n");
1196 fprintf(fd, "\" Mouse behavior (the Unix way)\n");
1182 fprintf(fd, "behave xterm\n"); 1197 fprintf(fd, "behave xterm\n");
1183 break; 1198 break;
1184 case mouse_mswin: 1199 case mouse_mswin:
1200 fprintf(fd, "\n");
1201 fprintf(fd, "\" Mouse behavior (the Windows way)\n");
1185 fprintf(fd, "behave mswin\n"); 1202 fprintf(fd, "behave mswin\n");
1186 break; 1203 break;
1187 case mouse_default: 1204 case mouse_default:
1188 break; 1205 break;
1189 } 1206 }
1190 if ((tfd = fopen("diff.exe", "r")) != NULL) 1207 if ((tfd = fopen("diff.exe", "r")) != NULL)
1191 { 1208 {
1192 /* Use the diff.exe that comes with the self-extracting gvim.exe. */ 1209 /* Use the diff.exe that comes with the self-extracting gvim.exe. */
1193 fclose(tfd); 1210 fclose(tfd);
1194 fprintf(fd, "\n"); 1211 fprintf(fd, "\n");
1195 fprintf(fd, "set diffexpr=MyDiff()\n"); 1212 fprintf(fd, "\" Use the internal diff if available.\n");
1213 fprintf(fd, "\" Otherwise use the special 'diffexpr' for Windows.\n");
1214 fprintf(fd, "if &diffopt !~# 'internal'\n");
1215 fprintf(fd, " set diffexpr=MyDiff()\n");
1216 fprintf(fd, "endif\n");
1196 fprintf(fd, "function MyDiff()\n"); 1217 fprintf(fd, "function MyDiff()\n");
1197 fprintf(fd, " let opt = '-a --binary '\n"); 1218 fprintf(fd, " let opt = '-a --binary '\n");
1198 fprintf(fd, " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif\n"); 1219 fprintf(fd, " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif\n");
1199 fprintf(fd, " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif\n"); 1220 fprintf(fd, " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif\n");
1200 /* Use quotes only when needed, they may cause trouble. 1221 /* Use quotes only when needed, they may cause trouble.
1489 static LONG 1510 static LONG
1490 register_uninstall( 1511 register_uninstall(
1491 HKEY hRootKey, 1512 HKEY hRootKey,
1492 const char *appname, 1513 const char *appname,
1493 const char *display_name, 1514 const char *display_name,
1494 const char *uninstall_string) 1515 const char *uninstall_string,
1516 const char *display_icon,
1517 const char *display_version,
1518 const char *publisher)
1495 { 1519 {
1496 LONG lRet = reg_create_key_and_value(hRootKey, appname, 1520 LONG lRet = reg_create_key_and_value(hRootKey, appname,
1497 "DisplayName", display_name, KEY_WOW64_64KEY); 1521 "DisplayName", display_name, KEY_WOW64_64KEY);
1498 1522
1499 if (ERROR_SUCCESS == lRet) 1523 if (ERROR_SUCCESS == lRet)
1500 lRet = reg_create_key_and_value(hRootKey, appname, 1524 lRet = reg_create_key_and_value(hRootKey, appname,
1501 "UninstallString", uninstall_string, KEY_WOW64_64KEY); 1525 "UninstallString", uninstall_string, KEY_WOW64_64KEY);
1526 if (ERROR_SUCCESS == lRet)
1527 lRet = reg_create_key_and_value(hRootKey, appname,
1528 "DisplayIcon", display_icon, KEY_WOW64_64KEY);
1529 if (ERROR_SUCCESS == lRet)
1530 lRet = reg_create_key_and_value(hRootKey, appname,
1531 "DisplayVersion", display_version, KEY_WOW64_64KEY);
1532 if (ERROR_SUCCESS == lRet)
1533 lRet = reg_create_key_and_value(hRootKey, appname,
1534 "Publisher", publisher, KEY_WOW64_64KEY);
1502 return lRet; 1535 return lRet;
1503 } 1536 }
1504 1537
1505 /* 1538 /*
1506 * Add some entries to the registry: 1539 * Add some entries to the registry:
1517 const char *vim_ext_name = "Vim Shell Extension"; 1550 const char *vim_ext_name = "Vim Shell Extension";
1518 const char *vim_ext_clsid = "{51EEE242-AD87-11d3-9C1E-0090278BBD99}"; 1551 const char *vim_ext_clsid = "{51EEE242-AD87-11d3-9C1E-0090278BBD99}";
1519 char vim_exe_path[BUFSIZE]; 1552 char vim_exe_path[BUFSIZE];
1520 char display_name[BUFSIZE]; 1553 char display_name[BUFSIZE];
1521 char uninstall_string[BUFSIZE]; 1554 char uninstall_string[BUFSIZE];
1555 char icon_string[BUFSIZE];
1522 int i; 1556 int i;
1523 int loop_count = is_64bit_os() ? 2 : 1; 1557 int loop_count = is_64bit_os() ? 2 : 1;
1524 DWORD flag; 1558 DWORD flag;
1525 1559
1526 sprintf(vim_exe_path, "%s\\gvim.exe", installdir); 1560 sprintf(vim_exe_path, "%s\\gvim.exe", installdir);
1581 if (interactive) 1615 if (interactive)
1582 sprintf(uninstall_string, "%s\\uninstal.exe", installdir); 1616 sprintf(uninstall_string, "%s\\uninstal.exe", installdir);
1583 else 1617 else
1584 sprintf(uninstall_string, "%s\\uninstall-gui.exe", installdir); 1618 sprintf(uninstall_string, "%s\\uninstall-gui.exe", installdir);
1585 1619
1620 sprintf(icon_string, "%s\\gvim.exe,0", installdir);
1621
1586 lRet = register_uninstall( 1622 lRet = register_uninstall(
1587 HKEY_LOCAL_MACHINE, 1623 HKEY_LOCAL_MACHINE,
1588 "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Vim " VIM_VERSION_SHORT, 1624 "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Vim " VIM_VERSION_SHORT,
1589 display_name, 1625 display_name,
1590 uninstall_string); 1626 uninstall_string,
1627 icon_string,
1628 VIM_VERSION_SHORT,
1629 "Bram Moolenaar et al.");
1591 if (ERROR_SUCCESS != lRet) 1630 if (ERROR_SUCCESS != lRet)
1592 return FAIL; 1631 return FAIL;
1593 1632
1594 return OK; 1633 return OK;
1595 } 1634 }
2217 printf(" Create a default _vimrc file if one does not already exist.\n"); 2256 printf(" Create a default _vimrc file if one does not already exist.\n");
2218 printf("-vimrc-remap [no|win]\n"); 2257 printf("-vimrc-remap [no|win]\n");
2219 printf(" Remap keys when creating a default _vimrc file.\n"); 2258 printf(" Remap keys when creating a default _vimrc file.\n");
2220 printf("-vimrc-behave [unix|mswin|default]\n"); 2259 printf("-vimrc-behave [unix|mswin|default]\n");
2221 printf(" Set mouse behavior when creating a default _vimrc file.\n"); 2260 printf(" Set mouse behavior when creating a default _vimrc file.\n");
2261 printf("-vimrc-compat [vi|vim|defaults|all]\n");
2262 printf(" Set Vi compatibility when creating a default _vimrc file.\n");
2222 printf("-install-popup\n"); 2263 printf("-install-popup\n");
2223 printf(" Install the Edit-with-Vim context menu entry\n"); 2264 printf(" Install the Edit-with-Vim context menu entry\n");
2224 printf("-install-openwith\n"); 2265 printf("-install-openwith\n");
2225 printf(" Add Vim to the \"Open With...\" context menu list\n"); 2266 printf(" Add Vim to the \"Open With...\" context menu list\n");
2226 printf("-add-start-menu"); 2267 printf("-add-start-menu");
2293 mouse_choice = mouse_xterm; 2334 mouse_choice = mouse_xterm;
2294 else if (strcmp(argv[i], "mswin") == 0) 2335 else if (strcmp(argv[i], "mswin") == 0)
2295 mouse_choice = mouse_mswin; 2336 mouse_choice = mouse_mswin;
2296 else if (strcmp(argv[i], "default") == 0) 2337 else if (strcmp(argv[i], "default") == 0)
2297 mouse_choice = mouse_default; 2338 mouse_choice = mouse_default;
2339 }
2340 else if (strcmp(argv[i], "-vimrc-compat") == 0)
2341 {
2342 if (i + 1 == argc)
2343 break;
2344 i++;
2345 if (strcmp(argv[i], "vi") == 0)
2346 compat_choice = compat_vi;
2347 else if (strcmp(argv[i], "vim") == 0)
2348 compat_choice = compat_vim;
2349 else if (strcmp(argv[i], "defaults") == 0)
2350 compat_choice = compat_some_enhancements;
2351 else if (strcmp(argv[i], "all") == 0)
2352 compat_choice = compat_all_enhancements;
2298 } 2353 }
2299 else if (strcmp(argv[i], "-install-popup") == 0) 2354 else if (strcmp(argv[i], "-install-popup") == 0)
2300 { 2355 {
2301 init_popup_choice(); 2356 init_popup_choice();
2302 } 2357 }
2544 * itself. */ 2599 * itself. */
2545 get_vim_env(); 2600 get_vim_env();
2546 2601
2547 /* When nothing found exit quietly. If something found wait for 2602 /* When nothing found exit quietly. If something found wait for
2548 * a little while, so that the user can read the messages. */ 2603 * a little while, so that the user can read the messages. */
2549 if (i) 2604 if (i && _isatty(1))
2550 sleep(3); 2605 sleep(3);
2551 exit(0); 2606 exit(0);
2552 } 2607 }
2553 2608
2554 printf("This program sets up the installation of Vim " 2609 printf("This program sets up the installation of Vim "