Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * |
| 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. |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * dosinst.c: Install program for Vim on MS-DOS and MS-Windows |
| 12 | * |
| 13 | * Compile with Make_mvc.mak, Make_bc3.mak, Make_bc5.mak or Make_djg.mak. |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * Include common code for dosinst.c and uninstal.c. |
| 18 | */ |
| 19 | #define DOSINST |
| 20 | #include "dosinst.h" |
| 21 | |
| 22 | /* Macro to do an error check I was typing over and over */ |
| 23 | #define CHECK_REG_ERROR(code) if (code != ERROR_SUCCESS) { printf("%ld error number: %ld\n", (long)__LINE__, (long)code); return 1; } |
| 24 | |
| 25 | int has_vim = 0; /* installable vim.exe exists */ |
| 26 | int has_gvim = 0; /* installable gvim.exe exists */ |
| 27 | |
| 28 | char oldvimrc[BUFSIZE]; /* name of existing vimrc file */ |
| 29 | char vimrc[BUFSIZE]; /* name of vimrc file to create */ |
| 30 | |
| 31 | char *default_bat_dir = NULL; /* when not NULL, use this as the default |
| 32 | directory to write .bat files in */ |
| 33 | char *default_vim_dir = NULL; /* when not NULL, use this as the default |
| 34 | install dir for NSIS */ |
| 35 | #if 0 |
| 36 | char homedir[BUFSIZE]; /* home directory or "" */ |
| 37 | #endif |
| 38 | |
| 39 | /* |
| 40 | * Structure used for each choice the user can make. |
| 41 | */ |
| 42 | struct choice |
| 43 | { |
| 44 | int active; /* non-zero when choice is active */ |
| 45 | char *text; /* text displayed for this choice */ |
| 46 | void (*changefunc)(int idx); /* function to change this choice */ |
| 47 | int arg; /* argument for function */ |
| 48 | void (*installfunc)(int idx); /* function to install this choice */ |
| 49 | }; |
| 50 | |
| 51 | struct choice choices[30]; /* choices the user can make */ |
| 52 | int choice_count = 0; /* number of choices available */ |
| 53 | |
| 54 | #define TABLE_SIZE(s) (int)(sizeof(s) / sizeof(*s)) |
| 55 | |
| 56 | enum |
| 57 | { |
| 58 | compat_vi = 1, |
| 59 | compat_some_enhancements, |
| 60 | compat_all_enhancements |
| 61 | }; |
| 62 | char *(compat_choices[]) = |
| 63 | { |
| 64 | "\nChoose the default way to run Vim:", |
| 65 | "Vi compatible", |
Bram Moolenaar | fff2bee | 2010-05-15 13:56:02 +0200 | [diff] [blame] | 66 | "with some Vim enhancements", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 67 | "with syntax highlighting and other features switched on", |
| 68 | }; |
| 69 | int compat_choice = (int)compat_all_enhancements; |
| 70 | char *compat_text = "- run Vim %s"; |
| 71 | |
| 72 | enum |
| 73 | { |
| 74 | remap_no = 1, |
| 75 | remap_win |
| 76 | }; |
| 77 | char *(remap_choices[]) = |
| 78 | { |
| 79 | "\nChoose:", |
| 80 | "Do not remap keys for Windows behavior", |
| 81 | "Remap a few keys for Windows behavior (<C-V>, <C-C>, etc)", |
| 82 | }; |
| 83 | int remap_choice = (int)remap_win; |
| 84 | char *remap_text = "- %s"; |
| 85 | |
| 86 | enum |
| 87 | { |
| 88 | mouse_xterm = 1, |
| 89 | mouse_mswin |
| 90 | }; |
| 91 | char *(mouse_choices[]) = |
| 92 | { |
| 93 | "\nChoose the way how Vim uses the mouse:", |
| 94 | "right button extends selection (the Unix way)", |
| 95 | "right button has a popup menu (the Windows way)", |
| 96 | }; |
| 97 | int mouse_choice = (int)mouse_mswin; |
| 98 | char *mouse_text = "- The mouse %s"; |
| 99 | |
| 100 | enum |
| 101 | { |
| 102 | vimfiles_dir_none = 1, |
| 103 | vimfiles_dir_vim, |
| 104 | vimfiles_dir_home |
| 105 | }; |
| 106 | static char *(vimfiles_dir_choices[]) = |
| 107 | { |
| 108 | "\nCreate plugin directories:", |
| 109 | "No", |
| 110 | "In the VIM directory", |
| 111 | "In your HOME directory", |
| 112 | }; |
| 113 | static int vimfiles_dir_choice; |
| 114 | |
| 115 | /* non-zero when selected to install the popup menu entry. */ |
| 116 | static int install_popup = 0; |
| 117 | |
| 118 | /* non-zero when selected to install the "Open with" entry. */ |
| 119 | static int install_openwith = 0; |
| 120 | |
| 121 | /* non-zero when need to add an uninstall entry in the registry */ |
| 122 | static int need_uninstall_entry = 0; |
| 123 | |
| 124 | /* |
| 125 | * Definitions of the directory name (under $VIM) of the vimfiles directory |
| 126 | * and its subdirectories: |
| 127 | */ |
| 128 | static char *(vimfiles_subdirs[]) = |
| 129 | { |
| 130 | "colors", |
| 131 | "compiler", |
| 132 | "doc", |
| 133 | "ftdetect", |
| 134 | "ftplugin", |
| 135 | "indent", |
| 136 | "keymap", |
| 137 | "plugin", |
| 138 | "syntax", |
| 139 | }; |
| 140 | |
| 141 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 142 | * Obtain a choice from a table. |
| 143 | * First entry is a question, others are choices. |
| 144 | */ |
| 145 | static int |
| 146 | get_choice(char **table, int entries) |
| 147 | { |
| 148 | int answer; |
| 149 | int idx; |
| 150 | char dummy[100]; |
| 151 | |
| 152 | do |
| 153 | { |
| 154 | for (idx = 0; idx < entries; ++idx) |
| 155 | { |
| 156 | if (idx) |
| 157 | printf("%2d ", idx); |
| 158 | printf(table[idx]); |
| 159 | printf("\n"); |
| 160 | } |
| 161 | printf("Choice: "); |
| 162 | if (scanf("%d", &answer) != 1) |
| 163 | { |
| 164 | scanf("%99s", dummy); |
| 165 | answer = 0; |
| 166 | } |
| 167 | } |
| 168 | while (answer < 1 || answer >= entries); |
| 169 | |
| 170 | return answer; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Check if the user unpacked the archives properly. |
| 175 | * Sets "runtimeidx". |
| 176 | */ |
| 177 | static void |
| 178 | check_unpack(void) |
| 179 | { |
| 180 | char buf[BUFSIZE]; |
| 181 | FILE *fd; |
| 182 | struct stat st; |
| 183 | |
| 184 | /* check for presence of the correct version number in installdir[] */ |
| 185 | runtimeidx = strlen(installdir) - strlen(VIM_VERSION_NODOT); |
| 186 | if (runtimeidx <= 0 |
| 187 | || stricmp(installdir + runtimeidx, VIM_VERSION_NODOT) != 0 |
| 188 | || (installdir[runtimeidx - 1] != '/' |
| 189 | && installdir[runtimeidx - 1] != '\\')) |
| 190 | { |
| 191 | printf("ERROR: Install program not in directory \"%s\"\n", |
| 192 | VIM_VERSION_NODOT); |
| 193 | printf("This program can only work when it is located in its original directory\n"); |
| 194 | myexit(1); |
| 195 | } |
| 196 | |
| 197 | /* check if filetype.vim is present, which means the runtime archive has |
| 198 | * been unpacked */ |
| 199 | sprintf(buf, "%s\\filetype.vim", installdir); |
| 200 | if (stat(buf, &st) < 0) |
| 201 | { |
| 202 | printf("ERROR: Cannot find filetype.vim in \"%s\"\n", installdir); |
| 203 | printf("It looks like you did not unpack the runtime archive.\n"); |
| 204 | printf("You must unpack the runtime archive \"vim%srt.zip\" before installing.\n", |
| 205 | VIM_VERSION_NODOT + 3); |
| 206 | myexit(1); |
| 207 | } |
| 208 | |
| 209 | /* Check if vim.exe or gvim.exe is in the current directory. */ |
| 210 | if ((fd = fopen("gvim.exe", "r")) != NULL) |
| 211 | { |
| 212 | fclose(fd); |
| 213 | has_gvim = 1; |
| 214 | } |
| 215 | if ((fd = fopen("vim.exe", "r")) != NULL) |
| 216 | { |
| 217 | fclose(fd); |
| 218 | has_vim = 1; |
| 219 | } |
| 220 | if (!has_gvim && !has_vim) |
| 221 | { |
| 222 | printf("ERROR: Cannot find any Vim executables in \"%s\"\n\n", |
| 223 | installdir); |
| 224 | myexit(1); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * Compare paths "p[plen]" to "q[qlen]". Return 0 if they match. |
| 230 | * Ignores case and differences between '/' and '\'. |
| 231 | * "plen" and "qlen" can be negative, strlen() is used then. |
| 232 | */ |
| 233 | static int |
| 234 | pathcmp(char *p, int plen, char *q, int qlen) |
| 235 | { |
| 236 | int i; |
| 237 | |
| 238 | if (plen < 0) |
| 239 | plen = strlen(p); |
| 240 | if (qlen < 0) |
| 241 | qlen = strlen(q); |
| 242 | for (i = 0; ; ++i) |
| 243 | { |
| 244 | /* End of "p": check if "q" also ends or just has a slash. */ |
| 245 | if (i == plen) |
| 246 | { |
| 247 | if (i == qlen) /* match */ |
| 248 | return 0; |
| 249 | if (i == qlen - 1 && (q[i] == '\\' || q[i] == '/')) |
| 250 | return 0; /* match with trailing slash */ |
| 251 | return 1; /* no match */ |
| 252 | } |
| 253 | |
| 254 | /* End of "q": check if "p" also ends or just has a slash. */ |
| 255 | if (i == qlen) |
| 256 | { |
| 257 | if (i == plen) /* match */ |
| 258 | return 0; |
| 259 | if (i == plen - 1 && (p[i] == '\\' || p[i] == '/')) |
| 260 | return 0; /* match with trailing slash */ |
| 261 | return 1; /* no match */ |
| 262 | } |
| 263 | |
| 264 | if (!(mytoupper(p[i]) == mytoupper(q[i]) |
| 265 | || ((p[i] == '/' || p[i] == '\\') |
| 266 | && (q[i] == '/' || q[i] == '\\')))) |
| 267 | return 1; /* no match */ |
| 268 | } |
| 269 | /*NOTREACHED*/ |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * If the executable "**destination" is in the install directory, find another |
| 274 | * one in $PATH. |
| 275 | * On input "**destination" is the path of an executable in allocated memory |
| 276 | * (or NULL). |
| 277 | * "*destination" is set to NULL or the location of the file. |
| 278 | */ |
| 279 | static void |
| 280 | findoldfile(char **destination) |
| 281 | { |
| 282 | char *bp = *destination; |
| 283 | size_t indir_l = strlen(installdir); |
| 284 | char *cp = bp + indir_l; |
| 285 | char *tmpname; |
| 286 | char *farname; |
| 287 | |
| 288 | /* |
| 289 | * No action needed if exe not found or not in this directory. |
| 290 | */ |
| 291 | if (bp == NULL |
| 292 | || strnicmp(bp, installdir, indir_l) != 0 |
| 293 | || strchr("/\\", *cp++) == NULL |
| 294 | || strchr(cp, '\\') != NULL |
| 295 | || strchr(cp, '/') != NULL) |
| 296 | return; |
| 297 | |
| 298 | tmpname = alloc((int)strlen(cp) + 1); |
| 299 | strcpy(tmpname, cp); |
| 300 | tmpname[strlen(tmpname) - 1] = 'x'; /* .exe -> .exx */ |
| 301 | |
| 302 | if (access(tmpname, 0) == 0) |
| 303 | { |
| 304 | printf("\nERROR: %s and %s clash. Remove or rename %s.\n", |
| 305 | tmpname, cp, tmpname); |
| 306 | myexit(1); |
| 307 | } |
| 308 | |
| 309 | if (rename(cp, tmpname) != 0) |
| 310 | { |
| 311 | printf("\nERROR: failed to rename %s to %s: %s\n", |
| 312 | cp, tmpname, strerror(0)); |
| 313 | myexit(1); |
| 314 | } |
| 315 | |
| 316 | farname = searchpath_save(cp); |
| 317 | |
| 318 | if (rename(tmpname, cp) != 0) |
| 319 | { |
| 320 | printf("\nERROR: failed to rename %s back to %s: %s\n", |
| 321 | tmpname, cp, strerror(0)); |
| 322 | myexit(1); |
| 323 | } |
| 324 | |
| 325 | free(*destination); |
| 326 | free(tmpname); |
| 327 | *destination = farname; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * Check if there is a vim.[exe|bat|, gvim.[exe|bat|, etc. in the path. |
| 332 | * When "check_bat_only" is TRUE, only find "default_bat_dir". |
| 333 | */ |
| 334 | static void |
| 335 | find_bat_exe(int check_bat_only) |
| 336 | { |
| 337 | int i; |
| 338 | |
Bram Moolenaar | 42bbef4 | 2006-03-25 22:02:07 +0000 | [diff] [blame] | 339 | /* avoid looking in the "installdir" by chdir to system root */ |
| 340 | mch_chdir(sysdrive); |
| 341 | mch_chdir("\\"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 342 | |
| 343 | for (i = 1; i < TARGET_COUNT; ++i) |
| 344 | { |
| 345 | targets[i].oldbat = searchpath_save(targets[i].batname); |
| 346 | if (!check_bat_only) |
| 347 | targets[i].oldexe = searchpath_save(targets[i].exename); |
| 348 | |
| 349 | if (default_bat_dir == NULL && targets[i].oldbat != NULL) |
| 350 | { |
| 351 | default_bat_dir = alloc(strlen(targets[i].oldbat) + 1); |
| 352 | strcpy(default_bat_dir, targets[i].oldbat); |
| 353 | remove_tail(default_bat_dir); |
| 354 | } |
| 355 | if (check_bat_only && targets[i].oldbat != NULL) |
Bram Moolenaar | 42bbef4 | 2006-03-25 22:02:07 +0000 | [diff] [blame] | 356 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 357 | free(targets[i].oldbat); |
Bram Moolenaar | 42bbef4 | 2006-03-25 22:02:07 +0000 | [diff] [blame] | 358 | targets[i].oldbat = NULL; |
| 359 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | mch_chdir(installdir); |
| 363 | } |
| 364 | |
| 365 | #ifdef WIN3264 |
| 366 | /* |
| 367 | * Get the value of $VIMRUNTIME or $VIM and write it in $TEMP/vimini.ini, so |
| 368 | * that NSIS can read it. |
| 369 | * When not set, use the directory of a previously installed Vim. |
| 370 | */ |
| 371 | static void |
| 372 | get_vim_env(void) |
| 373 | { |
| 374 | char *vim; |
| 375 | char buf[BUFSIZE]; |
| 376 | FILE *fd; |
| 377 | char fname[BUFSIZE]; |
| 378 | |
| 379 | /* First get $VIMRUNTIME. If it's set, remove the tail. */ |
| 380 | vim = getenv("VIMRUNTIME"); |
| 381 | if (vim != NULL && *vim != 0) |
| 382 | { |
| 383 | strcpy(buf, vim); |
| 384 | remove_tail(buf); |
| 385 | vim = buf; |
| 386 | } |
| 387 | else |
| 388 | { |
| 389 | vim = getenv("VIM"); |
| 390 | if (vim == NULL || *vim == 0) |
| 391 | { |
| 392 | /* Use the directory from an old uninstall entry. */ |
| 393 | if (default_vim_dir != NULL) |
| 394 | vim = default_vim_dir; |
| 395 | else |
| 396 | /* Let NSIS know there is no default, it should use |
Bram Moolenaar | b8017e7 | 2007-05-10 18:59:07 +0000 | [diff] [blame] | 397 | * $PROGRAMFILES. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 398 | vim = ""; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | /* NSIS also uses GetTempPath(), thus we should get the same directory |
| 403 | * name as where NSIS will look for vimini.ini. */ |
| 404 | GetTempPath(BUFSIZE, fname); |
| 405 | add_pathsep(fname); |
| 406 | strcat(fname, "vimini.ini"); |
| 407 | |
| 408 | fd = fopen(fname, "w"); |
| 409 | if (fd != NULL) |
| 410 | { |
| 411 | /* Make it look like an .ini file, so that NSIS can read it with a |
| 412 | * ReadINIStr command. */ |
| 413 | fprintf(fd, "[vimini]\n"); |
| 414 | fprintf(fd, "dir=\"%s\"\n", vim); |
| 415 | fclose(fd); |
| 416 | } |
| 417 | else |
| 418 | { |
| 419 | printf("Failed to open %s\n", fname); |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 420 | sleep(2); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | |
Bram Moolenaar | b230bd5 | 2010-05-25 21:02:00 +0200 | [diff] [blame] | 424 | static int num_windows; |
| 425 | |
| 426 | /* |
| 427 | * Callback used for EnumWindows(): |
| 428 | * Count the window if the title looks like it is for the uninstaller. |
| 429 | */ |
| 430 | /*ARGSUSED*/ |
| 431 | static BOOL CALLBACK |
| 432 | window_cb(HWND hwnd, LPARAM lparam) |
| 433 | { |
| 434 | char title[256]; |
| 435 | |
| 436 | title[0] = 0; |
| 437 | GetWindowText(hwnd, title, 256); |
| 438 | if (strstr(title, "Vim ") != NULL && strstr(title, "Uninstall:") != NULL) |
| 439 | ++num_windows; |
| 440 | return TRUE; |
| 441 | } |
| 442 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 443 | /* |
| 444 | * Check for already installed Vims. |
| 445 | * Return non-zero when found one. |
| 446 | */ |
| 447 | static int |
Bram Moolenaar | 442b422 | 2010-05-24 21:34:22 +0200 | [diff] [blame] | 448 | uninstall_check(int skip_question) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 449 | { |
| 450 | HKEY key_handle; |
| 451 | HKEY uninstall_key_handle; |
| 452 | char *uninstall_key = "software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; |
| 453 | char subkey_name_buff[BUFSIZE]; |
| 454 | char temp_string_buffer[BUFSIZE]; |
| 455 | DWORD local_bufsize = BUFSIZE; |
| 456 | FILETIME temp_pfiletime; |
| 457 | DWORD key_index; |
| 458 | char input; |
| 459 | long code; |
| 460 | DWORD value_type; |
| 461 | DWORD orig_num_keys; |
| 462 | DWORD new_num_keys; |
| 463 | int foundone = 0; |
| 464 | |
| 465 | code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, uninstall_key, 0, KEY_READ, |
| 466 | &key_handle); |
| 467 | CHECK_REG_ERROR(code); |
| 468 | |
| 469 | for (key_index = 0; |
| 470 | RegEnumKeyEx(key_handle, key_index, subkey_name_buff, &local_bufsize, |
| 471 | NULL, NULL, NULL, &temp_pfiletime) != ERROR_NO_MORE_ITEMS; |
| 472 | key_index++) |
| 473 | { |
| 474 | local_bufsize = BUFSIZE; |
| 475 | if (strncmp("Vim", subkey_name_buff, 3) == 0) |
| 476 | { |
| 477 | /* Open the key named Vim* */ |
| 478 | code = RegOpenKeyEx(key_handle, subkey_name_buff, 0, KEY_READ, |
| 479 | &uninstall_key_handle); |
| 480 | CHECK_REG_ERROR(code); |
| 481 | |
| 482 | /* get the DisplayName out of it to show the user */ |
| 483 | code = RegQueryValueEx(uninstall_key_handle, "displayname", 0, |
| 484 | &value_type, (LPBYTE)temp_string_buffer, |
| 485 | &local_bufsize); |
| 486 | local_bufsize = BUFSIZE; |
| 487 | CHECK_REG_ERROR(code); |
| 488 | |
| 489 | foundone = 1; |
| 490 | printf("\n*********************************************************\n"); |
| 491 | printf("Vim Install found what looks like an existing Vim version.\n"); |
| 492 | printf("The name of the entry is:\n"); |
| 493 | printf("\n \"%s\"\n\n", temp_string_buffer); |
| 494 | |
| 495 | printf("Installing the new version will disable part of the existing version.\n"); |
| 496 | printf("(The batch files used in a console and the \"Edit with Vim\" entry in\n"); |
| 497 | printf("the popup menu will use the new version)\n"); |
| 498 | |
Bram Moolenaar | 442b422 | 2010-05-24 21:34:22 +0200 | [diff] [blame] | 499 | if (skip_question) |
| 500 | printf("\nRunning uninstall program for \"%s\"\n", temp_string_buffer); |
| 501 | else |
| 502 | printf("\nDo you want to uninstall \"%s\" now?\n(y)es/(n)o) ", temp_string_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 503 | fflush(stdout); |
| 504 | |
| 505 | /* get the UninstallString */ |
| 506 | code = RegQueryValueEx(uninstall_key_handle, "uninstallstring", 0, |
| 507 | &value_type, (LPBYTE)temp_string_buffer, &local_bufsize); |
| 508 | local_bufsize = BUFSIZE; |
| 509 | CHECK_REG_ERROR(code); |
| 510 | |
| 511 | /* Remember the directory, it is used as the default for NSIS. */ |
| 512 | default_vim_dir = alloc(strlen(temp_string_buffer) + 1); |
| 513 | strcpy(default_vim_dir, temp_string_buffer); |
| 514 | remove_tail(default_vim_dir); |
| 515 | remove_tail(default_vim_dir); |
| 516 | |
| 517 | input = 'n'; |
| 518 | do |
| 519 | { |
| 520 | if (input != 'n') |
| 521 | printf("%c is an invalid reply. Please enter either 'y' or 'n'\n", input); |
| 522 | |
Bram Moolenaar | 442b422 | 2010-05-24 21:34:22 +0200 | [diff] [blame] | 523 | if (skip_question) |
| 524 | input = 'y'; |
| 525 | else |
| 526 | { |
| 527 | rewind(stdin); |
| 528 | scanf("%c", &input); |
| 529 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 530 | switch (input) |
| 531 | { |
| 532 | case 'y': |
| 533 | case 'Y': |
| 534 | /* save the number of uninstall keys so we can know if |
| 535 | * it changed */ |
| 536 | RegQueryInfoKey(key_handle, NULL, NULL, NULL, |
| 537 | &orig_num_keys, NULL, NULL, NULL, |
| 538 | NULL, NULL, NULL, NULL); |
| 539 | |
Bram Moolenaar | 442b422 | 2010-05-24 21:34:22 +0200 | [diff] [blame] | 540 | /* Find existing .bat files before deleting them. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 541 | find_bat_exe(TRUE); |
| 542 | |
| 543 | /* Execute the uninstall program. Put it in double |
| 544 | * quotes if there is an embedded space. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 545 | { |
| 546 | char buf[BUFSIZE]; |
| 547 | |
Bram Moolenaar | b230bd5 | 2010-05-25 21:02:00 +0200 | [diff] [blame] | 548 | if (strchr(temp_string_buffer, ' ') != NULL) |
| 549 | sprintf(buf, "\"%s\"", temp_string_buffer); |
| 550 | else |
| 551 | strcpy(buf, temp_string_buffer); |
| 552 | run_command(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 553 | } |
Bram Moolenaar | b230bd5 | 2010-05-25 21:02:00 +0200 | [diff] [blame] | 554 | |
| 555 | /* Count the number of windows with a title that match |
| 556 | * the installer, so that we can check when it's done. |
| 557 | * The uninstaller copies itself, executes the copy |
| 558 | * and exits, thus we can't wait for the process to |
| 559 | * finish. */ |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 560 | sleep(1); /* wait for uninstaller to start up */ |
Bram Moolenaar | b230bd5 | 2010-05-25 21:02:00 +0200 | [diff] [blame] | 561 | num_windows = 0; |
| 562 | EnumWindows(window_cb, 0); |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 563 | sleep(1); /* wait for windows to be counted */ |
Bram Moolenaar | b230bd5 | 2010-05-25 21:02:00 +0200 | [diff] [blame] | 564 | if (num_windows == 0) |
| 565 | { |
| 566 | /* Did not find the uninstaller, ask user to press |
| 567 | * Enter when done. Just in case. */ |
| 568 | printf("Press Enter when the uninstaller is finished\n"); |
| 569 | rewind(stdin); |
| 570 | (void)getchar(); |
| 571 | } |
| 572 | else |
| 573 | { |
| 574 | printf("Waiting for the uninstaller to finish (press CTRL-C to abort)."); |
| 575 | do |
| 576 | { |
| 577 | printf("."); |
| 578 | fflush(stdout); |
| 579 | num_windows = 0; |
| 580 | EnumWindows(window_cb, 0); |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 581 | sleep(1); /* wait for windows to be counted */ |
Bram Moolenaar | b230bd5 | 2010-05-25 21:02:00 +0200 | [diff] [blame] | 582 | } while (num_windows > 0); |
| 583 | } |
| 584 | printf("\nDone!\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 585 | |
Bram Moolenaar | fff2bee | 2010-05-15 13:56:02 +0200 | [diff] [blame] | 586 | /* Check if an uninstall reg key was deleted. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 587 | * if it was, we want to decrement key_index. |
| 588 | * if we don't do this, we will skip the key |
| 589 | * immediately after any key that we delete. */ |
| 590 | RegQueryInfoKey(key_handle, NULL, NULL, NULL, |
| 591 | &new_num_keys, NULL, NULL, NULL, |
| 592 | NULL, NULL, NULL, NULL); |
| 593 | if (new_num_keys < orig_num_keys) |
| 594 | key_index--; |
| 595 | |
| 596 | input = 'y'; |
| 597 | break; |
| 598 | |
| 599 | case 'n': |
| 600 | case 'N': |
| 601 | /* Do not uninstall */ |
| 602 | input = 'n'; |
| 603 | break; |
| 604 | |
| 605 | default: /* just drop through and redo the loop */ |
| 606 | break; |
| 607 | } |
| 608 | |
| 609 | } while (input != 'n' && input != 'y'); |
| 610 | |
| 611 | RegCloseKey(uninstall_key_handle); |
| 612 | } |
| 613 | } |
| 614 | RegCloseKey(key_handle); |
| 615 | |
| 616 | return foundone; |
| 617 | } |
| 618 | #endif |
| 619 | |
| 620 | /* |
| 621 | * Find out information about the system. |
| 622 | */ |
| 623 | static void |
| 624 | inspect_system(void) |
| 625 | { |
| 626 | char *p; |
| 627 | char buf[BUFSIZE]; |
| 628 | FILE *fd; |
| 629 | int i; |
| 630 | int foundone; |
| 631 | |
| 632 | /* This may take a little while, let the user know what we're doing. */ |
| 633 | printf("Inspecting system...\n"); |
| 634 | |
| 635 | /* |
| 636 | * If $VIM is set, check that it's pointing to our directory. |
| 637 | */ |
| 638 | p = getenv("VIM"); |
| 639 | if (p != NULL && pathcmp(p, -1, installdir, runtimeidx - 1) != 0) |
| 640 | { |
| 641 | printf("------------------------------------------------------\n"); |
| 642 | printf("$VIM is set to \"%s\".\n", p); |
| 643 | printf("This is different from where this version of Vim is:\n"); |
| 644 | strcpy(buf, installdir); |
| 645 | *(buf + runtimeidx - 1) = NUL; |
| 646 | printf("\"%s\"\n", buf); |
| 647 | printf("You must adjust or remove the setting of $VIM,\n"); |
| 648 | if (interactive) |
| 649 | { |
| 650 | printf("to be able to use this install program.\n"); |
| 651 | myexit(1); |
| 652 | } |
| 653 | printf("otherwise Vim WILL NOT WORK properly!\n"); |
| 654 | printf("------------------------------------------------------\n"); |
| 655 | } |
| 656 | |
| 657 | /* |
| 658 | * If $VIMRUNTIME is set, check that it's pointing to our runtime directory. |
| 659 | */ |
| 660 | p = getenv("VIMRUNTIME"); |
| 661 | if (p != NULL && pathcmp(p, -1, installdir, -1) != 0) |
| 662 | { |
| 663 | printf("------------------------------------------------------\n"); |
| 664 | printf("$VIMRUNTIME is set to \"%s\".\n", p); |
| 665 | printf("This is different from where this version of Vim is:\n"); |
| 666 | printf("\"%s\"\n", installdir); |
| 667 | printf("You must adjust or remove the setting of $VIMRUNTIME,\n"); |
| 668 | if (interactive) |
| 669 | { |
| 670 | printf("to be able to use this install program.\n"); |
| 671 | myexit(1); |
| 672 | } |
| 673 | printf("otherwise Vim WILL NOT WORK properly!\n"); |
| 674 | printf("------------------------------------------------------\n"); |
| 675 | } |
| 676 | |
| 677 | /* |
| 678 | * Check if there is a vim.[exe|bat|, gvim.[exe|bat|, etc. in the path. |
| 679 | */ |
| 680 | find_bat_exe(FALSE); |
| 681 | |
| 682 | /* |
| 683 | * A .exe in the install directory may be found anyway on Windows 2000. |
| 684 | * Check for this situation and find another executable if necessary. |
| 685 | * w.briscoe@ponl.com 2001-01-20 |
| 686 | */ |
| 687 | foundone = 0; |
| 688 | for (i = 1; i < TARGET_COUNT; ++i) |
| 689 | { |
| 690 | findoldfile(&(targets[i].oldexe)); |
| 691 | if (targets[i].oldexe != NULL) |
| 692 | foundone = 1; |
| 693 | } |
| 694 | |
| 695 | if (foundone) |
| 696 | { |
| 697 | printf("Warning: Found Vim executable(s) in your $PATH:\n"); |
| 698 | for (i = 1; i < TARGET_COUNT; ++i) |
| 699 | if (targets[i].oldexe != NULL) |
| 700 | printf("%s\n", targets[i].oldexe); |
| 701 | printf("It will be used instead of the version you are installing.\n"); |
| 702 | printf("Please delete or rename it, or adjust your $PATH setting.\n"); |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | * Check if there is an existing ../_vimrc or ../.vimrc file. |
| 707 | */ |
| 708 | strcpy(oldvimrc, installdir); |
| 709 | strcpy(oldvimrc + runtimeidx, "_vimrc"); |
| 710 | if ((fd = fopen(oldvimrc, "r")) == NULL) |
| 711 | { |
| 712 | strcpy(oldvimrc + runtimeidx, "vimrc~1"); /* short version of .vimrc */ |
| 713 | if ((fd = fopen(oldvimrc, "r")) == NULL) |
| 714 | { |
| 715 | strcpy(oldvimrc + runtimeidx, ".vimrc"); |
| 716 | fd = fopen(oldvimrc, "r"); |
| 717 | } |
| 718 | } |
| 719 | if (fd != NULL) |
| 720 | fclose(fd); |
| 721 | else |
| 722 | *oldvimrc = NUL; |
| 723 | |
| 724 | #if 0 /* currently not used */ |
| 725 | /* |
| 726 | * Get default home directory. |
| 727 | * Prefer $HOME if it's set. For Win NT use $HOMEDRIVE and $HOMEPATH. |
| 728 | * Otherwise, if there is a "c:" drive use that. |
| 729 | */ |
| 730 | p = getenv("HOME"); |
| 731 | if (p != NULL && *p != NUL && strlen(p) < BUFSIZE) |
| 732 | strcpy(homedir, p); |
| 733 | else |
| 734 | { |
| 735 | p = getenv("HOMEDRIVE"); |
| 736 | if (p != NULL && *p != NUL && strlen(p) + 2 < BUFSIZE) |
| 737 | { |
| 738 | strcpy(homedir, p); |
| 739 | p = getenv("HOMEPATH"); |
| 740 | if (p != NULL && *p != NUL && strlen(homedir) + strlen(p) < BUFSIZE) |
| 741 | strcat(homedir, p); |
| 742 | else |
| 743 | strcat(homedir, "\\"); |
| 744 | } |
| 745 | else |
| 746 | { |
| 747 | struct stat st; |
| 748 | |
| 749 | if (stat("c:\\", &st) == 0) |
| 750 | strcpy(homedir, "c:\\"); |
| 751 | else |
| 752 | *homedir = NUL; |
| 753 | } |
| 754 | } |
| 755 | #endif |
| 756 | } |
| 757 | |
| 758 | /* |
| 759 | * Add a dummy choice to avoid that the numbering changes depending on items |
| 760 | * in the environment. The user may type a number he remembered without |
| 761 | * looking. |
| 762 | */ |
| 763 | static void |
| 764 | add_dummy_choice(void) |
| 765 | { |
| 766 | choices[choice_count].installfunc = NULL; |
| 767 | choices[choice_count].active = 0; |
| 768 | choices[choice_count].changefunc = NULL; |
| 769 | choices[choice_count].installfunc = NULL; |
| 770 | ++choice_count; |
| 771 | } |
| 772 | |
| 773 | /*********************************************** |
| 774 | * stuff for creating the batch files. |
| 775 | */ |
| 776 | |
| 777 | /* |
| 778 | * Install the vim.bat, gvim.bat, etc. files. |
| 779 | */ |
| 780 | static void |
| 781 | install_bat_choice(int idx) |
| 782 | { |
| 783 | char *batpath = targets[choices[idx].arg].batpath; |
| 784 | char *oldname = targets[choices[idx].arg].oldbat; |
| 785 | char *exename = targets[choices[idx].arg].exenamearg; |
| 786 | char *vimarg = targets[choices[idx].arg].exearg; |
| 787 | FILE *fd; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 788 | |
| 789 | if (*batpath != NUL) |
| 790 | { |
| 791 | fd = fopen(batpath, "w"); |
| 792 | if (fd == NULL) |
| 793 | printf("\nERROR: Cannot open \"%s\" for writing.\n", batpath); |
| 794 | else |
| 795 | { |
| 796 | need_uninstall_entry = 1; |
| 797 | |
| 798 | fprintf(fd, "@echo off\n"); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 799 | fprintf(fd, "rem -- Run Vim --\n"); |
| 800 | fprintf(fd, "\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 801 | |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 802 | /* Don't use double quotes for the "set" argument, also when it |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 803 | * contains a space. The quotes would be included in the value |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 804 | * for MSDOS and NT. |
| 805 | * The order of preference is: |
| 806 | * 1. $VIMRUNTIME/vim.exe (user preference) |
| 807 | * 2. $VIM/vim70/vim.exe (hard coded version) |
| 808 | * 3. installdir/vim.exe (hard coded install directory) |
| 809 | */ |
| 810 | fprintf(fd, "set VIM_EXE_DIR=%s\n", installdir); |
| 811 | fprintf(fd, "if exist \"%%VIM%%\\%s\\%s\" set VIM_EXE_DIR=%%VIM%%\\%s\n", |
| 812 | VIM_VERSION_NODOT, exename, VIM_VERSION_NODOT); |
| 813 | fprintf(fd, "if exist \"%%VIMRUNTIME%%\\%s\" set VIM_EXE_DIR=%%VIMRUNTIME%%\n", exename); |
| 814 | fprintf(fd, "\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 815 | |
| 816 | /* Give an error message when the executable could not be found. */ |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 817 | fprintf(fd, "if exist \"%%VIM_EXE_DIR%%\\%s\" goto havevim\n", |
| 818 | exename); |
| 819 | fprintf(fd, "echo \"%%VIM_EXE_DIR%%\\%s\" not found\n", exename); |
| 820 | fprintf(fd, "goto eof\n"); |
| 821 | fprintf(fd, "\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 822 | fprintf(fd, ":havevim\n"); |
| 823 | |
| 824 | fprintf(fd, "rem collect the arguments in VIMARGS for Win95\n"); |
| 825 | fprintf(fd, "set VIMARGS=\n"); |
| 826 | if (*exename == 'g') |
| 827 | fprintf(fd, "set VIMNOFORK=\n"); |
| 828 | fprintf(fd, ":loopstart\n"); |
| 829 | fprintf(fd, "if .%%1==. goto loopend\n"); |
| 830 | if (*exename == 'g') |
| 831 | { |
| 832 | fprintf(fd, "if NOT .%%1==.-f goto noforkarg\n"); |
| 833 | fprintf(fd, "set VIMNOFORK=1\n"); |
| 834 | fprintf(fd, ":noforkarg\n"); |
| 835 | } |
| 836 | fprintf(fd, "set VIMARGS=%%VIMARGS%% %%1\n"); |
| 837 | fprintf(fd, "shift\n"); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 838 | fprintf(fd, "goto loopstart\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 839 | fprintf(fd, ":loopend\n"); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 840 | fprintf(fd, "\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 841 | |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 842 | fprintf(fd, "if .%%OS%%==.Windows_NT goto ntaction\n"); |
| 843 | fprintf(fd, "\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 844 | |
| 845 | /* For gvim.exe use "start" to avoid that the console window stays |
| 846 | * open. */ |
| 847 | if (*exename == 'g') |
| 848 | { |
| 849 | fprintf(fd, "if .%%VIMNOFORK%%==.1 goto nofork\n"); |
| 850 | fprintf(fd, "start "); |
| 851 | } |
| 852 | |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 853 | /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ |
| 854 | fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n", |
| 855 | exename, vimarg); |
| 856 | fprintf(fd, "goto eof\n"); |
| 857 | fprintf(fd, "\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 858 | |
| 859 | if (*exename == 'g') |
| 860 | { |
| 861 | fprintf(fd, ":nofork\n"); |
| 862 | fprintf(fd, "start /w "); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 863 | /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ |
| 864 | fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%VIMARGS%%\n", |
| 865 | exename, vimarg); |
| 866 | fprintf(fd, "goto eof\n"); |
| 867 | fprintf(fd, "\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | fprintf(fd, ":ntaction\n"); |
| 871 | fprintf(fd, "rem for WinNT we can use %%*\n"); |
| 872 | |
| 873 | /* For gvim.exe use "start /b" to avoid that the console window |
| 874 | * stays open. */ |
| 875 | if (*exename == 'g') |
| 876 | { |
| 877 | fprintf(fd, "if .%%VIMNOFORK%%==.1 goto noforknt\n"); |
| 878 | fprintf(fd, "start \"dummy\" /b "); |
| 879 | } |
| 880 | |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 881 | /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ |
| 882 | fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", exename, vimarg); |
| 883 | fprintf(fd, "goto eof\n"); |
| 884 | fprintf(fd, "\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 885 | |
| 886 | if (*exename == 'g') |
| 887 | { |
| 888 | fprintf(fd, ":noforknt\n"); |
| 889 | fprintf(fd, "start \"dummy\" /b /wait "); |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 890 | /* Always use quotes, $VIM or $VIMRUNTIME might have a space. */ |
| 891 | fprintf(fd, "\"%%VIM_EXE_DIR%%\\%s\" %s %%*\n", |
| 892 | exename, vimarg); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | fprintf(fd, "\n:eof\n"); |
| 896 | fprintf(fd, "set VIMARGS=\n"); |
| 897 | if (*exename == 'g') |
| 898 | fprintf(fd, "set VIMNOFORK=\n"); |
| 899 | |
| 900 | fclose(fd); |
| 901 | printf("%s has been %s\n", batpath, |
| 902 | oldname == NULL ? "created" : "overwritten"); |
| 903 | } |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /* |
| 908 | * Make the text string for choice "idx". |
| 909 | * The format "fmt" is must have one %s item, which "arg" is used for. |
| 910 | */ |
| 911 | static void |
| 912 | alloc_text(int idx, char *fmt, char *arg) |
| 913 | { |
| 914 | if (choices[idx].text != NULL) |
| 915 | free(choices[idx].text); |
| 916 | |
| 917 | choices[idx].text = alloc((int)(strlen(fmt) + strlen(arg)) - 1); |
| 918 | sprintf(choices[idx].text, fmt, arg); |
| 919 | } |
| 920 | |
| 921 | /* |
| 922 | * Toggle the "Overwrite .../vim.bat" to "Don't overwrite". |
| 923 | */ |
| 924 | static void |
| 925 | toggle_bat_choice(int idx) |
| 926 | { |
| 927 | char *batname = targets[choices[idx].arg].batpath; |
| 928 | char *oldname = targets[choices[idx].arg].oldbat; |
| 929 | |
| 930 | if (*batname == NUL) |
| 931 | { |
| 932 | alloc_text(idx, " Overwrite %s", oldname); |
| 933 | strcpy(batname, oldname); |
| 934 | } |
| 935 | else |
| 936 | { |
| 937 | alloc_text(idx, " Do NOT overwrite %s", oldname); |
| 938 | *batname = NUL; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | /* |
| 943 | * Do some work for a batch file entry: Append the batch file name to the path |
| 944 | * and set the text for the choice. |
| 945 | */ |
| 946 | static void |
| 947 | set_bat_text(int idx, char *batpath, char *name) |
| 948 | { |
| 949 | strcat(batpath, name); |
| 950 | |
| 951 | alloc_text(idx, " Create %s", batpath); |
| 952 | } |
| 953 | |
| 954 | /* |
| 955 | * Select a directory to write the batch file line. |
| 956 | */ |
| 957 | static void |
| 958 | change_bat_choice(int idx) |
| 959 | { |
| 960 | char *path; |
| 961 | char *batpath; |
| 962 | char *name; |
| 963 | int n; |
| 964 | char *s; |
| 965 | char *p; |
| 966 | int count; |
| 967 | char **names = NULL; |
| 968 | int i; |
| 969 | int target = choices[idx].arg; |
| 970 | |
| 971 | name = targets[target].batname; |
| 972 | batpath = targets[target].batpath; |
| 973 | |
| 974 | path = getenv("PATH"); |
| 975 | if (path == NULL) |
| 976 | { |
| 977 | printf("\nERROR: The variable $PATH is not set\n"); |
| 978 | return; |
| 979 | } |
| 980 | |
| 981 | /* |
| 982 | * first round: count number of names in path; |
| 983 | * second round: save names to names[]. |
| 984 | */ |
| 985 | for (;;) |
| 986 | { |
| 987 | count = 1; |
| 988 | for (p = path; *p; ) |
| 989 | { |
| 990 | s = strchr(p, ';'); |
| 991 | if (s == NULL) |
| 992 | s = p + strlen(p); |
| 993 | if (names != NULL) |
| 994 | { |
| 995 | names[count] = alloc((int)(s - p) + 1); |
| 996 | strncpy(names[count], p, s - p); |
| 997 | names[count][s - p] = NUL; |
| 998 | } |
| 999 | ++count; |
| 1000 | p = s; |
| 1001 | if (*p != NUL) |
| 1002 | ++p; |
| 1003 | } |
| 1004 | if (names != NULL) |
| 1005 | break; |
| 1006 | names = alloc((int)(count + 1) * sizeof(char *)); |
| 1007 | } |
| 1008 | names[0] = alloc(50); |
| 1009 | sprintf(names[0], "Select directory to create %s in:", name); |
| 1010 | names[count] = alloc(50); |
| 1011 | if (choices[idx].arg == 0) |
| 1012 | sprintf(names[count], "Do not create any .bat file."); |
| 1013 | else |
| 1014 | sprintf(names[count], "Do not create a %s file.", name); |
| 1015 | n = get_choice(names, count + 1); |
| 1016 | |
| 1017 | if (n == count) |
| 1018 | { |
| 1019 | /* Selected last item, don't create bat file. */ |
| 1020 | *batpath = NUL; |
| 1021 | if (choices[idx].arg != 0) |
| 1022 | alloc_text(idx, " Do NOT create %s", name); |
| 1023 | } |
| 1024 | else |
| 1025 | { |
| 1026 | /* Selected one of the paths. For the first item only keep the path, |
| 1027 | * for the others append the batch file name. */ |
| 1028 | strcpy(batpath, names[n]); |
| 1029 | add_pathsep(batpath); |
| 1030 | if (choices[idx].arg != 0) |
| 1031 | set_bat_text(idx, batpath, name); |
| 1032 | } |
| 1033 | |
| 1034 | for (i = 0; i <= count; ++i) |
| 1035 | free(names[i]); |
| 1036 | free(names); |
| 1037 | } |
| 1038 | |
| 1039 | char *bat_text_yes = "Install .bat files to use Vim at the command line:"; |
| 1040 | char *bat_text_no = "do NOT install .bat files to use Vim at the command line"; |
| 1041 | |
| 1042 | static void |
| 1043 | change_main_bat_choice(int idx) |
| 1044 | { |
| 1045 | int i; |
| 1046 | |
| 1047 | /* let the user select a default directory or NONE */ |
| 1048 | change_bat_choice(idx); |
| 1049 | |
| 1050 | if (targets[0].batpath[0] != NUL) |
| 1051 | choices[idx].text = bat_text_yes; |
| 1052 | else |
| 1053 | choices[idx].text = bat_text_no; |
| 1054 | |
| 1055 | /* update the individual batch file selections */ |
| 1056 | for (i = 1; i < TARGET_COUNT; ++i) |
| 1057 | { |
| 1058 | /* Only make it active when the first item has a path and the vim.exe |
| 1059 | * or gvim.exe exists (there is a changefunc then). */ |
| 1060 | if (targets[0].batpath[0] != NUL |
| 1061 | && choices[idx + i].changefunc != NULL) |
| 1062 | { |
| 1063 | choices[idx + i].active = 1; |
| 1064 | if (choices[idx + i].changefunc == change_bat_choice |
| 1065 | && targets[i].batpath[0] != NUL) |
| 1066 | { |
| 1067 | strcpy(targets[i].batpath, targets[0].batpath); |
| 1068 | set_bat_text(idx + i, targets[i].batpath, targets[i].batname); |
| 1069 | } |
| 1070 | } |
| 1071 | else |
| 1072 | choices[idx + i].active = 0; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | /* |
| 1077 | * Initialize a choice for creating a batch file. |
| 1078 | */ |
| 1079 | static void |
| 1080 | init_bat_choice(int target) |
| 1081 | { |
| 1082 | char *batpath = targets[target].batpath; |
| 1083 | char *oldbat = targets[target].oldbat; |
| 1084 | char *p; |
| 1085 | int i; |
| 1086 | |
| 1087 | choices[choice_count].arg = target; |
| 1088 | choices[choice_count].installfunc = install_bat_choice; |
| 1089 | choices[choice_count].active = 1; |
| 1090 | choices[choice_count].text = NULL; /* will be set below */ |
| 1091 | if (oldbat != NULL) |
| 1092 | { |
| 1093 | /* A [g]vim.bat exists: Only choice is to overwrite it or not. */ |
| 1094 | choices[choice_count].changefunc = toggle_bat_choice; |
| 1095 | *batpath = NUL; |
| 1096 | toggle_bat_choice(choice_count); |
| 1097 | } |
| 1098 | else |
| 1099 | { |
| 1100 | if (default_bat_dir != NULL) |
| 1101 | /* Prefer using the same path as an existing .bat file. */ |
| 1102 | strcpy(batpath, default_bat_dir); |
| 1103 | else |
| 1104 | { |
| 1105 | /* No [g]vim.bat exists: Write it to a directory in $PATH. Use |
| 1106 | * $WINDIR by default, if it's empty the first item in $PATH. */ |
| 1107 | p = getenv("WINDIR"); |
| 1108 | if (p != NULL && *p != NUL) |
| 1109 | strcpy(batpath, p); |
| 1110 | else |
| 1111 | { |
| 1112 | p = getenv("PATH"); |
| 1113 | if (p == NULL || *p == NUL) /* "cannot happen" */ |
| 1114 | strcpy(batpath, "C:/Windows"); |
| 1115 | else |
| 1116 | { |
| 1117 | i = 0; |
| 1118 | while (*p != NUL && *p != ';') |
| 1119 | batpath[i++] = *p++; |
| 1120 | batpath[i] = NUL; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | add_pathsep(batpath); |
| 1125 | set_bat_text(choice_count, batpath, targets[target].batname); |
| 1126 | |
| 1127 | choices[choice_count].changefunc = change_bat_choice; |
| 1128 | } |
| 1129 | ++choice_count; |
| 1130 | } |
| 1131 | |
| 1132 | /* |
| 1133 | * Set up the choices for installing .bat files. |
| 1134 | * For these items "arg" is the index in targets[]. |
| 1135 | */ |
| 1136 | static void |
| 1137 | init_bat_choices(void) |
| 1138 | { |
| 1139 | int i; |
| 1140 | |
| 1141 | /* The first item is used to switch installing batch files on/off and |
| 1142 | * setting the default path. */ |
| 1143 | choices[choice_count].text = bat_text_yes; |
| 1144 | choices[choice_count].changefunc = change_main_bat_choice; |
| 1145 | choices[choice_count].installfunc = NULL; |
| 1146 | choices[choice_count].active = 1; |
| 1147 | choices[choice_count].arg = 0; |
| 1148 | ++choice_count; |
| 1149 | |
| 1150 | /* Add items for each batch file target. Only used when not disabled by |
| 1151 | * the first item. When a .exe exists, don't offer to create a .bat. */ |
| 1152 | for (i = 1; i < TARGET_COUNT; ++i) |
| 1153 | if (targets[i].oldexe == NULL |
| 1154 | && (targets[i].exenamearg[0] == 'g' ? has_gvim : has_vim)) |
| 1155 | init_bat_choice(i); |
| 1156 | else |
| 1157 | add_dummy_choice(); |
| 1158 | } |
| 1159 | |
| 1160 | /* |
| 1161 | * Install the vimrc file. |
| 1162 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1163 | static void |
| 1164 | install_vimrc(int idx) |
| 1165 | { |
| 1166 | FILE *fd, *tfd; |
| 1167 | char *fname; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1168 | |
| 1169 | /* If an old vimrc file exists, overwrite it. |
| 1170 | * Otherwise create a new one. */ |
| 1171 | if (*oldvimrc != NUL) |
| 1172 | fname = oldvimrc; |
| 1173 | else |
| 1174 | fname = vimrc; |
| 1175 | |
| 1176 | fd = fopen(fname, "w"); |
| 1177 | if (fd == NULL) |
| 1178 | { |
| 1179 | printf("\nERROR: Cannot open \"%s\" for writing.\n", fname); |
| 1180 | return; |
| 1181 | } |
| 1182 | switch (compat_choice) |
| 1183 | { |
| 1184 | case compat_vi: |
| 1185 | fprintf(fd, "set compatible\n"); |
| 1186 | break; |
| 1187 | case compat_some_enhancements: |
| 1188 | fprintf(fd, "set nocompatible\n"); |
| 1189 | break; |
| 1190 | case compat_all_enhancements: |
| 1191 | fprintf(fd, "set nocompatible\n"); |
| 1192 | fprintf(fd, "source $VIMRUNTIME/vimrc_example.vim\n"); |
| 1193 | break; |
| 1194 | } |
| 1195 | switch (remap_choice) |
| 1196 | { |
| 1197 | case remap_no: |
| 1198 | break; |
| 1199 | case remap_win: |
| 1200 | fprintf(fd, "source $VIMRUNTIME/mswin.vim\n"); |
| 1201 | break; |
| 1202 | } |
| 1203 | switch (mouse_choice) |
| 1204 | { |
| 1205 | case mouse_xterm: |
| 1206 | fprintf(fd, "behave xterm\n"); |
| 1207 | break; |
| 1208 | case mouse_mswin: |
| 1209 | fprintf(fd, "behave mswin\n"); |
| 1210 | break; |
| 1211 | } |
| 1212 | if ((tfd = fopen("diff.exe", "r")) != NULL) |
| 1213 | { |
| 1214 | /* Use the diff.exe that comes with the self-extracting gvim.exe. */ |
| 1215 | fclose(tfd); |
| 1216 | fprintf(fd, "\n"); |
| 1217 | fprintf(fd, "set diffexpr=MyDiff()\n"); |
| 1218 | fprintf(fd, "function MyDiff()\n"); |
| 1219 | fprintf(fd, " let opt = '-a --binary '\n"); |
| 1220 | fprintf(fd, " if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif\n"); |
| 1221 | fprintf(fd, " if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif\n"); |
| 1222 | /* Use quotes only when needed, they may cause trouble. */ |
| 1223 | fprintf(fd, " let arg1 = v:fname_in\n"); |
| 1224 | fprintf(fd, " if arg1 =~ ' ' | let arg1 = '\"' . arg1 . '\"' | endif\n"); |
| 1225 | fprintf(fd, " let arg2 = v:fname_new\n"); |
| 1226 | fprintf(fd, " if arg2 =~ ' ' | let arg2 = '\"' . arg2 . '\"' | endif\n"); |
| 1227 | fprintf(fd, " let arg3 = v:fname_out\n"); |
| 1228 | fprintf(fd, " if arg3 =~ ' ' | let arg3 = '\"' . arg3 . '\"' | endif\n"); |
Bram Moolenaar | 33aec76 | 2006-01-22 23:30:12 +0000 | [diff] [blame] | 1229 | |
| 1230 | /* If the path has a space: When using cmd.exe (Win NT/2000/XP) put |
| 1231 | * quotes around the whole command and around the diff command. |
| 1232 | * Otherwise put a double quote just before the space and at the |
| 1233 | * end of the command. Putting quotes around the whole thing |
| 1234 | * doesn't work on Win 95/98/ME. This is mostly guessed! */ |
| 1235 | fprintf(fd, " let eq = ''\n"); |
| 1236 | fprintf(fd, " if $VIMRUNTIME =~ ' '\n"); |
| 1237 | fprintf(fd, " if &sh =~ '\\<cmd'\n"); |
| 1238 | fprintf(fd, " let cmd = '\"\"' . $VIMRUNTIME . '\\diff\"'\n"); |
| 1239 | fprintf(fd, " let eq = '\"'\n"); |
| 1240 | fprintf(fd, " else\n"); |
| 1241 | fprintf(fd, " let cmd = substitute($VIMRUNTIME, ' ', '\" ', '') . '\\diff\"'\n"); |
| 1242 | fprintf(fd, " endif\n"); |
| 1243 | fprintf(fd, " else\n"); |
| 1244 | fprintf(fd, " let cmd = $VIMRUNTIME . '\\diff'\n"); |
| 1245 | fprintf(fd, " endif\n"); |
| 1246 | fprintf(fd, " silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq\n"); |
| 1247 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1248 | fprintf(fd, "endfunction\n"); |
| 1249 | fprintf(fd, "\n"); |
| 1250 | } |
| 1251 | fclose(fd); |
| 1252 | printf("%s has been written\n", fname); |
| 1253 | } |
| 1254 | |
| 1255 | static void |
| 1256 | change_vimrc_choice(int idx) |
| 1257 | { |
| 1258 | if (choices[idx].installfunc != NULL) |
| 1259 | { |
| 1260 | /* Switch to NOT change or create a vimrc file. */ |
| 1261 | if (*oldvimrc != NUL) |
| 1262 | alloc_text(idx, "Do NOT change startup file %s", oldvimrc); |
| 1263 | else |
| 1264 | alloc_text(idx, "Do NOT create startup file %s", vimrc); |
| 1265 | choices[idx].installfunc = NULL; |
| 1266 | choices[idx + 1].active = 0; |
| 1267 | choices[idx + 2].active = 0; |
| 1268 | choices[idx + 3].active = 0; |
| 1269 | } |
| 1270 | else |
| 1271 | { |
| 1272 | /* Switch to change or create a vimrc file. */ |
| 1273 | if (*oldvimrc != NUL) |
| 1274 | alloc_text(idx, "Overwrite startup file %s with:", oldvimrc); |
| 1275 | else |
| 1276 | alloc_text(idx, "Create startup file %s with:", vimrc); |
| 1277 | choices[idx].installfunc = install_vimrc; |
| 1278 | choices[idx + 1].active = 1; |
| 1279 | choices[idx + 2].active = 1; |
| 1280 | choices[idx + 3].active = 1; |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | /* |
| 1285 | * Change the choice how to run Vim. |
| 1286 | */ |
| 1287 | static void |
| 1288 | change_run_choice(int idx) |
| 1289 | { |
| 1290 | compat_choice = get_choice(compat_choices, TABLE_SIZE(compat_choices)); |
| 1291 | alloc_text(idx, compat_text, compat_choices[compat_choice]); |
| 1292 | } |
| 1293 | |
| 1294 | /* |
| 1295 | * Change the choice if keys are to be remapped. |
| 1296 | */ |
| 1297 | static void |
| 1298 | change_remap_choice(int idx) |
| 1299 | { |
| 1300 | remap_choice = get_choice(remap_choices, TABLE_SIZE(remap_choices)); |
| 1301 | alloc_text(idx, remap_text, remap_choices[remap_choice]); |
| 1302 | } |
| 1303 | |
| 1304 | /* |
| 1305 | * Change the choice how to select text. |
| 1306 | */ |
| 1307 | static void |
| 1308 | change_mouse_choice(int idx) |
| 1309 | { |
| 1310 | mouse_choice = get_choice(mouse_choices, TABLE_SIZE(mouse_choices)); |
| 1311 | alloc_text(idx, mouse_text, mouse_choices[mouse_choice]); |
| 1312 | } |
| 1313 | |
| 1314 | static void |
| 1315 | init_vimrc_choices(void) |
| 1316 | { |
| 1317 | /* set path for a new _vimrc file (also when not used) */ |
| 1318 | strcpy(vimrc, installdir); |
| 1319 | strcpy(vimrc + runtimeidx, "_vimrc"); |
| 1320 | |
| 1321 | /* Set opposite value and then toggle it by calling change_vimrc_choice() */ |
| 1322 | if (*oldvimrc == NUL) |
| 1323 | choices[choice_count].installfunc = NULL; |
| 1324 | else |
| 1325 | choices[choice_count].installfunc = install_vimrc; |
| 1326 | choices[choice_count].text = NULL; |
| 1327 | change_vimrc_choice(choice_count); |
| 1328 | choices[choice_count].changefunc = change_vimrc_choice; |
| 1329 | choices[choice_count].active = 1; |
| 1330 | ++choice_count; |
| 1331 | |
| 1332 | /* default way to run Vim */ |
| 1333 | alloc_text(choice_count, compat_text, compat_choices[compat_choice]); |
| 1334 | choices[choice_count].changefunc = change_run_choice; |
| 1335 | choices[choice_count].installfunc = NULL; |
| 1336 | choices[choice_count].active = (*oldvimrc == NUL); |
| 1337 | ++choice_count; |
| 1338 | |
| 1339 | /* Whether to remap keys */ |
| 1340 | alloc_text(choice_count, remap_text , remap_choices[remap_choice]); |
| 1341 | choices[choice_count].changefunc = change_remap_choice; |
| 1342 | choices[choice_count].installfunc = NULL;; |
| 1343 | choices[choice_count].active = (*oldvimrc == NUL); |
| 1344 | ++choice_count; |
| 1345 | |
| 1346 | /* default way to use the mouse */ |
| 1347 | alloc_text(choice_count, mouse_text, mouse_choices[mouse_choice]); |
| 1348 | choices[choice_count].changefunc = change_mouse_choice; |
| 1349 | choices[choice_count].installfunc = NULL;; |
| 1350 | choices[choice_count].active = (*oldvimrc == NUL); |
| 1351 | ++choice_count; |
| 1352 | } |
| 1353 | |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 1354 | #if defined(WIN3264) |
| 1355 | /* |
| 1356 | * Modern way of creating registry entries, also works on 64 bit windows when |
| 1357 | * compiled as a 32 bit program. |
| 1358 | */ |
| 1359 | # ifndef KEY_WOW64_64KEY |
| 1360 | # define KEY_WOW64_64KEY 0x0100 |
| 1361 | # endif |
| 1362 | |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1363 | static LONG |
| 1364 | reg_create_key( |
| 1365 | HKEY root, |
| 1366 | const char *subkey, |
| 1367 | PHKEY phKey) |
| 1368 | { |
| 1369 | DWORD disp; |
| 1370 | |
| 1371 | *phKey = NULL; |
| 1372 | return RegCreateKeyEx( |
| 1373 | root, subkey, |
| 1374 | 0, NULL, REG_OPTION_NON_VOLATILE, |
| 1375 | KEY_WOW64_64KEY | KEY_WRITE, |
| 1376 | NULL, phKey, &disp); |
| 1377 | } |
| 1378 | |
| 1379 | static LONG |
| 1380 | reg_set_string_value( |
| 1381 | HKEY hKey, |
| 1382 | const char *value_name, |
| 1383 | const char *data) |
| 1384 | { |
| 1385 | return RegSetValueEx(hKey, value_name, 0, REG_SZ, |
| 1386 | (LPBYTE)data, (DWORD)(1 + strlen(data))); |
| 1387 | } |
| 1388 | |
| 1389 | static LONG |
| 1390 | reg_create_key_and_value( |
| 1391 | HKEY hRootKey, |
| 1392 | const char *subkey, |
| 1393 | const char *value_name, |
| 1394 | const char *data) |
| 1395 | { |
| 1396 | HKEY hKey; |
| 1397 | LONG lRet = reg_create_key(hRootKey, subkey, &hKey); |
| 1398 | |
| 1399 | if (ERROR_SUCCESS == lRet) |
| 1400 | { |
| 1401 | lRet = reg_set_string_value(hKey, value_name, data); |
| 1402 | RegCloseKey(hKey); |
| 1403 | } |
| 1404 | return lRet; |
| 1405 | } |
| 1406 | |
| 1407 | static LONG |
| 1408 | register_inproc_server( |
| 1409 | HKEY hRootKey, |
| 1410 | const char *clsid, |
| 1411 | const char *extname, |
| 1412 | const char *module, |
| 1413 | const char *threading_model) |
| 1414 | { |
| 1415 | CHAR subkey[BUFSIZE]; |
| 1416 | LONG lRet; |
| 1417 | |
| 1418 | sprintf(subkey, "CLSID\\%s", clsid); |
| 1419 | lRet = reg_create_key_and_value(hRootKey, subkey, NULL, extname); |
| 1420 | if (ERROR_SUCCESS == lRet) |
| 1421 | { |
| 1422 | sprintf(subkey, "CLSID\\%s\\InProcServer32", clsid); |
| 1423 | lRet = reg_create_key_and_value(hRootKey, subkey, NULL, module); |
| 1424 | if (ERROR_SUCCESS == lRet) |
| 1425 | { |
| 1426 | lRet = reg_create_key_and_value(hRootKey, subkey, |
| 1427 | "ThreadingModel", threading_model); |
| 1428 | } |
| 1429 | } |
| 1430 | return lRet; |
| 1431 | } |
| 1432 | |
| 1433 | static LONG |
| 1434 | register_shellex( |
| 1435 | HKEY hRootKey, |
| 1436 | const char *clsid, |
| 1437 | const char *name, |
| 1438 | const char *exe_path) |
| 1439 | { |
| 1440 | LONG lRet = reg_create_key_and_value( |
| 1441 | hRootKey, |
| 1442 | "*\\shellex\\ContextMenuHandlers\\gvim", |
| 1443 | NULL, |
| 1444 | clsid); |
| 1445 | |
| 1446 | if (ERROR_SUCCESS == lRet) |
| 1447 | { |
| 1448 | lRet = reg_create_key_and_value( |
| 1449 | HKEY_LOCAL_MACHINE, |
| 1450 | "Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved", |
| 1451 | clsid, |
| 1452 | name); |
| 1453 | |
| 1454 | if (ERROR_SUCCESS == lRet) |
| 1455 | { |
| 1456 | lRet = reg_create_key_and_value( |
| 1457 | HKEY_LOCAL_MACHINE, |
| 1458 | "Software\\Vim\\Gvim", |
| 1459 | "path", |
| 1460 | exe_path); |
| 1461 | } |
| 1462 | } |
| 1463 | return lRet; |
| 1464 | } |
| 1465 | |
| 1466 | static LONG |
| 1467 | register_openwith( |
| 1468 | HKEY hRootKey, |
| 1469 | const char *exe_path) |
| 1470 | { |
| 1471 | LONG lRet = reg_create_key_and_value( |
| 1472 | hRootKey, |
| 1473 | "Applications\\gvim.exe\\shell\\edit\\command", |
| 1474 | NULL, |
| 1475 | exe_path); |
| 1476 | |
| 1477 | if (ERROR_SUCCESS == lRet) |
| 1478 | { |
| 1479 | int i; |
| 1480 | static const char *openwith[] = { |
| 1481 | ".htm\\OpenWithList\\gvim.exe", |
| 1482 | ".vim\\OpenWithList\\gvim.exe", |
| 1483 | "*\\OpenWithList\\gvim.exe", |
| 1484 | }; |
| 1485 | |
| 1486 | for (i = 0; ERROR_SUCCESS == lRet |
| 1487 | && i < sizeof(openwith) / sizeof(openwith[0]); i++) |
| 1488 | { |
| 1489 | lRet = reg_create_key_and_value(hRootKey, openwith[i], NULL, ""); |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | return lRet; |
| 1494 | } |
| 1495 | |
| 1496 | static LONG |
| 1497 | register_uninstall( |
| 1498 | HKEY hRootKey, |
| 1499 | const char *appname, |
| 1500 | const char *display_name, |
| 1501 | const char *uninstall_string) |
| 1502 | { |
| 1503 | LONG lRet = reg_create_key_and_value(hRootKey, appname, |
| 1504 | "DisplayName", display_name); |
| 1505 | |
| 1506 | if (ERROR_SUCCESS == lRet) |
| 1507 | lRet = reg_create_key_and_value(hRootKey, appname, |
| 1508 | "UninstallString", uninstall_string); |
| 1509 | return lRet; |
| 1510 | } |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 1511 | #endif /* WIN3264 */ |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1512 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1513 | /* |
| 1514 | * Add some entries to the registry: |
| 1515 | * - to add "Edit with Vim" to the context * menu |
| 1516 | * - to add Vim to the "Open with..." list |
| 1517 | * - to uninstall Vim |
| 1518 | */ |
| 1519 | /*ARGSUSED*/ |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 1520 | static int |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1521 | install_registry(void) |
| 1522 | { |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 1523 | #ifdef WIN3264 |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1524 | LONG lRet = ERROR_SUCCESS; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1525 | const char *vim_ext_ThreadingModel = "Apartment"; |
| 1526 | const char *vim_ext_name = "Vim Shell Extension"; |
| 1527 | const char *vim_ext_clsid = "{51EEE242-AD87-11d3-9C1E-0090278BBD99}"; |
| 1528 | char buf[BUFSIZE]; |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1529 | char vim_exe_path[BUFSIZE]; |
| 1530 | char display_name[BUFSIZE]; |
| 1531 | char uninstall_string[BUFSIZE]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1532 | |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1533 | sprintf(vim_exe_path, "%s\\gvim.exe", installdir); |
| 1534 | |
| 1535 | if (install_popup) |
| 1536 | { |
| 1537 | char bufg[BUFSIZE]; |
| 1538 | struct stat st; |
| 1539 | |
| 1540 | if (stat("gvimext.dll", &st) >= 0) |
| 1541 | sprintf(bufg, "%s\\gvimext.dll", installdir); |
| 1542 | else |
| 1543 | /* gvimext.dll is in gvimext subdir */ |
| 1544 | sprintf(bufg, "%s\\gvimext\\gvimext.dll", installdir); |
| 1545 | |
| 1546 | printf("Creating \"Edit with Vim\" popup menu entry\n"); |
| 1547 | |
| 1548 | lRet = register_inproc_server( |
| 1549 | HKEY_CLASSES_ROOT, vim_ext_clsid, vim_ext_name, |
| 1550 | bufg, vim_ext_ThreadingModel); |
| 1551 | if (ERROR_SUCCESS != lRet) |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 1552 | return FAIL; |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1553 | lRet = register_shellex( |
| 1554 | HKEY_CLASSES_ROOT, vim_ext_clsid, vim_ext_name, vim_exe_path); |
| 1555 | if (ERROR_SUCCESS != lRet) |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 1556 | return FAIL; |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1557 | } |
| 1558 | |
| 1559 | if (install_openwith) |
| 1560 | { |
| 1561 | printf("Creating \"Open with ...\" list entry\n"); |
| 1562 | |
| 1563 | lRet = register_openwith(HKEY_CLASSES_ROOT, vim_exe_path); |
| 1564 | if (ERROR_SUCCESS != lRet) |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 1565 | return FAIL; |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | printf("Creating an uninstall entry\n"); |
| 1569 | |
| 1570 | /* For the NSIS installer use the generated uninstaller. */ |
| 1571 | if (interactive) |
| 1572 | { |
| 1573 | sprintf(display_name, "Vim " VIM_VERSION_SHORT); |
| 1574 | sprintf(uninstall_string, "%suninstal.exe", buf); |
| 1575 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1576 | else |
| 1577 | { |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1578 | sprintf(display_name, "Vim " VIM_VERSION_SHORT " (self-installing)"); |
| 1579 | sprintf(uninstall_string, "%suninstall-gui.exe", buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1580 | } |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1581 | |
| 1582 | lRet = register_uninstall( |
| 1583 | HKEY_LOCAL_MACHINE, |
| 1584 | "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Vim " VIM_VERSION_SHORT, |
| 1585 | display_name, |
| 1586 | uninstall_string); |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 1587 | if (ERROR_SUCCESS != lRet) |
| 1588 | return FAIL; |
| 1589 | #endif /* WIN3264 */ |
Bram Moolenaar | ccd9ccf | 2010-07-07 13:19:55 +0200 | [diff] [blame] | 1590 | |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 1591 | return OK; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | static void |
| 1595 | change_popup_choice(int idx) |
| 1596 | { |
| 1597 | if (install_popup == 0) |
| 1598 | { |
| 1599 | choices[idx].text = "Install an entry for Vim in the popup menu for the right\n mouse button so that you can edit any file with Vim"; |
| 1600 | install_popup = 1; |
| 1601 | } |
| 1602 | else |
| 1603 | { |
| 1604 | choices[idx].text = "Do NOT install an entry for Vim in the popup menu for the\n right mouse button to edit any file with Vim"; |
| 1605 | install_popup = 0; |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | /* |
| 1610 | * Only add the choice for the popup menu entry when gvim.exe was found and |
| 1611 | * both gvimext.dll and regedit.exe exist. |
| 1612 | */ |
| 1613 | static void |
| 1614 | init_popup_choice(void) |
| 1615 | { |
| 1616 | struct stat st; |
| 1617 | |
| 1618 | if (has_gvim |
| 1619 | && (stat("gvimext.dll", &st) >= 0 |
| 1620 | || stat("gvimext/gvimext.dll", &st) >= 0) |
| 1621 | #ifndef WIN3264 |
| 1622 | && searchpath("regedit.exe") != NULL |
| 1623 | #endif |
| 1624 | ) |
| 1625 | { |
| 1626 | choices[choice_count].changefunc = change_popup_choice; |
| 1627 | choices[choice_count].installfunc = NULL; |
| 1628 | choices[choice_count].active = 1; |
| 1629 | change_popup_choice(choice_count); /* set the text */ |
| 1630 | ++choice_count; |
| 1631 | } |
| 1632 | else |
| 1633 | add_dummy_choice(); |
| 1634 | } |
| 1635 | |
| 1636 | static void |
| 1637 | change_openwith_choice(int idx) |
| 1638 | { |
| 1639 | if (install_openwith == 0) |
| 1640 | { |
| 1641 | choices[idx].text = "Add Vim to the \"Open With...\" list in the popup menu for the right\n mouse button so that you can edit any file with Vim"; |
| 1642 | install_openwith = 1; |
| 1643 | } |
| 1644 | else |
| 1645 | { |
| 1646 | choices[idx].text = "Do NOT add Vim to the \"Open With...\" list in the popup menu for the\n right mouse button to edit any file with Vim"; |
| 1647 | install_openwith = 0; |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | /* |
| 1652 | * Only add the choice for the open-with menu entry when gvim.exe was found |
| 1653 | * and and regedit.exe exist. |
| 1654 | */ |
| 1655 | static void |
| 1656 | init_openwith_choice(void) |
| 1657 | { |
| 1658 | if (has_gvim |
| 1659 | #ifndef WIN3264 |
| 1660 | && searchpath("regedit.exe") != NULL |
| 1661 | #endif |
| 1662 | ) |
| 1663 | { |
| 1664 | choices[choice_count].changefunc = change_openwith_choice; |
| 1665 | choices[choice_count].installfunc = NULL; |
| 1666 | choices[choice_count].active = 1; |
| 1667 | change_openwith_choice(choice_count); /* set the text */ |
| 1668 | ++choice_count; |
| 1669 | } |
| 1670 | else |
| 1671 | add_dummy_choice(); |
| 1672 | } |
| 1673 | |
| 1674 | #ifdef WIN3264 |
| 1675 | /* create_shortcut |
| 1676 | * |
| 1677 | * Create a shell link. |
| 1678 | * |
| 1679 | * returns 0 on failure, non-zero on successful completion. |
| 1680 | * |
| 1681 | * NOTE: Currently untested with mingw. |
| 1682 | */ |
| 1683 | int |
| 1684 | create_shortcut( |
| 1685 | const char *shortcut_name, |
| 1686 | const char *iconfile_path, |
| 1687 | int iconindex, |
| 1688 | const char *shortcut_target, |
| 1689 | const char *shortcut_args, |
| 1690 | const char *workingdir |
| 1691 | ) |
| 1692 | { |
| 1693 | IShellLink *shelllink_ptr; |
| 1694 | HRESULT hres; |
| 1695 | IPersistFile *persistfile_ptr; |
| 1696 | |
| 1697 | /* Initialize COM library */ |
| 1698 | hres = CoInitialize(NULL); |
| 1699 | if (!SUCCEEDED(hres)) |
| 1700 | { |
| 1701 | printf("Error: Could not open the COM library. Not creating shortcut.\n"); |
| 1702 | return FAIL; |
| 1703 | } |
| 1704 | |
| 1705 | /* Instantiate a COM object for the ShellLink, store a pointer to it |
| 1706 | * in shelllink_ptr. */ |
| 1707 | hres = CoCreateInstance(&CLSID_ShellLink, |
| 1708 | NULL, |
| 1709 | CLSCTX_INPROC_SERVER, |
| 1710 | &IID_IShellLink, |
| 1711 | (void **) &shelllink_ptr); |
| 1712 | |
| 1713 | if (SUCCEEDED(hres)) /* If the instantiation was successful... */ |
| 1714 | { |
| 1715 | /* ...Then build a PersistFile interface for the ShellLink so we can |
| 1716 | * save it as a file after we build it. */ |
| 1717 | hres = shelllink_ptr->lpVtbl->QueryInterface(shelllink_ptr, |
| 1718 | &IID_IPersistFile, (void **) &persistfile_ptr); |
| 1719 | |
| 1720 | if (SUCCEEDED(hres)) |
| 1721 | { |
| 1722 | wchar_t wsz[BUFSIZE]; |
| 1723 | |
| 1724 | /* translate the (possibly) multibyte shortcut filename to windows |
| 1725 | * Unicode so it can be used as a file name. |
| 1726 | */ |
| 1727 | MultiByteToWideChar(CP_ACP, 0, shortcut_name, -1, wsz, BUFSIZE); |
| 1728 | |
| 1729 | /* set the attributes */ |
| 1730 | shelllink_ptr->lpVtbl->SetPath(shelllink_ptr, shortcut_target); |
| 1731 | shelllink_ptr->lpVtbl->SetWorkingDirectory(shelllink_ptr, |
| 1732 | workingdir); |
| 1733 | shelllink_ptr->lpVtbl->SetIconLocation(shelllink_ptr, |
| 1734 | iconfile_path, iconindex); |
| 1735 | shelllink_ptr->lpVtbl->SetArguments(shelllink_ptr, shortcut_args); |
| 1736 | |
| 1737 | /* save the shortcut to a file and return the PersistFile object*/ |
| 1738 | persistfile_ptr->lpVtbl->Save(persistfile_ptr, wsz, 1); |
| 1739 | persistfile_ptr->lpVtbl->Release(persistfile_ptr); |
| 1740 | } |
| 1741 | else |
| 1742 | { |
| 1743 | printf("QueryInterface Error\n"); |
| 1744 | return FAIL; |
| 1745 | } |
| 1746 | |
| 1747 | /* Return the ShellLink object */ |
| 1748 | shelllink_ptr->lpVtbl->Release(shelllink_ptr); |
| 1749 | } |
| 1750 | else |
| 1751 | { |
| 1752 | printf("CoCreateInstance Error - hres = %08x\n", (int)hres); |
| 1753 | return FAIL; |
| 1754 | } |
| 1755 | |
| 1756 | return OK; |
| 1757 | } |
| 1758 | |
| 1759 | /* |
| 1760 | * Build a path to where we will put a specified link. |
| 1761 | * |
| 1762 | * Return 0 on error, non-zero on success |
| 1763 | */ |
| 1764 | int |
| 1765 | build_link_name( |
| 1766 | char *link_path, |
| 1767 | const char *link_name, |
| 1768 | const char *shell_folder_name) |
| 1769 | { |
| 1770 | char shell_folder_path[BUFSIZE]; |
| 1771 | |
| 1772 | if (get_shell_folder_path(shell_folder_path, shell_folder_name) == FAIL) |
| 1773 | { |
| 1774 | printf("An error occurred while attempting to find the path to %s.\n", |
| 1775 | shell_folder_name); |
| 1776 | return FAIL; |
| 1777 | } |
| 1778 | |
| 1779 | /* Make sure the directory exists (create Start Menu\Programs\Vim). |
| 1780 | * Ignore errors if it already exists. */ |
| 1781 | vim_mkdir(shell_folder_path, 0755); |
| 1782 | |
| 1783 | /* build the path to the shortcut and the path to gvim.exe */ |
| 1784 | sprintf(link_path, "%s\\%s.lnk", shell_folder_path, link_name); |
| 1785 | |
| 1786 | return OK; |
| 1787 | } |
| 1788 | |
| 1789 | static int |
| 1790 | build_shortcut( |
| 1791 | const char *name, /* Name of the shortcut */ |
| 1792 | const char *exename, /* Name of the executable (e.g., vim.exe) */ |
| 1793 | const char *args, |
| 1794 | const char *shell_folder, |
| 1795 | const char *workingdir) |
| 1796 | { |
| 1797 | char executable_path[BUFSIZE]; |
| 1798 | char link_name[BUFSIZE]; |
| 1799 | |
| 1800 | sprintf(executable_path, "%s\\%s", installdir, exename); |
| 1801 | |
| 1802 | if (build_link_name(link_name, name, shell_folder) == FAIL) |
| 1803 | { |
| 1804 | printf("An error has occurred. A shortcut to %s will not be created %s.\n", |
| 1805 | name, |
| 1806 | *shell_folder == 'd' ? "on the desktop" : "in the Start menu"); |
| 1807 | return FAIL; |
| 1808 | } |
| 1809 | |
| 1810 | /* Create the shortcut: */ |
| 1811 | return create_shortcut(link_name, executable_path, 0, |
| 1812 | executable_path, args, workingdir); |
| 1813 | } |
| 1814 | |
| 1815 | /* |
| 1816 | * We used to use "homedir" as the working directory, but that is a bad choice |
| 1817 | * on multi-user systems. Not specifying a directory appears to work best. |
| 1818 | */ |
| 1819 | #define WORKDIR "" |
| 1820 | |
| 1821 | /* |
| 1822 | * Create shortcut(s) in the Start Menu\Programs\Vim folder. |
| 1823 | */ |
| 1824 | static void |
| 1825 | install_start_menu(int idx) |
| 1826 | { |
| 1827 | need_uninstall_entry = 1; |
| 1828 | printf("Creating start menu\n"); |
| 1829 | if (has_vim) |
| 1830 | { |
| 1831 | if (build_shortcut("Vim", "vim.exe", "", |
| 1832 | VIM_STARTMENU, WORKDIR) == FAIL) |
| 1833 | return; |
| 1834 | if (build_shortcut("Vim Read-only", "vim.exe", "-R", |
| 1835 | VIM_STARTMENU, WORKDIR) == FAIL) |
| 1836 | return; |
| 1837 | if (build_shortcut("Vim Diff", "vim.exe", "-d", |
| 1838 | VIM_STARTMENU, WORKDIR) == FAIL) |
| 1839 | return; |
| 1840 | } |
| 1841 | if (has_gvim) |
| 1842 | { |
| 1843 | if (build_shortcut("gVim", "gvim.exe", "", |
| 1844 | VIM_STARTMENU, WORKDIR) == FAIL) |
| 1845 | return; |
| 1846 | if (build_shortcut("gVim Easy", "gvim.exe", "-y", |
| 1847 | VIM_STARTMENU, WORKDIR) == FAIL) |
| 1848 | return; |
| 1849 | if (build_shortcut("gVim Read-only", "gvim.exe", "-R", |
| 1850 | VIM_STARTMENU, WORKDIR) == FAIL) |
| 1851 | return; |
| 1852 | if (build_shortcut("gVim Diff", "gvim.exe", "-d", |
| 1853 | VIM_STARTMENU, WORKDIR) == FAIL) |
| 1854 | return; |
| 1855 | } |
| 1856 | if (build_shortcut("Uninstall", |
| 1857 | interactive ? "uninstal.exe" : "uninstall-gui.exe", "", |
| 1858 | VIM_STARTMENU, installdir) == FAIL) |
| 1859 | return; |
| 1860 | /* For Windows NT the working dir of the vimtutor.bat must be right, |
| 1861 | * otherwise gvim.exe won't be found and using gvimbat doesn't work. */ |
| 1862 | if (build_shortcut("Vim tutor", "vimtutor.bat", "", |
| 1863 | VIM_STARTMENU, installdir) == FAIL) |
| 1864 | return; |
| 1865 | if (build_shortcut("Help", has_gvim ? "gvim.exe" : "vim.exe", "-c h", |
| 1866 | VIM_STARTMENU, WORKDIR) == FAIL) |
| 1867 | return; |
| 1868 | { |
| 1869 | char shell_folder_path[BUFSIZE]; |
| 1870 | |
| 1871 | /* Creating the URL shortcut works a bit differently... */ |
| 1872 | if (get_shell_folder_path(shell_folder_path, VIM_STARTMENU) == FAIL) |
| 1873 | { |
| 1874 | printf("Finding the path of the Start menu failed\n"); |
| 1875 | return ; |
| 1876 | } |
| 1877 | add_pathsep(shell_folder_path); |
| 1878 | strcat(shell_folder_path, "Vim Online.url"); |
| 1879 | if (!WritePrivateProfileString("InternetShortcut", "URL", |
| 1880 | "http://vim.sf.net/", shell_folder_path)) |
| 1881 | { |
| 1882 | printf("Creating the Vim online URL failed\n"); |
| 1883 | return; |
| 1884 | } |
| 1885 | } |
| 1886 | } |
| 1887 | |
| 1888 | static void |
| 1889 | toggle_startmenu_choice(int idx) |
| 1890 | { |
| 1891 | if (choices[idx].installfunc == NULL) |
| 1892 | { |
| 1893 | choices[idx].installfunc = install_start_menu; |
| 1894 | choices[idx].text = "Add Vim to the Start menu"; |
| 1895 | } |
| 1896 | else |
| 1897 | { |
| 1898 | choices[idx].installfunc = NULL; |
| 1899 | choices[idx].text = "Do NOT add Vim to the Start menu"; |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | /* |
| 1904 | * Function to actually create the shortcuts |
| 1905 | * |
| 1906 | * Currently I am supplying no working directory to the shortcut. This |
| 1907 | * means that the initial working dir will be: |
| 1908 | * - the location of the shortcut if no file is supplied |
| 1909 | * - the location of the file being edited if a file is supplied (ie via |
| 1910 | * drag and drop onto the shortcut). |
| 1911 | */ |
| 1912 | void |
| 1913 | install_shortcut_gvim(int idx) |
| 1914 | { |
| 1915 | /* Create shortcut(s) on the desktop */ |
| 1916 | if (choices[idx].arg) |
| 1917 | { |
| 1918 | (void)build_shortcut(icon_names[0], "gvim.exe", |
| 1919 | "", "desktop", WORKDIR); |
| 1920 | need_uninstall_entry = 1; |
| 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | void |
| 1925 | install_shortcut_evim(int idx) |
| 1926 | { |
| 1927 | if (choices[idx].arg) |
| 1928 | { |
| 1929 | (void)build_shortcut(icon_names[1], "gvim.exe", |
| 1930 | "-y", "desktop", WORKDIR); |
| 1931 | need_uninstall_entry = 1; |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | void |
| 1936 | install_shortcut_gview(int idx) |
| 1937 | { |
| 1938 | if (choices[idx].arg) |
| 1939 | { |
| 1940 | (void)build_shortcut(icon_names[2], "gvim.exe", |
| 1941 | "-R", "desktop", WORKDIR); |
| 1942 | need_uninstall_entry = 1; |
| 1943 | } |
| 1944 | } |
| 1945 | |
| 1946 | void |
| 1947 | toggle_shortcut_choice(int idx) |
| 1948 | { |
| 1949 | char *arg; |
| 1950 | |
| 1951 | if (choices[idx].installfunc == install_shortcut_gvim) |
| 1952 | arg = "gVim"; |
| 1953 | else if (choices[idx].installfunc == install_shortcut_evim) |
| 1954 | arg = "gVim Easy"; |
| 1955 | else |
| 1956 | arg = "gVim Read-only"; |
| 1957 | if (choices[idx].arg) |
| 1958 | { |
| 1959 | choices[idx].arg = 0; |
| 1960 | alloc_text(idx, "Do NOT create a desktop icon for %s", arg); |
| 1961 | } |
| 1962 | else |
| 1963 | { |
| 1964 | choices[idx].arg = 1; |
| 1965 | alloc_text(idx, "Create a desktop icon for %s", arg); |
| 1966 | } |
| 1967 | } |
| 1968 | #endif /* WIN3264 */ |
| 1969 | |
| 1970 | static void |
| 1971 | init_startmenu_choice(void) |
| 1972 | { |
| 1973 | #ifdef WIN3264 |
| 1974 | /* Start menu */ |
| 1975 | choices[choice_count].changefunc = toggle_startmenu_choice; |
| 1976 | choices[choice_count].installfunc = NULL; |
| 1977 | choices[choice_count].active = 1; |
| 1978 | toggle_startmenu_choice(choice_count); /* set the text */ |
| 1979 | ++choice_count; |
| 1980 | #else |
| 1981 | add_dummy_choice(); |
| 1982 | #endif |
| 1983 | } |
| 1984 | |
| 1985 | /* |
| 1986 | * Add the choice for the desktop shortcuts. |
| 1987 | */ |
| 1988 | static void |
| 1989 | init_shortcut_choices(void) |
| 1990 | { |
| 1991 | #ifdef WIN3264 |
| 1992 | /* Shortcut to gvim */ |
| 1993 | choices[choice_count].text = NULL; |
| 1994 | choices[choice_count].arg = 0; |
| 1995 | choices[choice_count].active = has_gvim; |
| 1996 | choices[choice_count].changefunc = toggle_shortcut_choice; |
| 1997 | choices[choice_count].installfunc = install_shortcut_gvim; |
| 1998 | toggle_shortcut_choice(choice_count); |
| 1999 | ++choice_count; |
| 2000 | |
| 2001 | /* Shortcut to evim */ |
| 2002 | choices[choice_count].text = NULL; |
| 2003 | choices[choice_count].arg = 0; |
| 2004 | choices[choice_count].active = has_gvim; |
| 2005 | choices[choice_count].changefunc = toggle_shortcut_choice; |
| 2006 | choices[choice_count].installfunc = install_shortcut_evim; |
| 2007 | toggle_shortcut_choice(choice_count); |
| 2008 | ++choice_count; |
| 2009 | |
| 2010 | /* Shortcut to gview */ |
| 2011 | choices[choice_count].text = NULL; |
| 2012 | choices[choice_count].arg = 0; |
| 2013 | choices[choice_count].active = has_gvim; |
| 2014 | choices[choice_count].changefunc = toggle_shortcut_choice; |
| 2015 | choices[choice_count].installfunc = install_shortcut_gview; |
| 2016 | toggle_shortcut_choice(choice_count); |
| 2017 | ++choice_count; |
| 2018 | #else |
| 2019 | add_dummy_choice(); |
| 2020 | add_dummy_choice(); |
| 2021 | add_dummy_choice(); |
| 2022 | #endif |
| 2023 | } |
| 2024 | |
| 2025 | #ifdef WIN3264 |
| 2026 | /* |
| 2027 | * Attempt to register OLE for Vim. |
| 2028 | */ |
| 2029 | static void |
| 2030 | install_OLE_register(void) |
| 2031 | { |
| 2032 | char register_command_string[BUFSIZE + 30]; |
| 2033 | |
| 2034 | printf("\n--- Attempting to register Vim with OLE ---\n"); |
| 2035 | printf("(There is no message whether this works or not.)\n"); |
| 2036 | |
| 2037 | #ifndef __CYGWIN__ |
| 2038 | sprintf(register_command_string, "\"%s\\gvim.exe\" -silent -register", installdir); |
| 2039 | #else |
| 2040 | /* handle this differently for Cygwin which sometimes has trouble with |
| 2041 | * Windows-style pathnames here. */ |
| 2042 | sprintf(register_command_string, "./gvim.exe -silent -register"); |
| 2043 | #endif |
| 2044 | system(register_command_string); |
| 2045 | } |
| 2046 | #endif /* WIN3264 */ |
| 2047 | |
| 2048 | /* |
| 2049 | * Remove the last part of directory "path[]" to get its parent, and put the |
| 2050 | * result in "to[]". |
| 2051 | */ |
| 2052 | static void |
| 2053 | dir_remove_last(const char *path, char to[BUFSIZE]) |
| 2054 | { |
| 2055 | char c; |
| 2056 | long last_char_to_copy; |
| 2057 | long path_length = strlen(path); |
| 2058 | |
| 2059 | /* skip the last character just in case it is a '\\' */ |
| 2060 | last_char_to_copy = path_length - 2; |
| 2061 | c = path[last_char_to_copy]; |
| 2062 | |
| 2063 | while (c != '\\') |
| 2064 | { |
| 2065 | last_char_to_copy--; |
| 2066 | c = path[last_char_to_copy]; |
| 2067 | } |
| 2068 | |
| 2069 | strncpy(to, path, (size_t)last_char_to_copy); |
| 2070 | to[last_char_to_copy] = NUL; |
| 2071 | } |
| 2072 | |
| 2073 | static void |
| 2074 | set_directories_text(int idx) |
| 2075 | { |
| 2076 | if (vimfiles_dir_choice == (int)vimfiles_dir_none) |
| 2077 | alloc_text(idx, "Do NOT create plugin directories%s", ""); |
| 2078 | else |
| 2079 | alloc_text(idx, "Create plugin directories: %s", |
| 2080 | vimfiles_dir_choices[vimfiles_dir_choice]); |
| 2081 | } |
| 2082 | |
| 2083 | /* |
| 2084 | * Change the directory that the vim plugin directories will be created in: |
| 2085 | * $HOME, $VIM or nowhere. |
| 2086 | */ |
| 2087 | static void |
| 2088 | change_directories_choice(int idx) |
| 2089 | { |
| 2090 | int choice_count = TABLE_SIZE(vimfiles_dir_choices); |
| 2091 | |
| 2092 | /* Don't offer the $HOME choice if $HOME isn't set. */ |
| 2093 | if (getenv("HOME") == NULL) |
| 2094 | --choice_count; |
| 2095 | vimfiles_dir_choice = get_choice(vimfiles_dir_choices, choice_count); |
| 2096 | set_directories_text(idx); |
| 2097 | } |
| 2098 | |
| 2099 | /* |
| 2100 | * Create the plugin directories... |
| 2101 | */ |
| 2102 | /*ARGSUSED*/ |
| 2103 | static void |
| 2104 | install_vimfilesdir(int idx) |
| 2105 | { |
| 2106 | int i; |
| 2107 | char *p; |
| 2108 | char vimdir_path[BUFSIZE]; |
| 2109 | char vimfiles_path[BUFSIZE]; |
| 2110 | char tmp_dirname[BUFSIZE]; |
| 2111 | |
| 2112 | /* switch on the location that the user wants the plugin directories |
| 2113 | * built in */ |
| 2114 | switch (vimfiles_dir_choice) |
| 2115 | { |
| 2116 | case vimfiles_dir_vim: |
| 2117 | { |
| 2118 | /* Go to the %VIM% directory - check env first, then go one dir |
| 2119 | * below installdir if there is no %VIM% environment variable. |
| 2120 | * The accuracy of $VIM is checked in inspect_system(), so we |
| 2121 | * can be sure it is ok to use here. */ |
| 2122 | p = getenv("VIM"); |
| 2123 | if (p == NULL) /* No $VIM in path */ |
| 2124 | dir_remove_last(installdir, vimdir_path); |
| 2125 | else |
| 2126 | strcpy(vimdir_path, p); |
| 2127 | break; |
| 2128 | } |
| 2129 | case vimfiles_dir_home: |
| 2130 | { |
| 2131 | /* Find the $HOME directory. Its existence was already checked. */ |
| 2132 | p = getenv("HOME"); |
| 2133 | if (p == NULL) |
| 2134 | { |
| 2135 | printf("Internal error: $HOME is NULL\n"); |
| 2136 | p = "c:\\"; |
| 2137 | } |
| 2138 | strcpy(vimdir_path, p); |
| 2139 | break; |
| 2140 | } |
| 2141 | case vimfiles_dir_none: |
| 2142 | { |
| 2143 | /* Do not create vim plugin directory */ |
| 2144 | return; |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | /* Now, just create the directory. If it already exists, it will fail |
| 2149 | * silently. */ |
| 2150 | sprintf(vimfiles_path, "%s\\vimfiles", vimdir_path); |
| 2151 | vim_mkdir(vimfiles_path, 0755); |
| 2152 | |
| 2153 | printf("Creating the following directories in \"%s\":\n", vimfiles_path); |
| 2154 | for (i = 0; i < TABLE_SIZE(vimfiles_subdirs); i++) |
| 2155 | { |
| 2156 | sprintf(tmp_dirname, "%s\\%s", vimfiles_path, vimfiles_subdirs[i]); |
| 2157 | printf(" %s", vimfiles_subdirs[i]); |
| 2158 | vim_mkdir(tmp_dirname, 0755); |
| 2159 | } |
| 2160 | printf("\n"); |
| 2161 | } |
| 2162 | |
| 2163 | /* |
| 2164 | * Add the creation of runtime files to the setup sequence. |
| 2165 | */ |
| 2166 | static void |
| 2167 | init_directories_choice(void) |
| 2168 | { |
| 2169 | struct stat st; |
| 2170 | char tmp_dirname[BUFSIZE]; |
| 2171 | char *p; |
| 2172 | |
| 2173 | choices[choice_count].text = alloc(150); |
| 2174 | choices[choice_count].changefunc = change_directories_choice; |
| 2175 | choices[choice_count].installfunc = install_vimfilesdir; |
| 2176 | choices[choice_count].active = 1; |
| 2177 | |
| 2178 | /* Check if the "compiler" directory already exists. That's a good |
| 2179 | * indication that the plugin directories were already created. */ |
| 2180 | if (getenv("HOME") != NULL) |
| 2181 | { |
| 2182 | vimfiles_dir_choice = (int)vimfiles_dir_home; |
| 2183 | sprintf(tmp_dirname, "%s\\vimfiles\\compiler", getenv("HOME")); |
| 2184 | if (stat(tmp_dirname, &st) == 0) |
| 2185 | vimfiles_dir_choice = (int)vimfiles_dir_none; |
| 2186 | } |
| 2187 | else |
| 2188 | { |
| 2189 | vimfiles_dir_choice = (int)vimfiles_dir_vim; |
| 2190 | p = getenv("VIM"); |
| 2191 | if (p == NULL) /* No $VIM in path, use the install dir */ |
| 2192 | dir_remove_last(installdir, tmp_dirname); |
| 2193 | else |
| 2194 | strcpy(tmp_dirname, p); |
| 2195 | strcat(tmp_dirname, "\\vimfiles\\compiler"); |
| 2196 | if (stat(tmp_dirname, &st) == 0) |
| 2197 | vimfiles_dir_choice = (int)vimfiles_dir_none; |
| 2198 | } |
| 2199 | |
| 2200 | set_directories_text(choice_count); |
| 2201 | ++choice_count; |
| 2202 | } |
| 2203 | |
| 2204 | /* |
| 2205 | * Setup the choices and the default values. |
| 2206 | */ |
| 2207 | static void |
| 2208 | setup_choices(void) |
| 2209 | { |
| 2210 | /* install the batch files */ |
| 2211 | init_bat_choices(); |
| 2212 | |
| 2213 | /* (over) write _vimrc file */ |
| 2214 | init_vimrc_choices(); |
| 2215 | |
| 2216 | /* Whether to add Vim to the popup menu */ |
| 2217 | init_popup_choice(); |
| 2218 | |
| 2219 | /* Whether to add Vim to the "Open With..." menu */ |
| 2220 | init_openwith_choice(); |
| 2221 | |
| 2222 | /* Whether to add Vim to the Start Menu. */ |
| 2223 | init_startmenu_choice(); |
| 2224 | |
| 2225 | /* Whether to add shortcuts to the Desktop. */ |
| 2226 | init_shortcut_choices(); |
| 2227 | |
| 2228 | /* Whether to create the runtime directories. */ |
| 2229 | init_directories_choice(); |
| 2230 | } |
| 2231 | |
| 2232 | static void |
| 2233 | print_cmd_line_help(void) |
| 2234 | { |
| 2235 | printf("Vim installer non-interactive command line arguments:\n"); |
| 2236 | printf("\n"); |
| 2237 | printf("-create-batfiles [vim gvim evim view gview vimdiff gvimdiff]\n"); |
| 2238 | printf(" Create .bat files for Vim variants in the Windows directory.\n"); |
| 2239 | printf("-create-vimrc\n"); |
| 2240 | printf(" Create a default _vimrc file if one does not already exist.\n"); |
| 2241 | printf("-install-popup\n"); |
| 2242 | printf(" Install the Edit-with-Vim context menu entry\n"); |
| 2243 | printf("-install-openwith\n"); |
| 2244 | printf(" Add Vim to the \"Open With...\" context menu list\n"); |
| 2245 | #ifdef WIN3264 |
| 2246 | printf("-add-start-menu"); |
| 2247 | printf(" Add Vim to the start menu\n"); |
| 2248 | printf("-install-icons"); |
| 2249 | printf(" Create icons for gVim executables on the desktop\n"); |
| 2250 | #endif |
| 2251 | printf("-create-directories [vim|home]\n"); |
| 2252 | printf(" Create runtime directories to drop plugins into; in the $VIM\n"); |
| 2253 | printf(" or $HOME directory\n"); |
| 2254 | #ifdef WIN3264 |
| 2255 | printf("-register-OLE"); |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 2256 | printf(" Ignored\n"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2257 | #endif |
| 2258 | printf("\n"); |
| 2259 | } |
| 2260 | |
| 2261 | /* |
| 2262 | * Setup installation choices based on command line switches |
| 2263 | */ |
| 2264 | static void |
| 2265 | command_line_setup_choices(int argc, char **argv) |
| 2266 | { |
| 2267 | int i, j; |
| 2268 | |
| 2269 | for (i = 1; i < argc; i++) |
| 2270 | { |
| 2271 | if (strcmp(argv[i], "-create-batfiles") == 0) |
| 2272 | { |
| 2273 | if (i + 1 == argc) |
| 2274 | continue; |
| 2275 | while (argv[i + 1][0] != '-' && i < argc) |
| 2276 | { |
| 2277 | i++; |
| 2278 | for (j = 1; j < TARGET_COUNT; ++j) |
| 2279 | if ((targets[j].exenamearg[0] == 'g' ? has_gvim : has_vim) |
| 2280 | && strcmp(argv[i], targets[j].name) == 0) |
| 2281 | { |
| 2282 | init_bat_choice(j); |
| 2283 | break; |
| 2284 | } |
| 2285 | if (j == TARGET_COUNT) |
| 2286 | printf("%s is not a valid choice for -create-batfiles\n", |
| 2287 | argv[i]); |
| 2288 | |
| 2289 | if (i + 1 == argc) |
| 2290 | break; |
| 2291 | } |
| 2292 | } |
| 2293 | else if (strcmp(argv[i], "-create-vimrc") == 0) |
| 2294 | { |
| 2295 | /* Setup default vimrc choices. If there is already a _vimrc file, |
| 2296 | * it will NOT be overwritten. |
| 2297 | */ |
| 2298 | init_vimrc_choices(); |
| 2299 | } |
| 2300 | else if (strcmp(argv[i], "-install-popup") == 0) |
| 2301 | { |
| 2302 | init_popup_choice(); |
| 2303 | } |
| 2304 | else if (strcmp(argv[i], "-install-openwith") == 0) |
| 2305 | { |
| 2306 | init_openwith_choice(); |
| 2307 | } |
| 2308 | else if (strcmp(argv[i], "-add-start-menu") == 0) |
| 2309 | { |
| 2310 | init_startmenu_choice(); |
| 2311 | } |
| 2312 | else if (strcmp(argv[i], "-install-icons") == 0) |
| 2313 | { |
| 2314 | init_shortcut_choices(); |
| 2315 | } |
| 2316 | else if (strcmp(argv[i], "-create-directories") == 0) |
| 2317 | { |
| 2318 | init_directories_choice(); |
| 2319 | if (argv[i + 1][0] != '-') |
| 2320 | { |
| 2321 | i++; |
| 2322 | if (strcmp(argv[i], "vim") == 0) |
| 2323 | vimfiles_dir_choice = (int)vimfiles_dir_vim; |
| 2324 | else if (strcmp(argv[i], "home") == 0) |
| 2325 | { |
| 2326 | if (getenv("HOME") == NULL) /* No $HOME in environment */ |
| 2327 | vimfiles_dir_choice = (int)vimfiles_dir_vim; |
| 2328 | else |
| 2329 | vimfiles_dir_choice = (int)vimfiles_dir_home; |
| 2330 | } |
| 2331 | else |
| 2332 | { |
| 2333 | printf("Unknown argument for -create-directories: %s\n", |
| 2334 | argv[i]); |
| 2335 | print_cmd_line_help(); |
| 2336 | } |
| 2337 | } |
| 2338 | else /* No choice specified, default to vim directory */ |
| 2339 | vimfiles_dir_choice = (int)vimfiles_dir_vim; |
| 2340 | } |
| 2341 | #ifdef WIN3264 |
| 2342 | else if (strcmp(argv[i], "-register-OLE") == 0) |
| 2343 | { |
| 2344 | /* This is always done when gvim is found */ |
| 2345 | } |
| 2346 | #endif |
| 2347 | else /* Unknown switch */ |
| 2348 | { |
| 2349 | printf("Got unknown argument argv[%d] = %s\n", i, argv[i]); |
| 2350 | print_cmd_line_help(); |
| 2351 | } |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | |
| 2356 | /* |
| 2357 | * Show a few screens full of helpful information. |
| 2358 | */ |
| 2359 | static void |
| 2360 | show_help(void) |
| 2361 | { |
| 2362 | static char *(items[]) = |
| 2363 | { |
| 2364 | "Installing .bat files\n" |
| 2365 | "---------------------\n" |
| 2366 | "The vim.bat file is written in one of the directories in $PATH.\n" |
| 2367 | "This makes it possible to start Vim from the command line.\n" |
| 2368 | "If vim.exe can be found in $PATH, the choice for vim.bat will not be\n" |
| 2369 | "present. It is assumed you will use the existing vim.exe.\n" |
| 2370 | "If vim.bat can already be found in $PATH this is probably for an old\n" |
| 2371 | "version of Vim (but this is not checked!). You can overwrite it.\n" |
| 2372 | "If no vim.bat already exists, you can select one of the directories in\n" |
| 2373 | "$PATH for creating the batch file, or disable creating a vim.bat file.\n" |
| 2374 | "\n" |
| 2375 | "If you choose not to create the vim.bat file, Vim can still be executed\n" |
| 2376 | "in other ways, but not from the command line.\n" |
| 2377 | "\n" |
| 2378 | "The same applies to choices for gvim, evim, (g)view, and (g)vimdiff.\n" |
| 2379 | "The first item can be used to change the path for all of them.\n" |
| 2380 | , |
| 2381 | "Creating a _vimrc file\n" |
| 2382 | "----------------------\n" |
| 2383 | "The _vimrc file is used to set options for how Vim behaves.\n" |
| 2384 | "The install program can create a _vimrc file with a few basic choices.\n" |
| 2385 | "You can edit this file later to tune your preferences.\n" |
| 2386 | "If you already have a _vimrc or .vimrc file it can be overwritten.\n" |
| 2387 | "Don't do that if you have made changes to it.\n" |
| 2388 | , |
| 2389 | "Vim features\n" |
| 2390 | "------------\n" |
| 2391 | "(this choice is only available when creating a _vimrc file)\n" |
| 2392 | "1. Vim can run in Vi-compatible mode. Many nice Vim features are then\n" |
| 2393 | " disabled. In the not-Vi-compatible mode Vim is still mostly Vi\n" |
| 2394 | " compatible, but adds nice features like multi-level undo. Only\n" |
| 2395 | " choose Vi-compatible if you really need full Vi compatibility.\n" |
| 2396 | "2. Running Vim with some enhancements is useful when you want some of\n" |
| 2397 | " the nice Vim features, but have a slow computer and want to keep it\n" |
| 2398 | " really fast.\n" |
| 2399 | "3. Syntax highlighting shows many files in color. Not only does this look\n" |
| 2400 | " nice, it also makes it easier to spot errors and you can work faster.\n" |
| 2401 | " The other features include editing compressed files.\n" |
| 2402 | , |
| 2403 | "Windows key mapping\n" |
| 2404 | "-------------------\n" |
| 2405 | "(this choice is only available when creating a _vimrc file)\n" |
| 2406 | "Under MS-Windows the CTRL-C key copies text to the clipboard and CTRL-V\n" |
| 2407 | "pastes text from the clipboard. There are a few more keys like these.\n" |
| 2408 | "Unfortunately, in Vim these keys normally have another meaning.\n" |
| 2409 | "1. Choose to have the keys like they normally are in Vim (useful if you\n" |
| 2410 | " also use Vim on other systems).\n" |
| 2411 | "2. Choose to have the keys work like they are used on MS-Windows (useful\n" |
| 2412 | " if you mostly work on MS-Windows).\n" |
| 2413 | , |
| 2414 | "Mouse use\n" |
| 2415 | "---------\n" |
| 2416 | "(this choice is only available when creating a _vimrc file)\n" |
| 2417 | "The right mouse button can be used in two ways:\n" |
| 2418 | "1. The Unix way is to extend an existing selection. The popup menu is\n" |
| 2419 | " not available.\n" |
| 2420 | "2. The MS-Windows way is to show a popup menu, which allows you to\n" |
| 2421 | " copy/paste text, undo/redo, etc. Extending the selection can still be\n" |
| 2422 | " done by keeping SHIFT pressed while using the left mouse button\n" |
| 2423 | , |
| 2424 | "Edit-with-Vim context menu entry\n" |
| 2425 | "--------------------------------\n" |
| 2426 | "(this choice is only available when gvim.exe and gvimext.dll are present)\n" |
| 2427 | "You can associate different file types with Vim, so that you can (double)\n" |
| 2428 | "click on a file to edit it with Vim. This means you have to individually\n" |
| 2429 | "select each file type.\n" |
| 2430 | "An alternative is the option offered here: Install an \"Edit with Vim\"\n" |
| 2431 | "entry in the popup menu for the right mouse button. This means you can\n" |
| 2432 | "edit any file with Vim.\n" |
| 2433 | , |
| 2434 | "\"Open With...\" context menu entry\n" |
| 2435 | "--------------------------------\n" |
| 2436 | "(this choice is only available when gvim.exe is present)\n" |
| 2437 | "This option adds Vim to the \"Open With...\" entry in the popup menu for\n" |
| 2438 | "the right mouse button. This also makes it possible to edit HTML files\n" |
| 2439 | "directly from Internet Explorer.\n" |
| 2440 | , |
| 2441 | "Add Vim to the Start menu\n" |
| 2442 | "-------------------------\n" |
| 2443 | "In Windows 95 and later, Vim can be added to the Start menu. This will\n" |
| 2444 | "create a submenu with an entry for vim, gvim, evim, vimdiff, etc..\n" |
| 2445 | , |
| 2446 | "Icons on the desktop\n" |
| 2447 | "--------------------\n" |
| 2448 | "(these choices are only available when installing gvim)\n" |
| 2449 | "In Windows 95 and later, shortcuts (icons) can be created on the Desktop.\n" |
| 2450 | , |
| 2451 | "Create plugin directories\n" |
| 2452 | "-------------------------\n" |
| 2453 | "Plugin directories allow extending Vim by dropping a file into a directory.\n" |
| 2454 | "This choice allows creating them in $HOME (if you have a home directory) or\n" |
| 2455 | "$VIM (used for everybody on the system).\n" |
| 2456 | , |
| 2457 | NULL |
| 2458 | }; |
| 2459 | int i; |
| 2460 | int c; |
| 2461 | |
| 2462 | rewind(stdin); |
| 2463 | printf("\n"); |
| 2464 | for (i = 0; items[i] != NULL; ++i) |
| 2465 | { |
| 2466 | printf(items[i]); |
| 2467 | printf("\n"); |
| 2468 | printf("Hit Enter to continue, b (back) or q (quit help): "); |
| 2469 | c = getchar(); |
| 2470 | rewind(stdin); |
| 2471 | if (c == 'b' || c == 'B') |
| 2472 | { |
| 2473 | if (i == 0) |
| 2474 | --i; |
| 2475 | else |
| 2476 | i -= 2; |
| 2477 | } |
| 2478 | if (c == 'q' || c == 'Q') |
| 2479 | break; |
| 2480 | printf("\n"); |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | /* |
| 2485 | * Install the choices. |
| 2486 | */ |
| 2487 | static void |
| 2488 | install(void) |
| 2489 | { |
| 2490 | int i; |
| 2491 | |
| 2492 | /* Install the selected choices. */ |
| 2493 | for (i = 0; i < choice_count; ++i) |
| 2494 | if (choices[i].installfunc != NULL && choices[i].active) |
| 2495 | (choices[i].installfunc)(i); |
| 2496 | |
| 2497 | /* Add some entries to the registry, if needed. */ |
| 2498 | if (install_popup |
| 2499 | || install_openwith |
| 2500 | || (need_uninstall_entry && interactive) |
| 2501 | || !interactive) |
| 2502 | install_registry(); |
| 2503 | |
| 2504 | #ifdef WIN3264 |
| 2505 | /* Register gvim with OLE. */ |
| 2506 | if (has_gvim) |
| 2507 | install_OLE_register(); |
| 2508 | #endif |
| 2509 | } |
| 2510 | |
| 2511 | /* |
| 2512 | * request_choice |
| 2513 | */ |
| 2514 | static void |
| 2515 | request_choice(void) |
| 2516 | { |
| 2517 | int i; |
| 2518 | |
| 2519 | printf("\n\nInstall will do for you:\n"); |
| 2520 | for (i = 0; i < choice_count; ++i) |
| 2521 | if (choices[i].active) |
| 2522 | printf("%2d %s\n", i + 1, choices[i].text); |
| 2523 | printf("To change an item, enter its number\n\n"); |
| 2524 | printf("Enter item number, h (help), d (do it) or q (quit): "); |
| 2525 | } |
| 2526 | |
| 2527 | int |
| 2528 | main(int argc, char **argv) |
| 2529 | { |
| 2530 | int i; |
| 2531 | char buf[BUFSIZE]; |
| 2532 | |
| 2533 | /* |
| 2534 | * Run interactively if there are no command line arguments. |
| 2535 | */ |
| 2536 | if (argc > 1) |
| 2537 | interactive = 0; |
| 2538 | else |
| 2539 | interactive = 1; |
| 2540 | |
| 2541 | /* Initialize this program. */ |
| 2542 | do_inits(argv); |
| 2543 | |
| 2544 | #ifdef WIN3264 |
| 2545 | if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0) |
| 2546 | { |
| 2547 | /* Only check for already installed Vims. Used by NSIS installer. */ |
Bram Moolenaar | 442b422 | 2010-05-24 21:34:22 +0200 | [diff] [blame] | 2548 | i = uninstall_check(1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2549 | |
| 2550 | /* Find the value of $VIM, because NSIS isn't able to do this by |
| 2551 | * itself. */ |
| 2552 | get_vim_env(); |
| 2553 | |
| 2554 | /* When nothing found exit quietly. If something found wait for |
Bram Moolenaar | b230bd5 | 2010-05-25 21:02:00 +0200 | [diff] [blame] | 2555 | * a little while, so that the user can read the messages. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2556 | if (i) |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 2557 | sleep(3); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2558 | exit(0); |
| 2559 | } |
| 2560 | #endif |
| 2561 | |
| 2562 | printf("This program sets up the installation of Vim " |
| 2563 | VIM_VERSION_MEDIUM "\n\n"); |
| 2564 | |
| 2565 | /* Check if the user unpacked the archives properly. */ |
| 2566 | check_unpack(); |
| 2567 | |
| 2568 | #ifdef WIN3264 |
| 2569 | /* Check for already installed Vims. */ |
| 2570 | if (interactive) |
Bram Moolenaar | 442b422 | 2010-05-24 21:34:22 +0200 | [diff] [blame] | 2571 | uninstall_check(0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2572 | #endif |
| 2573 | |
| 2574 | /* Find out information about the system. */ |
| 2575 | inspect_system(); |
| 2576 | |
| 2577 | if (interactive) |
| 2578 | { |
| 2579 | /* Setup all the choices. */ |
| 2580 | setup_choices(); |
| 2581 | |
| 2582 | /* Let the user change choices and finally install (or quit). */ |
| 2583 | for (;;) |
| 2584 | { |
| 2585 | request_choice(); |
| 2586 | rewind(stdin); |
| 2587 | if (scanf("%99s", buf) == 1) |
| 2588 | { |
| 2589 | if (isdigit(buf[0])) |
| 2590 | { |
| 2591 | /* Change a choice. */ |
| 2592 | i = atoi(buf); |
| 2593 | if (i > 0 && i <= choice_count && choices[i - 1].active) |
| 2594 | (choices[i - 1].changefunc)(i - 1); |
| 2595 | else |
| 2596 | printf("\nIllegal choice\n"); |
| 2597 | } |
| 2598 | else if (buf[0] == 'h' || buf[0] == 'H') |
| 2599 | { |
| 2600 | /* Help */ |
| 2601 | show_help(); |
| 2602 | } |
| 2603 | else if (buf[0] == 'd' || buf[0] == 'D') |
| 2604 | { |
| 2605 | /* Install! */ |
| 2606 | install(); |
| 2607 | printf("\nThat finishes the installation. Happy Vimming!\n"); |
| 2608 | break; |
| 2609 | } |
| 2610 | else if (buf[0] == 'q' || buf[0] == 'Q') |
| 2611 | { |
| 2612 | /* Quit */ |
| 2613 | printf("\nExiting without anything done\n"); |
| 2614 | break; |
| 2615 | } |
| 2616 | else |
| 2617 | printf("\nIllegal choice\n"); |
| 2618 | } |
| 2619 | } |
| 2620 | printf("\n"); |
Bram Moolenaar | 442b422 | 2010-05-24 21:34:22 +0200 | [diff] [blame] | 2621 | myexit(0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2622 | } |
| 2623 | else |
| 2624 | { |
| 2625 | /* |
| 2626 | * Run non-interactive - setup according to the command line switches |
| 2627 | */ |
| 2628 | command_line_setup_choices(argc, argv); |
| 2629 | install(); |
Bram Moolenaar | 442b422 | 2010-05-24 21:34:22 +0200 | [diff] [blame] | 2630 | |
| 2631 | /* Avoid that the user has to hit Enter, just wait a little bit to |
| 2632 | * allow reading the messages. */ |
Bram Moolenaar | ab8205e | 2010-07-07 15:14:03 +0200 | [diff] [blame] | 2633 | sleep(2); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2636 | return 0; |
| 2637 | } |