summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorKenneth Zhou <knthzh@gmail.com>2014-06-18 19:55:40 -0400
committerwm4 <wm4@nowhere>2014-06-26 19:37:25 +0200
commitcb250d490c14872f03bb0320179e48d05fe2539d (patch)
treedd27e22fcbb6e306175d041eb2b2c714b7079645 /osdep
parent8bb7d427e2180067f13f8dc5c5105029e9e00be7 (diff)
downloadmpv-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')
-rw-r--r--osdep/path-macosx.m5
-rw-r--r--osdep/path-win.c59
-rw-r--r--osdep/path.h15
3 files changed, 39 insertions, 40 deletions
diff --git a/osdep/path-macosx.m b/osdep/path-macosx.m
index c5240f570e..83fb113e8d 100644
--- a/osdep/path-macosx.m
+++ b/osdep/path-macosx.m
@@ -20,12 +20,11 @@
#include "options/path.h"
#include "osdep/path.h"
-char *mp_get_macosx_bundled_path(void *talloc_ctx, struct mpv_global *global,
- const char *file)
+char *mp_get_macosx_bundle_dir(void *talloc_ctx)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *path = [[NSBundle mainBundle] resourcePath];
- char *rv = mp_path_join(talloc_ctx, bstr0([path UTF8String]), bstr0(file));
+ char *rv = talloc_strdup(talloc_ctx, [path UTF8String]);
[pool release];
return rv;
}
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++;
}
diff --git a/osdep/path.h b/osdep/path.h
index 91afbce604..c2fe2ba303 100644
--- a/osdep/path.h
+++ b/osdep/path.h
@@ -1,12 +1,19 @@
#ifndef OSDEP_PATH_H
#define OSDEP_PATH_H
+#define MAX_CONFIG_PATHS 32
+
struct mpv_global;
-char *mp_get_win_config_path(const char *filename);
+// Windows config directories
+char *mp_get_win_exe_dir(void *talloc_ctx);
+char *mp_get_win_exe_subdir(void *talloc_ctx);
+char *mp_get_win_app_dir(void *talloc_ctx);
+
+void mp_add_win_config_dirs(void *talloc_ctx, struct mpv_global *global,
+ char **dirs, int i);
-// Returns absolute path of a resource file in a Mac OS X application bundle.
-char *mp_get_macosx_bundled_path(void *talloc_ctx, struct mpv_global *global,
- const char *filename);
+// Returns Mac OS X application bundle directory.
+char *mp_get_macosx_bundle_dir(void *talloc_ctx);
#endif