Config: Parse from command line options on top of config file

Any options that are not arrays (ie. RTP paths) specified
as command line options will override entries in mkxp.conf.

The syntax is: --<option>=<value>
This commit is contained in:
Jonas Kulla 2014-01-10 20:16:34 +01:00
parent b8fc5e25b9
commit c33144552a
3 changed files with 17 additions and 8 deletions

View File

@ -52,7 +52,7 @@ Config::Config()
pathCache(true)
{}
void Config::read()
void Config::read(int argc, char *argv[])
{
#define PO_DESC_ALL \
PO_DESC(debugMode, bool) \
@ -82,22 +82,31 @@ void Config::read()
po::options_description podesc;
podesc.add_options()
PO_DESC_ALL
("RTP", po::value<StringVec>())
("RTP", po::value<StringVec>()->composing())
;
po::variables_map vm;
/* Parse command line options */
po::parsed_options cmdPo =
po::command_line_parser(argc, argv).options(podesc)
.allow_unregistered()
.run();
GUARD_ALL( po::store(cmdPo, vm); )
/* Parse configuration file (mkxp.conf) */
std::ifstream confFile;
confFile.open("mkxp.conf");
po::variables_map vm;
if (confFile)
{
GUARD_ALL( po::store(po::parse_config_file(confFile, podesc, true), vm); )
po::notify(vm);
}
confFile.close();
po::notify(vm);
#undef PO_DESC
#define PO_DESC(key, type) GUARD_ALL( key = vm[#key].as< type >(); )

View File

@ -62,7 +62,7 @@ struct Config
Config();
void read();
void read(int argc, char *argv[]);
void readGameINI();
};

View File

@ -224,7 +224,7 @@ int rgssThreadFun(void *userdata)
return 0;
}
int main(int, char *argv[])
int main(int argc, char *argv[])
{
/* initialize SDL first */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
@ -253,7 +253,7 @@ int main(int, char *argv[])
/* now we load the config */
Config conf;
conf.read();
conf.read(argc, argv);
conf.readGameINI();
int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG;