diff options
author | Dudemanguy <random342@airmail.cc> | 2022-11-07 18:35:43 -0600 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-05-09 20:37:17 +0000 |
commit | 5158b85b21b9316b610ab59ba65da36144e03b9a (patch) | |
tree | b5765fbb2910f7a54591923b974bc6a3575ce835 | |
parent | baa9d56481fe0f7633c77d0e7ee6ffd33b3a3783 (diff) | |
download | mpv-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.
-rw-r--r-- | options/path.c | 12 | ||||
-rw-r--r-- | options/path.h | 13 | ||||
-rw-r--r-- | player/configfiles.c | 6 |
3 files changed, 16 insertions, 15 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 */ diff --git a/player/configfiles.c b/player/configfiles.c index 41c22ed2b9..9de7e36ec7 100644 --- a/player/configfiles.c +++ b/player/configfiles.c @@ -63,7 +63,7 @@ void mp_parse_cfgfiles(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; - mp_mk_config_dir(mpctx->global, ""); + mp_mk_user_dir(mpctx->global, "home", ""); char *p1 = mp_get_user_path(NULL, mpctx->global, "~~home/"); char *p2 = mp_get_user_path(NULL, mpctx->global, "~~old_home/"); @@ -226,7 +226,7 @@ static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx, if (!mpctx->cached_watch_later_configdir) { mpctx->cached_watch_later_configdir = - mp_find_user_config_file(mpctx, mpctx->global, MP_WATCH_LATER_CONF); + mp_find_user_file(mpctx, mpctx->global, "home", MP_WATCH_LATER_CONF); } if (mpctx->cached_watch_later_configdir) @@ -292,7 +292,7 @@ void mp_write_watch_later_conf(struct MPContext *mpctx) if (!conffile) goto exit; - mp_mk_config_dir(mpctx->global, mpctx->cached_watch_later_configdir); + mp_mk_user_dir(mpctx->global, "home", mpctx->cached_watch_later_configdir); MP_INFO(mpctx, "Saving state.\n"); |