diff options
Diffstat (limited to 'mpvcore/path.c')
-rw-r--r-- | mpvcore/path.c | 85 |
1 files changed, 15 insertions, 70 deletions
diff --git a/mpvcore/path.c b/mpvcore/path.c index f0c8525b21..73eee15567 100644 --- a/mpvcore/path.c +++ b/mpvcore/path.c @@ -37,14 +37,7 @@ #include "mpvcore/path.h" #include "talloc.h" #include "osdep/io.h" - -#if defined(__MINGW32__) -#include <windows.h> -#include <shlobj.h> -#elif defined(__CYGWIN__) -#include <windows.h> -#include <sys/cygwin.h> -#endif +#include "osdep/path.h" #ifdef CONFIG_COCOA #include "osdep/macosx_bundle.h" @@ -77,75 +70,27 @@ char *mp_find_config_file(const char *filename) char *mp_find_user_config_file(const char *filename) { - char *homedir = NULL, *buff = NULL; - char *homepath = NULL; -#ifdef __MINGW32__ - char *config_dir = "mpv"; - char buf[MAX_PATH]; - - if (homepath == NULL) { - if (SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, - SHGFP_TYPE_CURRENT, buf) == S_OK) { - - homepath = buf; - } - } -#else - char *config_dir = ".mpv"; + char *homedir = getenv("MPV_HOME"); + char *configdir = NULL; + char *result = NULL; - if (homepath == NULL) { - homepath = getenv("HOME"); - } + if (!homedir) { +#ifdef _WIN32 + result = mp_get_win_config_path(filename); #endif -#if defined(__MINGW32__) || defined(__CYGWIN__) - char *temp = NULL; - char exedir[260]; - /* 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++) { - if (exedir[i] == '\\') { - exedir[i] = '/'; - imax = i; - } + homedir = getenv("HOME"); + configdir = ".mpv"; } - 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 = homepath) == NULL) { -#if defined(__MINGW32__) || defined(__CYGWIN__) - homedir = exedir; -#else - return NULL; -#endif - } -#if defined(__MINGW32__) || defined(__CYGWIN__) - talloc_free(temp); -#endif - - if (filename) { - char * temp = mp_path_join(NULL, bstr0(homedir), bstr0(config_dir)); - buff = mp_path_join(NULL, bstr0(temp), bstr0(filename)); + if (!result && homedir) { + char *temp = mp_path_join(NULL, bstr0(homedir), bstr0(configdir)); + result = mp_path_join(NULL, bstr0(temp), bstr0(filename)); talloc_free(temp); - } else { - buff = mp_path_join(NULL, bstr0(homedir), bstr0(config_dir)); } - mp_msg(MSGT_GLOBAL, MSGL_V, "get_path('%s') -> '%s'\n", filename, buff); - return buff; + mp_msg(MSGT_GLOBAL, MSGL_V, "mp_find_user_config_file('%s') -> '%s'\n", + filename ? filename : "(NULL)", result ? result : "(NULL)"); + return result; } char *mp_find_global_config_file(const char *filename) |