diff options
author | Martin Herkt <lachs0r@srsfckn.biz> | 2013-09-12 17:44:20 +0200 |
---|---|---|
committer | Martin Herkt <lachs0r@srsfckn.biz> | 2013-09-12 18:02:57 +0200 |
commit | 63c61500b80643f339339e9515b5491909a9b5a1 (patch) | |
tree | fa8b3cbaeb1c2a68d76388be3a43e3ba13ce127a /mpvcore | |
parent | 195b8bfe931b2ddb4a10c0da0edbe3903e6a965b (diff) | |
download | mpv-63c61500b80643f339339e9515b5491909a9b5a1.tar.bz2 mpv-63c61500b80643f339339e9515b5491909a9b5a1.tar.xz |
mpvcore/path: Fix config path handling on Windows
Previously, mpv incorrectly used the %HOME% environment variable on
MinGW to determine the current user’s home directory. This is wrong;
the correct variable to use would be %HOMEPATH%, which would however
still be wrong since application data goes into the application data
directory, not the user’s home. This patch makes it use the local
AppData path instead of reading an environment variable.
This however exposed another problem (which also affected users who
actually had the %HOME% variable set):
b2c2fe7a3782 (discussed in issue #95) introduced some changes that
make mpv load user config files from the executable path on Windows.
The problem with this change is that config_dir was still declared
static, so once a config file had been found in the executable path,
it would set config_dir to an empty string, so mpv would dump e.g.
watch_later data straight into the user’s home. This commit also
fixes that.
One side effect of this is that mpv no longer considers the “mpv”
subdirectory in the executable path (that behavior resulted from
the homedir variable always being empty), unless it is somehow
unable to determine the local AppData path.
Diffstat (limited to 'mpvcore')
-rw-r--r-- | mpvcore/path.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/mpvcore/path.c b/mpvcore/path.c index 9de6291975..9d88eaa92d 100644 --- a/mpvcore/path.c +++ b/mpvcore/path.c @@ -40,6 +40,7 @@ #if defined(__MINGW32__) #include <windows.h> +#include <shlobj.h> #elif defined(__CYGWIN__) #include <windows.h> #include <sys/cygwin.h> @@ -78,9 +79,20 @@ char *mp_find_user_config_file(const char *filename) { char *homedir = NULL, *buff = NULL; #ifdef __MINGW32__ - static char *config_dir = "mpv"; + char *config_dir = "mpv"; + static char *homepath = NULL; + + if (homepath == NULL) { + char buf[MAX_PATH]; + if (SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, + SHGFP_TYPE_CURRENT, buf) == S_OK) { + + homepath = buf; + } + } #else - static char *config_dir = ".mpv"; + char *config_dir = ".mpv"; + static char *homepath = getenv("HOME"); #endif #if defined(__MINGW32__) || defined(__CYGWIN__) char *temp = NULL; @@ -88,15 +100,19 @@ char *mp_find_user_config_file(const char *filename) /* Hack to get fonts etc. loaded outside of Cygwin environment. */ int i, imax = 0; int len = (int)GetModuleFileNameA(NULL, exedir, 260); - for (i = 0; i < len; i++) + + for (i = 0; i < len; i++) { if (exedir[i] == '\\') { exedir[i] = '/'; imax = i; } + } + exedir[imax] = '\0'; - if (filename) + if (filename) { temp = mp_path_join(NULL, bstr0(exedir), bstr0(filename)); + } if (temp && mp_path_exists(temp) && !mp_path_isdir(temp)) { homedir = exedir; @@ -106,7 +122,7 @@ char *mp_find_user_config_file(const char *filename) #endif if ((homedir = getenv("MPV_HOME")) != NULL) { config_dir = ""; - } else if ((homedir = getenv("HOME")) == NULL) { + } else if ((homedir = homepath) == NULL) { #if defined(__MINGW32__) || defined(__CYGWIN__) homedir = exedir; #else |