summaryrefslogtreecommitdiffstats
path: root/options
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2022-11-07 18:35:43 -0600
committerDudemanguy <random342@airmail.cc>2023-05-09 20:37:17 +0000
commit5158b85b21b9316b610ab59ba65da36144e03b9a (patch)
treeb5765fbb2910f7a54591923b974bc6a3575ce835 /options
parentbaa9d56481fe0f7633c77d0e7ee6ffd33b3a3783 (diff)
downloadmpv-5158b85b21b9316b610ab59ba65da36144e03b9a.tar.bz2
mpv-5158b85b21b9316b610ab59ba65da36144e03b9a.tar.xz
path: expand internal path selection API to allow for additional types
Currently, nothing new is actually implemented but the idea is simply to just pass a type string all the way up from mp_find_user_file down to actually getting the platform path. This allows for selecting different directories besides the user's native config directory. See the next commit for an implementation.
Diffstat (limited to 'options')
-rw-r--r--options/path.c12
-rw-r--r--options/path.h13
2 files changed, 13 insertions, 12 deletions
diff --git a/options/path.c b/options/path.c
index 4dfe36bd2d..bd8adf6d81 100644
--- a/options/path.c
+++ b/options/path.c
@@ -102,15 +102,15 @@ static const char *mp_get_platform_path(void *talloc_ctx,
return NULL;
}
-char *mp_find_user_config_file(void *talloc_ctx, struct mpv_global *global,
- const char *filename)
+char *mp_find_user_file(void *talloc_ctx, struct mpv_global *global,
+ const char *type, const char *filename)
{
void *tmp = talloc_new(NULL);
- char *res = (char *)mp_get_platform_path(tmp, global, config_dirs[0]);
+ char *res = (char *)mp_get_platform_path(tmp, global, type);
if (res)
res = mp_path_join(talloc_ctx, res, filename);
talloc_free(tmp);
- MP_DBG(global, "config path: '%s' -> '%s'\n", filename, res ? res : "-");
+ MP_DBG(global, "path: '%s' -> '%s'\n", filename, res ? res : "-");
return res;
}
@@ -378,9 +378,9 @@ void mp_mkdirp(const char *dir)
talloc_free(path);
}
-void mp_mk_config_dir(struct mpv_global *global, char *subdir)
+void mp_mk_user_dir(struct mpv_global *global, const char *type, char *subdir)
{
- char *dir = mp_find_user_config_file(NULL, global, subdir);
+ char *dir = mp_find_user_file(NULL, global, type, subdir);
if (dir)
mp_mkdirp(dir);
talloc_free(dir);
diff --git a/options/path.h b/options/path.h
index 19f4fb5909..66ddcdc798 100644
--- a/options/path.h
+++ b/options/path.h
@@ -34,11 +34,12 @@ void mp_init_paths(struct mpv_global *global, struct MPOpts *opts);
char *mp_find_config_file(void *talloc_ctx, struct mpv_global *global,
const char *filename);
-// Like mp_find_config_file(), but search only the local writable user config
-// dir. Also, this returns a result even if the file does not exist. Calling
-// it with filename="" is equivalent to retrieving the user config dir.
-char *mp_find_user_config_file(void *talloc_ctx, struct mpv_global *global,
- const char *filename);
+// Search for local writable user files within a specific kind of user dir
+// as documented in osdep/path.h. This returns a result even if the file does
+// not exist. Calling it with filename="" is equivalent to retrieving the path
+// to the dir.
+char *mp_find_user_file(void *talloc_ctx, struct mpv_global *global,
+ const char *type, const char *filename);
// Find all instances of the given config file. Paths are returned in order
// from lowest to highest priority. filename can contain multiple names
@@ -90,6 +91,6 @@ bool mp_is_url(bstr path);
bstr mp_split_proto(bstr path, bstr *out_url);
void mp_mkdirp(const char *dir);
-void mp_mk_config_dir(struct mpv_global *global, char *subdir);
+void mp_mk_user_dir(struct mpv_global *global, const char *type, char *subdir);
#endif /* MPLAYER_PATH_H */