change to exe dir on startup and add some extra guards around boost program option parsing.

This commit is contained in:
Edward Rudd 2013-12-31 21:03:53 -05:00
parent e87bdb8a95
commit a18497ca7b
2 changed files with 27 additions and 21 deletions

View File

@ -21,11 +21,10 @@
#include "config.h"
#include <SDL2/SDL_filesystem.h>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <fstream>
#include "debugwriter.h"
@ -48,13 +47,7 @@ Config::Config()
solidFonts(false),
gameFolder("."),
allowSymlinks(false)
{
char *dataDir = SDL_GetBasePath();
if (dataDir) {
gameFolder = dataDir;
SDL_free(dataDir);
}
}
{ }
void Config::read()
{
@ -74,6 +67,9 @@ void Config::read()
PO_DESC(allowSymlinks, bool) \
PO_DESC(customScript, std::string)
// Not gonna take your shit boost
#define GUARD_ALL( exp ) try { exp } catch(...) {}
#define PO_DESC(key, type) (#key, po::value< type >()->default_value(key))
po::options_description podesc;
@ -86,13 +82,14 @@ void Config::read()
confFile.open("mkxp.conf");
po::variables_map vm;
po::store(po::parse_config_file(confFile, podesc, true), vm);
po::notify(vm);
if (confFile) {
GUARD_ALL( po::store(po::parse_config_file(confFile, podesc, true), vm); )
po::notify(vm);
}
confFile.close();
// Not gonna take your shit boost
#define GUARD_ALL( exp ) try { exp } catch(...) {}
#undef PO_DESC
#define PO_DESC(key, type) GUARD_ALL( key = vm[#key].as< type >(); )
@ -128,7 +125,7 @@ void Config::readGameINI()
iniFile.open((iniPath).c_str());
po::variables_map vm;
po::store(po::parse_config_file(iniFile, podesc, true), vm);
GUARD_ALL( po::store(po::parse_config_file(iniFile, podesc, true), vm); )
po::notify(vm);
iniFile.close();

View File

@ -232,11 +232,7 @@ int rgssThreadFun(void *userdata)
int main(int, char *argv[])
{
Config conf;
conf.read();
conf.readGameINI();
// initialize SDL first
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
{
Debug() << "Error initializing SDL:" << SDL_GetError();
@ -244,6 +240,19 @@ int main(int, char *argv[])
return 0;
}
// set working directory
char *dataDir = SDL_GetBasePath();
if (dataDir) {
chdir(dataDir);
SDL_free(dataDir);
}
// now we load the config
Config conf;
conf.read();
conf.readGameINI();
int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG;
if (IMG_Init(imgFlags) != imgFlags)
{