summaryrefslogtreecommitdiffstats
path: root/player/configfiles.c
diff options
context:
space:
mode:
Diffstat (limited to 'player/configfiles.c')
-rw-r--r--player/configfiles.c52
1 files changed, 24 insertions, 28 deletions
diff --git a/player/configfiles.c b/player/configfiles.c
index 2b94308baa..3ecb5a19c8 100644
--- a/player/configfiles.c
+++ b/player/configfiles.c
@@ -21,8 +21,12 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h>
+
+#ifdef _WIN32
+#include <sys/utime.h>
+#else
#include <utime.h>
+#endif
#include <libavutil/md5.h>
@@ -209,20 +213,16 @@ static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx,
struct MPOpts *opts = mpctx->opts;
char *res = NULL;
void *tmp = talloc_new(NULL);
- const char *realpath = fname;
- bstr bfname = bstr0(fname);
- if (!mp_is_url(bfname)) {
- if (opts->ignore_path_in_watch_later_config) {
- realpath = mp_basename(fname);
- } else {
- char *cwd = mp_getcwd(tmp);
- if (!cwd)
- goto exit;
- realpath = mp_path_join(tmp, cwd, fname);
- }
+ const char *path = NULL;
+ if (opts->ignore_path_in_watch_later_config && !mp_is_url(bstr0(path))) {
+ path = mp_basename(fname);
+ } else {
+ path = mp_normalize_path(tmp, fname);
+ if (!path)
+ goto exit;
}
uint8_t md5[16];
- av_md5_sum(md5, realpath, strlen(realpath));
+ av_md5_sum(md5, path, strlen(path));
char *conf = talloc_strdup(tmp, "");
for (int i = 0; i < 16; i++)
conf = talloc_asprintf_append(conf, "%02X", md5[i]);
@@ -312,6 +312,8 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
goto exit;
char *path = mp_normalize_path(ctx, cur->filename);
+ if (!path)
+ goto exit;
struct demuxer *demux = mpctx->demuxer;
@@ -333,7 +335,7 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
write_filename(mpctx, file, path);
bool write_start = true;
- double pos = get_current_time(mpctx);
+ double pos = get_playback_time(mpctx);
if ((demux && (!demux->seekable || demux->partially_seekable)) ||
pos == MP_NOPTS_VALUE)
@@ -391,26 +393,19 @@ exit:
void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file)
{
- if (!file) {
- struct playlist_entry *cur = mpctx->playing;
- if (!cur)
- return;
- file = cur->filename;
- if (!file)
- return;
- }
+ void *ctx = talloc_new(NULL);
+ char *path = mp_normalize_path(ctx, file ? file : mpctx->filename);
+ if (!path)
+ goto exit;
- char *fname = mp_get_playback_resume_config_filename(mpctx, file);
+ char *fname = mp_get_playback_resume_config_filename(mpctx, path);
if (fname) {
unlink(fname);
talloc_free(fname);
}
- if (mp_is_url(bstr0(file)) || mpctx->opts->ignore_path_in_watch_later_config)
- return;
-
- void *ctx = talloc_new(NULL);
- char *path = mp_normalize_path(ctx, file);
+ if (mp_is_url(bstr0(path)) || mpctx->opts->ignore_path_in_watch_later_config)
+ goto exit;
bstr dir = mp_dirname(path);
while (dir.len > 1 && dir.len < strlen(path)) {
@@ -424,6 +419,7 @@ void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file)
dir = mp_dirname(path);
}
+exit:
talloc_free(ctx);
}