Mercurial > vim
comparison src/dosinst.c @ 15046:c1be7c8bb602 v8.1.0534
patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
commit https://github.com/vim/vim/commit/25a494ce609f54ce240b1986aad16ca27186d646
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Nov 16 19:39:50 2018 +0100
patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
Problem: MS-Windows installer uses different $HOME than Vim.
Solution: Use the Vim logic also in the MS-Windows installer. (Ken Takata,
closes #3564)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 16 Nov 2018 19:45:05 +0100 |
parents | b2308693cb87 |
children | a7b9fa73d238 |
comparison
equal
deleted
inserted
replaced
15045:ad62eff820ee | 15046:c1be7c8bb602 |
---|---|
113 { | 113 { |
114 vimfiles_dir_none = 1, | 114 vimfiles_dir_none = 1, |
115 vimfiles_dir_vim, | 115 vimfiles_dir_vim, |
116 vimfiles_dir_home | 116 vimfiles_dir_home |
117 }; | 117 }; |
118 static char *(vimfiles_dir_choices[]) = | 118 static char *(vimfiles_dir_choices[]) = |
119 { | 119 { |
120 "\nCreate plugin directories:", | 120 "\nCreate plugin directories:", |
121 "No", | 121 "No", |
122 "In the VIM directory", | 122 "In the VIM directory", |
123 "In your HOME directory", | 123 "In your HOME directory", |
124 }; | 124 }; |
125 static int vimfiles_dir_choice; | |
126 | 125 |
127 /* non-zero when selected to install the popup menu entry. */ | 126 /* non-zero when selected to install the popup menu entry. */ |
128 static int install_popup = 0; | 127 static int install_popup = 0; |
129 | 128 |
130 /* non-zero when selected to install the "Open with" entry. */ | 129 /* non-zero when selected to install the "Open with" entry. */ |
739 add_dummy_choice(void) | 738 add_dummy_choice(void) |
740 { | 739 { |
741 choices[choice_count].installfunc = NULL; | 740 choices[choice_count].installfunc = NULL; |
742 choices[choice_count].active = 0; | 741 choices[choice_count].active = 0; |
743 choices[choice_count].changefunc = NULL; | 742 choices[choice_count].changefunc = NULL; |
744 choices[choice_count].installfunc = NULL; | 743 choices[choice_count].text = NULL; |
744 choices[choice_count].arg = 0; | |
745 ++choice_count; | 745 ++choice_count; |
746 } | 746 } |
747 | 747 |
748 /*********************************************** | 748 /*********************************************** |
749 * stuff for creating the batch files. | 749 * stuff for creating the batch files. |
2087 } | 2087 } |
2088 | 2088 |
2089 static void | 2089 static void |
2090 set_directories_text(int idx) | 2090 set_directories_text(int idx) |
2091 { | 2091 { |
2092 int vimfiles_dir_choice = choices[idx].arg; | |
2093 | |
2092 if (vimfiles_dir_choice == (int)vimfiles_dir_none) | 2094 if (vimfiles_dir_choice == (int)vimfiles_dir_none) |
2093 alloc_text(idx, "Do NOT create plugin directories%s", ""); | 2095 alloc_text(idx, "Do NOT create plugin directories%s", ""); |
2094 else | 2096 else |
2095 alloc_text(idx, "Create plugin directories: %s", | 2097 alloc_text(idx, "Create plugin directories: %s", |
2096 vimfiles_dir_choices[vimfiles_dir_choice]); | 2098 vimfiles_dir_choices[vimfiles_dir_choice]); |
2097 } | 2099 } |
2098 | 2100 |
2099 /* | 2101 /* |
2102 * To get the "real" home directory: | |
2103 * - get value of $HOME | |
2104 * - if not found, get value of $HOMEDRIVE$HOMEPATH | |
2105 * - if not found, get value of $USERPROFILE | |
2106 * | |
2107 * This code is based on init_homedir() in misc1.c, keep in sync! | |
2108 */ | |
2109 static char *homedir = NULL; | |
2110 | |
2111 void | |
2112 init_homedir(void) | |
2113 { | |
2114 char *var; | |
2115 char buf[MAX_PATH]; | |
2116 | |
2117 if (homedir != NULL) | |
2118 { | |
2119 free(homedir); | |
2120 homedir = NULL; | |
2121 } | |
2122 | |
2123 var = getenv("HOME"); | |
2124 | |
2125 /* | |
2126 * Typically, $HOME is not defined on Windows, unless the user has | |
2127 * specifically defined it for Vim's sake. However, on Windows NT | |
2128 * platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for | |
2129 * each user. Try constructing $HOME from these. | |
2130 */ | |
2131 if (var == NULL || *var == NUL) | |
2132 { | |
2133 char *homedrive, *homepath; | |
2134 | |
2135 homedrive = getenv("HOMEDRIVE"); | |
2136 homepath = getenv("HOMEPATH"); | |
2137 if (homepath == NULL || *homepath == NUL) | |
2138 homepath = "\\"; | |
2139 if (homedrive != NULL | |
2140 && strlen(homedrive) + strlen(homepath) < MAX_PATH) | |
2141 { | |
2142 sprintf(buf, "%s%s", homedrive, homepath); | |
2143 if (buf[0] != NUL) | |
2144 var = buf; | |
2145 } | |
2146 } | |
2147 | |
2148 if (var == NULL) | |
2149 var = getenv("USERPROFILE"); | |
2150 | |
2151 /* | |
2152 * Weird but true: $HOME may contain an indirect reference to another | |
2153 * variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set | |
2154 * when $HOME is being set. | |
2155 */ | |
2156 if (var != NULL && *var == '%') | |
2157 { | |
2158 char *p; | |
2159 char *exp; | |
2160 | |
2161 p = strchr(var + 1, '%'); | |
2162 if (p != NULL) | |
2163 { | |
2164 strncpy(buf, var + 1, p - (var + 1)); | |
2165 buf[p - (var + 1)] = NUL; | |
2166 exp = getenv(buf); | |
2167 if (exp != NULL && *exp != NUL | |
2168 && strlen(exp) + strlen(p) < MAX_PATH) | |
2169 { | |
2170 _snprintf(buf, MAX_PATH, "%s%s", exp, p + 1); | |
2171 buf[MAX_PATH - 1] = NUL; | |
2172 var = buf; | |
2173 } | |
2174 } | |
2175 } | |
2176 | |
2177 if (var != NULL && *var == NUL) // empty is same as not set | |
2178 var = NULL; | |
2179 | |
2180 if (var == NULL) | |
2181 homedir = NULL; | |
2182 else | |
2183 homedir = _strdup(var); | |
2184 } | |
2185 | |
2186 /* | |
2100 * Change the directory that the vim plugin directories will be created in: | 2187 * Change the directory that the vim plugin directories will be created in: |
2101 * $HOME, $VIM or nowhere. | 2188 * $HOME, $VIM or nowhere. |
2102 */ | 2189 */ |
2103 static void | 2190 static void |
2104 change_directories_choice(int idx) | 2191 change_directories_choice(int idx) |
2105 { | 2192 { |
2106 int choice_count = TABLE_SIZE(vimfiles_dir_choices); | 2193 int choice_count = TABLE_SIZE(vimfiles_dir_choices); |
2107 | 2194 |
2108 /* Don't offer the $HOME choice if $HOME isn't set. */ | 2195 /* Don't offer the $HOME choice if $HOME isn't set. */ |
2109 if (getenv("HOME") == NULL) | 2196 if (homedir == NULL) |
2110 --choice_count; | 2197 --choice_count; |
2111 vimfiles_dir_choice = get_choice(vimfiles_dir_choices, choice_count); | 2198 choices[idx].arg = get_choice(vimfiles_dir_choices, choice_count); |
2112 set_directories_text(idx); | 2199 set_directories_text(idx); |
2113 } | 2200 } |
2114 | 2201 |
2115 /* | 2202 /* |
2116 * Create the plugin directories... | 2203 * Create the plugin directories... |
2118 /*ARGSUSED*/ | 2205 /*ARGSUSED*/ |
2119 static void | 2206 static void |
2120 install_vimfilesdir(int idx) | 2207 install_vimfilesdir(int idx) |
2121 { | 2208 { |
2122 int i; | 2209 int i; |
2210 int vimfiles_dir_choice = choices[idx].arg; | |
2123 char *p; | 2211 char *p; |
2124 char vimdir_path[BUFSIZE]; | 2212 char vimdir_path[BUFSIZE]; |
2125 char vimfiles_path[BUFSIZE]; | 2213 char vimfiles_path[BUFSIZE]; |
2126 char tmp_dirname[BUFSIZE]; | 2214 char tmp_dirname[BUFSIZE]; |
2127 | 2215 |
2142 strcpy(vimdir_path, p); | 2230 strcpy(vimdir_path, p); |
2143 break; | 2231 break; |
2144 } | 2232 } |
2145 case vimfiles_dir_home: | 2233 case vimfiles_dir_home: |
2146 { | 2234 { |
2147 /* Find the $HOME directory. Its existence was already checked. */ | 2235 // Find the $HOME directory. Its existence was already checked. |
2148 p = getenv("HOME"); | 2236 p = homedir; |
2149 if (p == NULL) | 2237 if (p == NULL) |
2150 { | 2238 { |
2151 printf("Internal error: $HOME is NULL\n"); | 2239 printf("Internal error: $HOME is NULL\n"); |
2152 p = "c:\\"; | 2240 p = "c:\\"; |
2153 } | 2241 } |
2154 strcpy(vimdir_path, p); | 2242 strcpy(vimdir_path, p); |
2155 break; | 2243 break; |
2156 } | 2244 } |
2157 case vimfiles_dir_none: | 2245 case vimfiles_dir_none: |
2158 { | 2246 { |
2159 /* Do not create vim plugin directory */ | 2247 // Do not create vim plugin directory. |
2160 return; | 2248 return; |
2161 } | 2249 } |
2162 } | 2250 } |
2163 | 2251 |
2164 /* Now, just create the directory. If it already exists, it will fail | 2252 /* Now, just create the directory. If it already exists, it will fail |
2183 init_directories_choice(void) | 2271 init_directories_choice(void) |
2184 { | 2272 { |
2185 struct stat st; | 2273 struct stat st; |
2186 char tmp_dirname[BUFSIZE]; | 2274 char tmp_dirname[BUFSIZE]; |
2187 char *p; | 2275 char *p; |
2276 int vimfiles_dir_choice; | |
2188 | 2277 |
2189 choices[choice_count].text = alloc(150); | 2278 choices[choice_count].text = alloc(150); |
2190 choices[choice_count].changefunc = change_directories_choice; | 2279 choices[choice_count].changefunc = change_directories_choice; |
2191 choices[choice_count].installfunc = install_vimfilesdir; | 2280 choices[choice_count].installfunc = install_vimfilesdir; |
2192 choices[choice_count].active = 1; | 2281 choices[choice_count].active = 1; |
2193 | 2282 |
2194 /* Check if the "compiler" directory already exists. That's a good | 2283 // Check if the "compiler" directory already exists. That's a good |
2195 * indication that the plugin directories were already created. */ | 2284 // indication that the plugin directories were already created. |
2196 if (getenv("HOME") != NULL) | 2285 if (getenv("HOME") != NULL) |
2197 { | 2286 { |
2198 vimfiles_dir_choice = (int)vimfiles_dir_home; | 2287 vimfiles_dir_choice = (int)vimfiles_dir_home; |
2199 sprintf(tmp_dirname, "%s\\vimfiles\\compiler", getenv("HOME")); | 2288 sprintf(tmp_dirname, "%s\\vimfiles\\compiler", getenv("HOME")); |
2200 if (stat(tmp_dirname, &st) == 0) | 2289 if (stat(tmp_dirname, &st) == 0) |
2202 } | 2291 } |
2203 else | 2292 else |
2204 { | 2293 { |
2205 vimfiles_dir_choice = (int)vimfiles_dir_vim; | 2294 vimfiles_dir_choice = (int)vimfiles_dir_vim; |
2206 p = getenv("VIM"); | 2295 p = getenv("VIM"); |
2207 if (p == NULL) /* No $VIM in path, use the install dir */ | 2296 if (p == NULL) // No $VIM in path, use the install dir. |
2208 dir_remove_last(installdir, tmp_dirname); | 2297 dir_remove_last(installdir, tmp_dirname); |
2209 else | 2298 else |
2210 strcpy(tmp_dirname, p); | 2299 strcpy(tmp_dirname, p); |
2211 strcat(tmp_dirname, "\\vimfiles\\compiler"); | 2300 strcat(tmp_dirname, "\\vimfiles\\compiler"); |
2212 if (stat(tmp_dirname, &st) == 0) | 2301 if (stat(tmp_dirname, &st) == 0) |
2213 vimfiles_dir_choice = (int)vimfiles_dir_none; | 2302 vimfiles_dir_choice = (int)vimfiles_dir_none; |
2214 } | 2303 } |
2215 | 2304 |
2305 choices[choice_count].arg = vimfiles_dir_choice; | |
2216 set_directories_text(choice_count); | 2306 set_directories_text(choice_count); |
2217 ++choice_count; | 2307 ++choice_count; |
2218 } | 2308 } |
2219 | 2309 |
2220 /* | 2310 /* |
2367 { | 2457 { |
2368 init_shortcut_choices(); | 2458 init_shortcut_choices(); |
2369 } | 2459 } |
2370 else if (strcmp(argv[i], "-create-directories") == 0) | 2460 else if (strcmp(argv[i], "-create-directories") == 0) |
2371 { | 2461 { |
2462 int vimfiles_dir_choice; | |
2463 | |
2372 init_directories_choice(); | 2464 init_directories_choice(); |
2373 if (argv[i + 1][0] != '-') | 2465 if (argv[i + 1][0] != '-') |
2374 { | 2466 { |
2375 i++; | 2467 i++; |
2376 if (strcmp(argv[i], "vim") == 0) | 2468 if (strcmp(argv[i], "vim") == 0) |
2377 vimfiles_dir_choice = (int)vimfiles_dir_vim; | 2469 vimfiles_dir_choice = (int)vimfiles_dir_vim; |
2378 else if (strcmp(argv[i], "home") == 0) | 2470 else if (strcmp(argv[i], "home") == 0) |
2379 { | 2471 { |
2380 if (getenv("HOME") == NULL) /* No $HOME in environment */ | 2472 if (homedir == NULL) // No $HOME in environment |
2381 vimfiles_dir_choice = (int)vimfiles_dir_vim; | 2473 vimfiles_dir_choice = (int)vimfiles_dir_none; |
2382 else | 2474 else |
2383 vimfiles_dir_choice = (int)vimfiles_dir_home; | 2475 vimfiles_dir_choice = (int)vimfiles_dir_home; |
2384 } | 2476 } |
2385 else | 2477 else |
2386 { | 2478 { |
2389 print_cmd_line_help(); | 2481 print_cmd_line_help(); |
2390 } | 2482 } |
2391 } | 2483 } |
2392 else /* No choice specified, default to vim directory */ | 2484 else /* No choice specified, default to vim directory */ |
2393 vimfiles_dir_choice = (int)vimfiles_dir_vim; | 2485 vimfiles_dir_choice = (int)vimfiles_dir_vim; |
2486 choices[choice_count - 1].arg = vimfiles_dir_choice; | |
2394 } | 2487 } |
2395 else if (strcmp(argv[i], "-register-OLE") == 0) | 2488 else if (strcmp(argv[i], "-register-OLE") == 0) |
2396 { | 2489 { |
2397 /* This is always done when gvim is found */ | 2490 /* This is always done when gvim is found */ |
2398 } | 2491 } |
2587 else | 2680 else |
2588 interactive = 1; | 2681 interactive = 1; |
2589 | 2682 |
2590 /* Initialize this program. */ | 2683 /* Initialize this program. */ |
2591 do_inits(argv); | 2684 do_inits(argv); |
2685 init_homedir(); | |
2592 | 2686 |
2593 if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0) | 2687 if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0) |
2594 { | 2688 { |
2595 /* Only check for already installed Vims. Used by NSIS installer. */ | 2689 /* Only check for already installed Vims. Used by NSIS installer. */ |
2596 i = uninstall_check(1); | 2690 i = uninstall_check(1); |