summaryrefslogtreecommitdiffstats
path: root/mpvcore/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'mpvcore/path.c')
-rw-r--r--mpvcore/path.c26
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