mirror of
https://github.com/mpv-player/mpv
synced 2025-04-17 04:40:09 +00:00
mplayer: factor config dir creation
Move it into its own function.
This commit is contained in:
parent
5165e19a23
commit
497ec230bf
@ -608,6 +608,16 @@ static MP_NORETURN void exit_player(struct MPContext *mpctx,
|
|||||||
exit(rc);
|
exit(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mk_config_dir(char *subdir)
|
||||||
|
{
|
||||||
|
void *tmp = talloc_new(NULL);
|
||||||
|
char *confdir = talloc_steal(tmp, mp_find_user_config_file(""));
|
||||||
|
if (subdir)
|
||||||
|
confdir = mp_path_join(tmp, bstr0(confdir), bstr0(subdir));
|
||||||
|
mkdir(confdir, 0777);
|
||||||
|
talloc_free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
#include "cfg-mplayer.h"
|
#include "cfg-mplayer.h"
|
||||||
|
|
||||||
static int cfg_include(struct m_config *conf, char *filename)
|
static int cfg_include(struct m_config *conf, char *filename)
|
||||||
@ -626,26 +636,21 @@ static bool parse_cfgfiles(struct MPContext *mpctx, m_config_t *conf)
|
|||||||
return true;
|
return true;
|
||||||
if (!m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mpv.conf") < 0)
|
if (!m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mpv.conf") < 0)
|
||||||
return false;
|
return false;
|
||||||
if ((conffile = mp_find_user_config_file("")) == NULL)
|
mk_config_dir(NULL);
|
||||||
mp_tmsg(MSGT_CPLAYER, MSGL_WARN, "Cannot find HOME directory.\n");
|
if ((conffile = mp_find_user_config_file("config")) == NULL)
|
||||||
|
mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
|
||||||
|
"mp_find_user_config_file(\"config\") problem\n");
|
||||||
else {
|
else {
|
||||||
mkdir(conffile, 0777);
|
if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY,
|
||||||
talloc_free(conffile);
|
0666)) != -1) {
|
||||||
if ((conffile = mp_find_user_config_file("config")) == NULL)
|
mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
|
||||||
mp_tmsg(MSGT_CPLAYER, MSGL_ERR,
|
"Creating config file: %s\n", conffile);
|
||||||
"mp_find_user_config_file(\"config\") problem\n");
|
write(conffile_fd, DEF_CONFIG, sizeof(DEF_CONFIG) - 1);
|
||||||
else {
|
close(conffile_fd);
|
||||||
if ((conffile_fd = open(conffile, O_CREAT | O_EXCL | O_WRONLY,
|
|
||||||
0666)) != -1) {
|
|
||||||
mp_tmsg(MSGT_CPLAYER, MSGL_INFO,
|
|
||||||
"Creating config file: %s\n", conffile);
|
|
||||||
write(conffile_fd, DEF_CONFIG, sizeof(DEF_CONFIG) - 1);
|
|
||||||
close(conffile_fd);
|
|
||||||
}
|
|
||||||
if (m_config_parse_config_file(conf, conffile) < 0)
|
|
||||||
return false;
|
|
||||||
talloc_free(conffile);
|
|
||||||
}
|
}
|
||||||
|
if (m_config_parse_config_file(conf, conffile) < 0)
|
||||||
|
return false;
|
||||||
|
talloc_free(conffile);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user