diff options
author | Kenneth Zhou <knthzh@gmail.com> | 2014-06-18 19:55:40 -0400 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-06-26 19:37:25 +0200 |
commit | cb250d490c14872f03bb0320179e48d05fe2539d (patch) | |
tree | dd27e22fcbb6e306175d041eb2b2c714b7079645 /osdep/path-win.c | |
parent | 8bb7d427e2180067f13f8dc5c5105029e9e00be7 (diff) | |
download | mpv-cb250d490c14872f03bb0320179e48d05fe2539d.tar.bz2 mpv-cb250d490c14872f03bb0320179e48d05fe2539d.tar.xz |
Basic xdg directory implementation
Search $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS for config files.
This also negates the need to have separate user and global variants of
mp_find_config_file()
Closes #864, #109.
Signed-off-by: wm4 <wm4@nowhere>
Diffstat (limited to 'osdep/path-win.c')
-rw-r--r-- | osdep/path-win.c | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/osdep/path-win.c b/osdep/path-win.c index 2b1e8b5144..e35bab37a2 100644 --- a/osdep/path-win.c +++ b/osdep/path-win.c @@ -24,55 +24,48 @@ // Warning: do not use PATH_MAX. Cygwin messed it up. -static void get_exe_dir(wchar_t path[MAX_PATH + 1]) +char *mp_get_win_exe_dir(void *talloc_ctx) { - int len = (int)GetModuleFileNameW(NULL, path, MAX_PATH); + wchar_t w_exedir[MAX_PATH + 1] = {0}; + + int len = (int)GetModuleFileNameW(NULL, w_exedir, MAX_PATH); int imax = 0; for (int i = 0; i < len; i++) { - if (path[i] == '\\') { - path[i] = '/'; + if (w_exedir[i] == '\\') { + w_exedir[i] = '/'; imax = i; } } - path[imax] = '\0'; + w_exedir[imax] = '\0'; + + return mp_to_utf8(talloc_ctx, w_exedir); +} +char *mp_get_win_exe_subdir(void *talloc_ctx) +{ + return talloc_asprintf(talloc_ctx, "%s/mpv", mp_get_win_exe_dir(talloc_ctx)); } -char *mp_get_win_config_path(const char *filename) +char *mp_get_win_app_dir(void *talloc_ctx) { wchar_t w_appdir[MAX_PATH + 1] = {0}; - wchar_t w_exedir[MAX_PATH + 1] = {0}; - char *res = NULL; - void *tmp = talloc_new(NULL); -#ifndef __CYGWIN__ if (SHGetFolderPathW(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, w_appdir) != S_OK) - w_appdir[0] = '\0'; -#endif + return NULL; - get_exe_dir(w_exedir); + return talloc_asprintf(talloc_ctx, "%s/mpv", mp_to_utf8(talloc_ctx, w_appdir)); +} - if (filename && filename[0] && w_exedir[0]) { - char *dir = mp_to_utf8(tmp, w_exedir); - char *temp = mp_path_join(tmp, bstr0(dir), bstr0("mpv")); - res = mp_path_join(NULL, bstr0(temp), bstr0(filename)); - if (!mp_path_exists(res) || mp_path_isdir(res)) { - talloc_free(res); - res = mp_path_join(NULL, bstr0(dir), bstr0(filename)); - if (!mp_path_exists(res) || mp_path_isdir(res)) { - talloc_free(res); - res = NULL; - } - } - } - if (!res && w_appdir[0]) { - char *dir = mp_to_utf8(tmp, w_appdir); - char *temp = mp_path_join(tmp, bstr0(dir), bstr0("mpv")); - res = mp_path_join(NULL, bstr0(temp), bstr0(filename)); - } - talloc_free(tmp); - return res; +void mp_add_win_config_dirs(void *talloc_ctx, struct mpv_global *global, + char **dirs, int i) +{ + if ((dirs[i] = mp_get_win_exe_subdir(talloc_ctx))) + i++; + if ((dirs[i] = mp_get_win_exe_dir(talloc_ctx))) + i++; + if ((dirs[i] = mp_get_win_app_dir(talloc_ctx))) + i++; } |