mirror of
https://github.com/mpv-player/mpv
synced 2024-09-09 01:16:56 +02:00
Factor out code to try and load a config file only if it exists.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29603 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
1cd2feed03
commit
a0eda318e8
27
mplayer.c
27
mplayer.c
@ -913,21 +913,30 @@ static void load_per_output_config (m_config_t* conf, char *cfg, char *out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to load a config file
|
||||||
|
* @return 0 if file was not found, 1 otherwise
|
||||||
|
*/
|
||||||
|
static int try_load_config(m_config_t *conf, const char *file)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
if (stat(file, &st))
|
||||||
|
return 0;
|
||||||
|
mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, file);
|
||||||
|
m_config_parse_config_file (conf, file);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void load_per_file_config (m_config_t* conf, const char *const file)
|
static void load_per_file_config (m_config_t* conf, const char *const file)
|
||||||
{
|
{
|
||||||
char *confpath;
|
char *confpath;
|
||||||
char cfg[strlen(file)+10];
|
char cfg[strlen(file)+10];
|
||||||
struct stat st;
|
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
sprintf (cfg, "%s.conf", file);
|
sprintf (cfg, "%s.conf", file);
|
||||||
|
|
||||||
if (use_filedir_conf && !stat (cfg, &st))
|
if (use_filedir_conf && try_load_config(conf, cfg))
|
||||||
{
|
|
||||||
mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, cfg);
|
|
||||||
m_config_parse_config_file (conf, cfg);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if ((name = strrchr (cfg, '/')) == NULL)
|
if ((name = strrchr (cfg, '/')) == NULL)
|
||||||
name = cfg;
|
name = cfg;
|
||||||
@ -936,11 +945,7 @@ static void load_per_file_config (m_config_t* conf, const char *const file)
|
|||||||
|
|
||||||
if ((confpath = get_path (name)) != NULL)
|
if ((confpath = get_path (name)) != NULL)
|
||||||
{
|
{
|
||||||
if (!stat (confpath, &st))
|
try_load_config(conf, confpath);
|
||||||
{
|
|
||||||
mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_LoadingConfig, confpath);
|
|
||||||
m_config_parse_config_file (conf, confpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
free (confpath);
|
free (confpath);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user