0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

player: remove some minor code duplication in config loader code

It's better to keep the logic in one place.

Also drop that a broken config file aborts loading of the player. I
don't see much reason for this, and it inflates the code slightly.
This commit is contained in:
wm4 2014-06-26 17:56:47 +02:00
parent cb250d490c
commit c63378d41c
3 changed files with 16 additions and 21 deletions

View File

@ -46,17 +46,26 @@
#include "core.h"
#include "command.h"
static void load_all_cfgfiles(struct MPContext *mpctx, char *section,
char *filename)
{
void *tmp = talloc_new(NULL);
char **cf = mp_find_all_config_files(tmp, mpctx->global, filename);
for (int i = 0; cf && cf[i]; i++)
m_config_parse_config_file(mpctx->mconfig, cf[i], section, 0);
talloc_free(tmp);
}
#define SECT_ENCODE "encoding"
bool mp_parse_cfgfiles(struct MPContext *mpctx)
void mp_parse_cfgfiles(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
if (!opts->load_config)
return true;
return;
m_config_t *conf = mpctx->mconfig;
void *tmp = talloc_new(NULL);
bool r = true;
char *conffile;
char *section = NULL;
bool encoding = opts->encode_opts &&
@ -75,26 +84,13 @@ bool mp_parse_cfgfiles(struct MPContext *mpctx)
m_config_parse_config_file(mpctx->mconfig, conffile, SECT_ENCODE, 0);
#endif
// Maintain compatibility with /config
for (char** cf = mp_find_all_config_files(tmp, mpctx->global, "config"); *cf; cf++) {
if (m_config_parse_config_file(conf, *cf, section, 0) < 0) {
r = false;
goto done;
}
}
for (char** cf = mp_find_all_config_files(tmp, mpctx->global, "mpv.conf"); *cf; cf++) {
if (m_config_parse_config_file(conf, *cf, section, 0) < 0) {
r = false;
goto done;
}
}
load_all_cfgfiles(mpctx, section, "config");
load_all_cfgfiles(mpctx, section, "mpv.conf");
if (encoding)
m_config_set_profile(conf, m_config_add_profile(conf, SECT_ENCODE), 0);
done:
talloc_free(tmp);
return r;
}
static int try_load_config(struct MPContext *mpctx, const char *file, int flags)

View File

@ -363,7 +363,7 @@ void clear_audio_output_buffers(struct MPContext *mpctx);
void clear_audio_decode_buffers(struct MPContext *mpctx);
// configfiles.c
bool mp_parse_cfgfiles(struct MPContext *mpctx);
void mp_parse_cfgfiles(struct MPContext *mpctx);
void mp_load_auto_profiles(struct MPContext *mpctx);
void mp_get_resume_defaults(struct MPContext *mpctx);
void mp_load_playback_resume(struct MPContext *mpctx, const char *file);

View File

@ -491,8 +491,7 @@ int mpv_main(int argc, char *argv[])
mp_print_version(mpctx->log, false);
if (!mp_parse_cfgfiles(mpctx))
exit_player(mpctx, EXIT_ERROR);
mp_parse_cfgfiles(mpctx);
int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
mpctx->global, argc, argv);