0
0
mirror of https://github.com/vim/vim.git synced 2025-10-14 07:04:10 -04:00

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)
This commit is contained in:
Bram Moolenaar
2018-11-16 19:39:50 +01:00
parent 447f6ce8bd
commit 25a494ce60
3 changed files with 111 additions and 13 deletions

View File

@@ -115,14 +115,13 @@ enum
vimfiles_dir_vim, vimfiles_dir_vim,
vimfiles_dir_home vimfiles_dir_home
}; };
static char *(vimfiles_dir_choices[]) = static char *(vimfiles_dir_choices[]) =
{ {
"\nCreate plugin directories:", "\nCreate plugin directories:",
"No", "No",
"In the VIM directory", "In the VIM directory",
"In your HOME directory", "In your HOME directory",
}; };
static int vimfiles_dir_choice;
/* non-zero when selected to install the popup menu entry. */ /* non-zero when selected to install the popup menu entry. */
static int install_popup = 0; static int install_popup = 0;
@@ -741,7 +740,8 @@ add_dummy_choice(void)
choices[choice_count].installfunc = NULL; choices[choice_count].installfunc = NULL;
choices[choice_count].active = 0; choices[choice_count].active = 0;
choices[choice_count].changefunc = NULL; choices[choice_count].changefunc = NULL;
choices[choice_count].installfunc = NULL; choices[choice_count].text = NULL;
choices[choice_count].arg = 0;
++choice_count; ++choice_count;
} }
@@ -2089,6 +2089,8 @@ dir_remove_last(const char *path, char to[BUFSIZE])
static void static void
set_directories_text(int idx) set_directories_text(int idx)
{ {
int vimfiles_dir_choice = choices[idx].arg;
if (vimfiles_dir_choice == (int)vimfiles_dir_none) if (vimfiles_dir_choice == (int)vimfiles_dir_none)
alloc_text(idx, "Do NOT create plugin directories%s", ""); alloc_text(idx, "Do NOT create plugin directories%s", "");
else else
@@ -2096,6 +2098,91 @@ set_directories_text(int idx)
vimfiles_dir_choices[vimfiles_dir_choice]); vimfiles_dir_choices[vimfiles_dir_choice]);
} }
/*
* To get the "real" home directory:
* - get value of $HOME
* - if not found, get value of $HOMEDRIVE$HOMEPATH
* - if not found, get value of $USERPROFILE
*
* This code is based on init_homedir() in misc1.c, keep in sync!
*/
static char *homedir = NULL;
void
init_homedir(void)
{
char *var;
char buf[MAX_PATH];
if (homedir != NULL)
{
free(homedir);
homedir = NULL;
}
var = getenv("HOME");
/*
* Typically, $HOME is not defined on Windows, unless the user has
* specifically defined it for Vim's sake. However, on Windows NT
* platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for
* each user. Try constructing $HOME from these.
*/
if (var == NULL || *var == NUL)
{
char *homedrive, *homepath;
homedrive = getenv("HOMEDRIVE");
homepath = getenv("HOMEPATH");
if (homepath == NULL || *homepath == NUL)
homepath = "\\";
if (homedrive != NULL
&& strlen(homedrive) + strlen(homepath) < MAX_PATH)
{
sprintf(buf, "%s%s", homedrive, homepath);
if (buf[0] != NUL)
var = buf;
}
}
if (var == NULL)
var = getenv("USERPROFILE");
/*
* Weird but true: $HOME may contain an indirect reference to another
* variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set
* when $HOME is being set.
*/
if (var != NULL && *var == '%')
{
char *p;
char *exp;
p = strchr(var + 1, '%');
if (p != NULL)
{
strncpy(buf, var + 1, p - (var + 1));
buf[p - (var + 1)] = NUL;
exp = getenv(buf);
if (exp != NULL && *exp != NUL
&& strlen(exp) + strlen(p) < MAX_PATH)
{
_snprintf(buf, MAX_PATH, "%s%s", exp, p + 1);
buf[MAX_PATH - 1] = NUL;
var = buf;
}
}
}
if (var != NULL && *var == NUL) // empty is same as not set
var = NULL;
if (var == NULL)
homedir = NULL;
else
homedir = _strdup(var);
}
/* /*
* Change the directory that the vim plugin directories will be created in: * Change the directory that the vim plugin directories will be created in:
* $HOME, $VIM or nowhere. * $HOME, $VIM or nowhere.
@@ -2106,9 +2193,9 @@ change_directories_choice(int idx)
int choice_count = TABLE_SIZE(vimfiles_dir_choices); int choice_count = TABLE_SIZE(vimfiles_dir_choices);
/* Don't offer the $HOME choice if $HOME isn't set. */ /* Don't offer the $HOME choice if $HOME isn't set. */
if (getenv("HOME") == NULL) if (homedir == NULL)
--choice_count; --choice_count;
vimfiles_dir_choice = get_choice(vimfiles_dir_choices, choice_count); choices[idx].arg = get_choice(vimfiles_dir_choices, choice_count);
set_directories_text(idx); set_directories_text(idx);
} }
@@ -2120,6 +2207,7 @@ change_directories_choice(int idx)
install_vimfilesdir(int idx) install_vimfilesdir(int idx)
{ {
int i; int i;
int vimfiles_dir_choice = choices[idx].arg;
char *p; char *p;
char vimdir_path[BUFSIZE]; char vimdir_path[BUFSIZE];
char vimfiles_path[BUFSIZE]; char vimfiles_path[BUFSIZE];
@@ -2144,8 +2232,8 @@ install_vimfilesdir(int idx)
} }
case vimfiles_dir_home: case vimfiles_dir_home:
{ {
/* Find the $HOME directory. Its existence was already checked. */ // Find the $HOME directory. Its existence was already checked.
p = getenv("HOME"); p = homedir;
if (p == NULL) if (p == NULL)
{ {
printf("Internal error: $HOME is NULL\n"); printf("Internal error: $HOME is NULL\n");
@@ -2156,7 +2244,7 @@ install_vimfilesdir(int idx)
} }
case vimfiles_dir_none: case vimfiles_dir_none:
{ {
/* Do not create vim plugin directory */ // Do not create vim plugin directory.
return; return;
} }
} }
@@ -2185,14 +2273,15 @@ init_directories_choice(void)
struct stat st; struct stat st;
char tmp_dirname[BUFSIZE]; char tmp_dirname[BUFSIZE];
char *p; char *p;
int vimfiles_dir_choice;
choices[choice_count].text = alloc(150); choices[choice_count].text = alloc(150);
choices[choice_count].changefunc = change_directories_choice; choices[choice_count].changefunc = change_directories_choice;
choices[choice_count].installfunc = install_vimfilesdir; choices[choice_count].installfunc = install_vimfilesdir;
choices[choice_count].active = 1; choices[choice_count].active = 1;
/* Check if the "compiler" directory already exists. That's a good // Check if the "compiler" directory already exists. That's a good
* indication that the plugin directories were already created. */ // indication that the plugin directories were already created.
if (getenv("HOME") != NULL) if (getenv("HOME") != NULL)
{ {
vimfiles_dir_choice = (int)vimfiles_dir_home; vimfiles_dir_choice = (int)vimfiles_dir_home;
@@ -2204,7 +2293,7 @@ init_directories_choice(void)
{ {
vimfiles_dir_choice = (int)vimfiles_dir_vim; vimfiles_dir_choice = (int)vimfiles_dir_vim;
p = getenv("VIM"); p = getenv("VIM");
if (p == NULL) /* No $VIM in path, use the install dir */ if (p == NULL) // No $VIM in path, use the install dir.
dir_remove_last(installdir, tmp_dirname); dir_remove_last(installdir, tmp_dirname);
else else
strcpy(tmp_dirname, p); strcpy(tmp_dirname, p);
@@ -2213,6 +2302,7 @@ init_directories_choice(void)
vimfiles_dir_choice = (int)vimfiles_dir_none; vimfiles_dir_choice = (int)vimfiles_dir_none;
} }
choices[choice_count].arg = vimfiles_dir_choice;
set_directories_text(choice_count); set_directories_text(choice_count);
++choice_count; ++choice_count;
} }
@@ -2369,6 +2459,8 @@ command_line_setup_choices(int argc, char **argv)
} }
else if (strcmp(argv[i], "-create-directories") == 0) else if (strcmp(argv[i], "-create-directories") == 0)
{ {
int vimfiles_dir_choice;
init_directories_choice(); init_directories_choice();
if (argv[i + 1][0] != '-') if (argv[i + 1][0] != '-')
{ {
@@ -2377,8 +2469,8 @@ command_line_setup_choices(int argc, char **argv)
vimfiles_dir_choice = (int)vimfiles_dir_vim; vimfiles_dir_choice = (int)vimfiles_dir_vim;
else if (strcmp(argv[i], "home") == 0) else if (strcmp(argv[i], "home") == 0)
{ {
if (getenv("HOME") == NULL) /* No $HOME in environment */ if (homedir == NULL) // No $HOME in environment
vimfiles_dir_choice = (int)vimfiles_dir_vim; vimfiles_dir_choice = (int)vimfiles_dir_none;
else else
vimfiles_dir_choice = (int)vimfiles_dir_home; vimfiles_dir_choice = (int)vimfiles_dir_home;
} }
@@ -2391,6 +2483,7 @@ command_line_setup_choices(int argc, char **argv)
} }
else /* No choice specified, default to vim directory */ else /* No choice specified, default to vim directory */
vimfiles_dir_choice = (int)vimfiles_dir_vim; vimfiles_dir_choice = (int)vimfiles_dir_vim;
choices[choice_count - 1].arg = vimfiles_dir_choice;
} }
else if (strcmp(argv[i], "-register-OLE") == 0) else if (strcmp(argv[i], "-register-OLE") == 0)
{ {
@@ -2589,6 +2682,7 @@ main(int argc, char **argv)
/* Initialize this program. */ /* Initialize this program. */
do_inits(argv); do_inits(argv);
init_homedir();
if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0) if (argc > 1 && strcmp(argv[1], "-uninstall-check") == 0)
{ {

View File

@@ -3905,6 +3905,8 @@ vim_beep(
* - do mch_dirname() to get the real name of that directory. * - do mch_dirname() to get the real name of that directory.
* This also works with mounts and links. * This also works with mounts and links.
* Don't do this for MS-DOS, it will change the "current dir" for a drive. * Don't do this for MS-DOS, it will change the "current dir" for a drive.
* For Windows:
* This code is duplicated in init_homedir() in dosinst.c. Keep in sync!
*/ */
static char_u *homedir = NULL; static char_u *homedir = NULL;

View File

@@ -792,6 +792,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
534,
/**/ /**/
533, 533,
/**/ /**/