diff options
author | wm4 <wm4@nowhere> | 2014-02-25 22:34:32 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-02-25 22:34:32 +0100 |
commit | 67f244c6d4b0ef9ad2e55483508efbf6fe40d03b (patch) | |
tree | 320e7bc2b718af0192412dce83ee8ad864b99116 /player/configfiles.c | |
parent | 70ff543029068188a3de39a80a764267c6671e7c (diff) | |
download | mpv-67f244c6d4b0ef9ad2e55483508efbf6fe40d03b.tar.bz2 mpv-67f244c6d4b0ef9ad2e55483508efbf6fe40d03b.tar.xz |
config: don't save options to resume-config that didn't change
This is approximate: we read each option value on program start
(before starting playback of a file), and when writing the resume
config, compare each value to the current state. This also means
when a value is changed and then changed back, it's not stored. In
particular, option values set in config files and on the command
line are considered the default.
This should help reducing the numbers of options overridden by the
resume config. If too much is overridden, it becomes an inconvenience,
because changes in config files will apparently have no effect when
resuming a file.
Also see github issue #574.
Diffstat (limited to 'player/configfiles.c')
-rw-r--r-- | player/configfiles.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/player/configfiles.c b/player/configfiles.c index cc5659fa18..3516544dd4 100644 --- a/player/configfiles.c +++ b/player/configfiles.c @@ -232,6 +232,25 @@ static const char *backup_properties[] = { 0 }; +// Used to retrieve default settings, which should not be stored in the +// resume config. Uses backup_properties[] meaning/order of values. +// This explicitly includes values set by config files and command line. +void mp_get_resume_defaults(struct MPContext *mpctx) +{ + char **list = + talloc_zero_array(mpctx, char*, MP_ARRAY_SIZE(backup_properties)); + for (int i = 0; backup_properties[i]; i++) { + const char *pname = backup_properties[i]; + char name[80]; + snprintf(name, sizeof(name), "options/%s", pname); + char *val = NULL; + int r = mp_property_do(name, M_PROPERTY_GET_STRING, &val, mpctx); + if (r == M_PROPERTY_OK) + list[i] = talloc_steal(list, val); + } + mpctx->resume_defaults = list; +} + // Should follow what parser-cfg.c does/needs static bool needs_config_quoting(const char *s) { @@ -273,11 +292,15 @@ void mp_write_watch_later_conf(struct MPContext *mpctx) char *val = NULL; int r = mp_property_do(pname, M_PROPERTY_GET_STRING, &val, mpctx); if (r == M_PROPERTY_OK) { - if (needs_config_quoting(val)) { - // e.g. '%6%STRING' - fprintf(file, "%s=%%%d%%%s\n", pname, (int)strlen(val), val); - } else { - fprintf(file, "%s=%s\n", pname, val); + // Only store it if it's different from the initial value. + char *prev = mpctx->resume_defaults[i]; + if (!prev || strcmp(prev, val) != 0) { + if (needs_config_quoting(val)) { + // e.g. '%6%STRING' + fprintf(file, "%s=%%%d%%%s\n", pname, (int)strlen(val), val); + } else { + fprintf(file, "%s=%s\n", pname, val); + } } } talloc_free(val); |