core: support mpv directory itself as a valid location for config files on Windows

This prefers ./ on Windows if-and-only-if the file being searched for
already exists there. (If the mpv directory is non-writable, the result
is still intended behavior.) This change is transparent to most users
because the user has to move the config files there intentionally, and
if anything, not being detected would be the surprising behavior.
This commit is contained in:
elevengu 2013-05-22 12:31:38 -03:00 committed by wm4
parent 3cae1b9fc9
commit b2c2fe7a37
1 changed files with 22 additions and 9 deletions

View File

@ -83,12 +83,8 @@ char *mp_find_user_config_file(const char *filename)
static char *config_dir = ".mpv"; static char *config_dir = ".mpv";
#endif #endif
#if defined(__MINGW32__) || defined(__CYGWIN__) #if defined(__MINGW32__) || defined(__CYGWIN__)
char *temp = NULL;
char exedir[260]; char exedir[260];
#endif
if ((homedir = getenv("MPV_HOME")) != NULL) {
config_dir = "";
} else if ((homedir = getenv("HOME")) == NULL) {
#if defined(__MINGW32__) || defined(__CYGWIN__)
/* Hack to get fonts etc. loaded outside of Cygwin environment. */ /* Hack to get fonts etc. loaded outside of Cygwin environment. */
int i, imax = 0; int i, imax = 0;
int len = (int)GetModuleFileNameA(NULL, exedir, 260); int len = (int)GetModuleFileNameA(NULL, exedir, 260);
@ -98,11 +94,28 @@ char *mp_find_user_config_file(const char *filename)
imax = i; imax = i;
} }
exedir[imax] = '\0'; exedir[imax] = '\0';
if (filename)
temp = mp_path_join(NULL, bstr0(exedir), bstr0(filename));
if (temp && mp_path_exists(temp) && !mp_path_isdir(temp)) {
homedir = exedir;
config_dir = "";
}
else
#endif
if ((homedir = getenv("MPV_HOME")) != NULL) {
config_dir = "";
} else if ((homedir = getenv("HOME")) == NULL) {
#if defined(__MINGW32__) || defined(__CYGWIN__)
homedir = exedir; homedir = exedir;
#else #else
return NULL; return NULL;
#endif #endif
} }
#if defined(__MINGW32__) || defined(__CYGWIN__)
talloc_free(temp);
#endif
if (filename) { if (filename) {
char * temp = mp_path_join(NULL, bstr0(homedir), bstr0(config_dir)); char * temp = mp_path_join(NULL, bstr0(homedir), bstr0(config_dir));