summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Herkt <lachs0r@srsfckn.biz>2013-09-12 17:44:20 +0200
committerwm4 <wm4@nowhere>2013-09-13 22:00:29 +0200
commiteb02fdde90c6a5d4eccb48b5a66a6ad9f40cd408 (patch)
tree7b487a7112135e8fa36bb89f7e9ec789f680ec7d
parente2bb20c43e5efa6a4dde73088e539c9407f69317 (diff)
downloadmpv-eb02fdde90c6a5d4eccb48b5a66a6ad9f40cd408.tar.bz2
mpv-eb02fdde90c6a5d4eccb48b5a66a6ad9f40cd408.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.
-rw-r--r--mpvcore/path.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/mpvcore/path.c b/mpvcore/path.c
index 5d9b7841a4..6d7927e621 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