comparison src/dosinst.c @ 2220:b1c70c500de4 vim73

Found a way to make the MS-Windows installer wait for the uninstaller to finish, no need for the user to press Enter.
author Bram Moolenaar <bram@vim.org>
date Tue, 25 May 2010 21:02:00 +0200
parents 120502692d82
children 144aa6167799
comparison
equal deleted inserted replaced
2219:c81f0a037059 2220:b1c70c500de4
442 else 442 else
443 { 443 {
444 printf("Failed to open %s\n", fname); 444 printf("Failed to open %s\n", fname);
445 Sleep(2000); 445 Sleep(2000);
446 } 446 }
447 }
448
449 static int num_windows;
450
451 /*
452 * Callback used for EnumWindows():
453 * Count the window if the title looks like it is for the uninstaller.
454 */
455 /*ARGSUSED*/
456 static BOOL CALLBACK
457 window_cb(HWND hwnd, LPARAM lparam)
458 {
459 char title[256];
460
461 title[0] = 0;
462 GetWindowText(hwnd, title, 256);
463 if (strstr(title, "Vim ") != NULL && strstr(title, "Uninstall:") != NULL)
464 ++num_windows;
465 return TRUE;
447 } 466 }
448 467
449 /* 468 /*
450 * Check for already installed Vims. 469 * Check for already installed Vims.
451 * Return non-zero when found one. 470 * Return non-zero when found one.
541 * it changed */ 560 * it changed */
542 RegQueryInfoKey(key_handle, NULL, NULL, NULL, 561 RegQueryInfoKey(key_handle, NULL, NULL, NULL,
543 &orig_num_keys, NULL, NULL, NULL, 562 &orig_num_keys, NULL, NULL, NULL,
544 NULL, NULL, NULL, NULL); 563 NULL, NULL, NULL, NULL);
545 564
546 #if 0 /* let the uninstall program delete the key */
547 /* Delete the uninstall key. It has no subkeys, so
548 * this is easy. Do this before uninstalling, that
549 * may try to delete the key as well. */
550 RegDeleteKey(key_handle, subkey_name_buff);
551 #endif
552
553 /* Find existing .bat files before deleting them. */ 565 /* Find existing .bat files before deleting them. */
554 find_bat_exe(TRUE); 566 find_bat_exe(TRUE);
555 567
556 /* Execute the uninstall program. Put it in double 568 /* Execute the uninstall program. Put it in double
557 * quotes if there is an embedded space. */ 569 * quotes if there is an embedded space. */
558 if (strchr(temp_string_buffer, ' ') != NULL)
559 { 570 {
560 char buf[BUFSIZE]; 571 char buf[BUFSIZE];
561 572
562 strcpy(buf, temp_string_buffer); 573 if (strchr(temp_string_buffer, ' ') != NULL)
563 sprintf(temp_string_buffer, "\"%s\"", buf); 574 sprintf(buf, "\"%s\"", temp_string_buffer);
575 else
576 strcpy(buf, temp_string_buffer);
577 run_command(buf);
564 } 578 }
565 run_command(temp_string_buffer); 579
580 /* Count the number of windows with a title that match
581 * the installer, so that we can check when it's done.
582 * The uninstaller copies itself, executes the copy
583 * and exits, thus we can't wait for the process to
584 * finish. */
585 Sleep(1000); /* wait for uninstaller to start up */
586 num_windows = 0;
587 EnumWindows(window_cb, 0);
588 Sleep(1000); /* wait for windows to be counted */
589 if (num_windows == 0)
590 {
591 /* Did not find the uninstaller, ask user to press
592 * Enter when done. Just in case. */
593 printf("Press Enter when the uninstaller is finished\n");
594 rewind(stdin);
595 (void)getchar();
596 }
597 else
598 {
599 printf("Waiting for the uninstaller to finish (press CTRL-C to abort).");
600 do
601 {
602 printf(".");
603 fflush(stdout);
604 num_windows = 0;
605 EnumWindows(window_cb, 0);
606 Sleep(1000); /* wait for windows to be counted */
607 } while (num_windows > 0);
608 }
609 printf("\nDone!\n");
566 610
567 /* Check if an uninstall reg key was deleted. 611 /* Check if an uninstall reg key was deleted.
568 * if it was, we want to decrement key_index. 612 * if it was, we want to decrement key_index.
569 * if we don't do this, we will skip the key 613 * if we don't do this, we will skip the key
570 * immediately after any key that we delete. */ 614 * immediately after any key that we delete. */
2391 /* Find the value of $VIM, because NSIS isn't able to do this by 2435 /* Find the value of $VIM, because NSIS isn't able to do this by
2392 * itself. */ 2436 * itself. */
2393 get_vim_env(); 2437 get_vim_env();
2394 2438
2395 /* When nothing found exit quietly. If something found wait for 2439 /* When nothing found exit quietly. If something found wait for
2396 * hitting Enter. 2440 * a little while, so that the user can read the messages. */
2397 * We would like to exit without hitting Enter, but the uninstaller
2398 * detaches itself, thus we get here before it's finished. */
2399 if (i) 2441 if (i)
2400 { 2442 Sleep(3000);
2401 printf("\n");
2402 printf("When the uninstall program is finished, press Enter to continue\n");
2403 rewind(stdin);
2404 (void)getchar();
2405 }
2406 exit(0); 2443 exit(0);
2407 } 2444 }
2408 #endif 2445 #endif
2409 2446
2410 printf("This program sets up the installation of Vim " 2447 printf("This program sets up the installation of Vim "