From a18497ca7badad7a14678a861a09ea6991713a00 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Tue, 31 Dec 2013 21:03:53 -0500 Subject: [PATCH] change to exe dir on startup and add some extra guards around boost program option parsing. --- src/config.cpp | 25 +++++++++++-------------- src/main.cpp | 23 ++++++++++++++++------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 0d14a61..13eeb18 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -21,11 +21,10 @@ #include "config.h" -#include - #include #include #include + #include #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(); diff --git a/src/main.cpp b/src/main.cpp index 049f5df..e6283e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -232,18 +232,27 @@ int rgssThreadFun(void *userdata) int main(int, char *argv[]) { + // initialize SDL first + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) + { + Debug() << "Error initializing SDL:" << SDL_GetError(); + + 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(); - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) - { - Debug() << "Error initializing SDL:" << SDL_GetError(); - - return 0; - } - int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG; if (IMG_Init(imgFlags) != imgFlags) {