From e50ff873001bd96afc1ac3abd8fa750ec6c549ed Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 21 Oct 2011 16:49:15 +0100 Subject: [PATCH] Relocate appData fgfsrc loading prior to init of fg-root, so we can specify --fg-root that way. --- src/Main/fg_init.cxx | 49 ++++++++++++++++++++------------------------ src/Main/options.cxx | 9 +++++++- src/Main/options.hxx | 2 +- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 6edb7a66d..ad85151c3 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -514,9 +514,28 @@ static SGPath platformDefaultDataPath() #endif // Read in configuration (file and command line) -bool fgInitConfig ( int argc, char **argv ) { - - flightgear::Options::sharedInstance()->init(argc, argv); +bool fgInitConfig ( int argc, char **argv ) +{ + SGPath dataPath = platformDefaultDataPath(); + + const char *fg_home = getenv("FG_HOME"); + if (fg_home) + dataPath = fg_home; + + simgear::Dir exportDir(simgear::Dir(dataPath).file("Export")); + if (!exportDir.exists()) { + exportDir.create(0777); + } + + // Set /sim/fg-home and don't allow malign code to override it until + // Nasal security is set up. Use FG_HOME if necessary. + SGPropertyNode *home = fgGetNode("/sim", true); + home->removeChild("fg-home", 0, false); + home = home->getChild("fg-home", 0, true); + home->setStringValue(dataPath.c_str()); + home->setAttribute(SGPropertyNode::WRITE, false); + + flightgear::Options::sharedInstance()->init(argc, argv, dataPath); // Read global preferences from $FG_ROOT/preferences.xml SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences"); @@ -529,24 +548,7 @@ bool fgInitConfig ( int argc, char **argv ) { } SGPropertyNode autosave; - SGPath dataPath = platformDefaultDataPath(); - - const char *fg_home = getenv("FG_HOME"); - if (fg_home) - dataPath = fg_home; - - simgear::Dir exportDir(simgear::Dir(dataPath).file("Export")); - if (!exportDir.exists()) { - exportDir.create(0777); - } - // Set /sim/fg-home and don't allow malign code to override it until - // Nasal security is set up. Use FG_HOME if necessary. - SGPropertyNode *home = fgGetNode("/sim", true); - home->removeChild("fg-home", 0, false); - home = home->getChild("fg-home", 0, true); - home->setStringValue(dataPath.c_str()); - home->setAttribute(SGPropertyNode::WRITE, false); SGPath autosaveFile = simgear::Dir(dataPath).file("autosave.xml"); if (autosaveFile.exists()) { @@ -558,13 +560,6 @@ bool fgInitConfig ( int argc, char **argv ) { << "(from " << e.getOrigin() << ")"); } } - - // check for a config file in app data - SGPath appDataConfig(dataPath); - appDataConfig.append("fgfsrc"); - if (appDataConfig.exists()) { - flightgear::Options::sharedInstance()->readConfig(appDataConfig); - } // Scan user config files and command line for a specified aircraft. flightgear::Options::sharedInstance()->initAircraft(); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 6dd374a85..06995a288 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -1671,7 +1671,7 @@ Options::~Options() { } -void Options::init(int argc, char **argv) +void Options::init(int argc, char **argv, const SGPath& appDataPath) { fgSetDefaults(); @@ -1717,6 +1717,13 @@ void Options::init(int argc, char **argv) readConfig(config); } +// check for a config file in app data + SGPath appDataConfig(appDataPath); + appDataConfig.append("fgfsrc"); + if (appDataConfig.exists()) { + readConfig(appDataConfig); + } + // setup FG_ROOT setupRoot(); diff --git a/src/Main/options.hxx b/src/Main/options.hxx index bd7e36848..c5d7ab862 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -48,7 +48,7 @@ public: /** * pass command line arguments, read default config files */ - void init(int argc, char* argv[]); + void init(int argc, char* argv[], const SGPath& appDataPath); /** * parse a config file (eg, .fgfsrc)