summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--options/path.c23
-rw-r--r--options/path.h6
-rw-r--r--player/configfiles.c26
-rw-r--r--player/core.h2
-rw-r--r--player/loadfile.c3
5 files changed, 37 insertions, 23 deletions
diff --git a/options/path.c b/options/path.c
index ea36363a90..2895b7224b 100644
--- a/options/path.c
+++ b/options/path.c
@@ -91,6 +91,18 @@ 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)
+{
+ void *tmp = talloc_new(NULL);
+ char *res = (char *)mp_get_platform_path(tmp, global, config_dirs[0]);
+ if (res)
+ res = mp_path_join(talloc_ctx, res, filename);
+ talloc_free(tmp);
+ MP_VERBOSE(global, "config file: '%s' -> '%s'\n", filename, res ? res : "-");
+ return res;
+}
+
static char **mp_find_all_config_files_limited(void *talloc_ctx,
struct mpv_global *global,
int max_files,
@@ -316,13 +328,8 @@ void mp_mkdirp(const char *dir)
void mp_mk_config_dir(struct mpv_global *global, char *subdir)
{
- void *tmp = talloc_new(NULL);
- const char *dir = mp_get_platform_path(tmp, global, "home");
-
- if (dir) {
- dir = talloc_asprintf(tmp, "%s/%s", dir, subdir);
+ char *dir = mp_find_user_config_file(NULL, global, subdir);
+ if (dir)
mp_mkdirp(dir);
- }
-
- talloc_free(tmp);
+ talloc_free(dir);
}
diff --git a/options/path.h b/options/path.h
index 1facea81cf..763a8dda54 100644
--- a/options/path.h
+++ b/options/path.h
@@ -31,6 +31,12 @@ struct mpv_global;
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);
+
// Find all instances of the given config file. Paths are returned in order
// from lowest to highest priority. filename can contain multiple names
// separated with '|', with the first having highest priority.
diff --git a/player/configfiles.c b/player/configfiles.c
index 6806938a1a..0cd1d0d523 100644
--- a/player/configfiles.c
+++ b/player/configfiles.c
@@ -166,10 +166,10 @@ void mp_load_auto_profiles(struct MPContext *mpctx)
#define MP_WATCH_LATER_CONF "watch_later"
-static char *mp_get_playback_resume_config_filename(struct mpv_global *global,
+static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx,
const char *fname)
{
- struct MPOpts *opts = global->opts;
+ struct MPOpts *opts = mpctx->opts;
char *res = NULL;
void *tmp = talloc_new(NULL);
const char *realpath = fname;
@@ -195,15 +195,14 @@ static char *mp_get_playback_resume_config_filename(struct mpv_global *global,
for (int i = 0; i < 16; i++)
conf = talloc_asprintf_append(conf, "%02X", md5[i]);
- res = talloc_asprintf(tmp, MP_WATCH_LATER_CONF "/%s", conf);
- res = mp_find_config_file(NULL, global, res);
-
- if (!res) {
- res = mp_find_config_file(tmp, global, MP_WATCH_LATER_CONF);
- if (res)
- res = talloc_asprintf(NULL, "%s/%s", res, conf);
+ if (!mpctx->cached_watch_later_configdir) {
+ mpctx->cached_watch_later_configdir =
+ mp_find_user_config_file(mpctx, mpctx->global, MP_WATCH_LATER_CONF);
}
+ if (mpctx->cached_watch_later_configdir)
+ res = mp_path_join(NULL, mpctx->cached_watch_later_configdir, conf);
+
exit:
talloc_free(tmp);
return res;
@@ -298,7 +297,7 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
mp_mk_config_dir(mpctx->global, MP_WATCH_LATER_CONF);
- conffile = mp_get_playback_resume_config_filename(mpctx->global, filename);
+ conffile = mp_get_playback_resume_config_filename(mpctx, filename);
if (!conffile)
goto exit;
@@ -342,7 +341,9 @@ exit:
void mp_load_playback_resume(struct MPContext *mpctx, const char *file)
{
- char *fname = mp_get_playback_resume_config_filename(mpctx->global, file);
+ if (!mpctx->opts->position_resume)
+ return;
+ char *fname = mp_get_playback_resume_config_filename(mpctx, file);
if (fname && mp_path_exists(fname)) {
// Never apply the saved start position to following files
m_config_backup_opt(mpctx->mconfig, "start");
@@ -365,8 +366,7 @@ struct playlist_entry *mp_check_playlist_resume(struct MPContext *mpctx,
if (!mpctx->opts->position_resume)
return NULL;
for (struct playlist_entry *e = playlist->first; e; e = e->next) {
- char *conf = mp_get_playback_resume_config_filename(mpctx->global,
- e->filename);
+ char *conf = mp_get_playback_resume_config_filename(mpctx, e->filename);
bool exists = conf && mp_path_exists(conf);
talloc_free(conf);
if (exists)
diff --git a/player/core.h b/player/core.h
index ea7694d02a..055a48bda4 100644
--- a/player/core.h
+++ b/player/core.h
@@ -335,6 +335,8 @@ typedef struct MPContext {
// playback rate. Used to avoid showing it multiple times.
bool drop_message_shown;
+ char *cached_watch_later_configdir;
+
struct screenshot_ctx *screenshot_ctx;
struct command_ctx *command_ctx;
struct encode_lavc_context *encode_lavc_ctx;
diff --git a/player/loadfile.c b/player/loadfile.c
index 40ed71d5fd..3dc0e0318a 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -1063,8 +1063,7 @@ static void play_current_file(struct MPContext *mpctx)
mp_load_auto_profiles(mpctx);
- if (opts->position_resume)
- mp_load_playback_resume(mpctx, mpctx->filename);
+ mp_load_playback_resume(mpctx, mpctx->filename);
load_per_file_options(mpctx->mconfig, mpctx->playing->params,
mpctx->playing->num_params);