From: James Turner Date: Sat, 29 Sep 2012 18:02:03 +0000 (+0100) Subject: Support a --no-default-config option. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3b6c2c426d8fa1b72b7563383cecbba8eb0ff018;p=flightgear.git Support a --no-default-config option. For (future) easier testing of the sim, support a mode where only explicitly named config / option files are loaded, instead of the default ones. (Including, for example, preferences.xml). This currently produces a non-functional sim, but will soon be more useful :) No behaviour should change unless you try the new option. --- diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 38f43dc85..1def26fe1 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -414,25 +414,30 @@ bool fgInitConfig ( int argc, char **argv ) home->setStringValue(dataPath.c_str()); home->setAttribute(SGPropertyNode::WRITE, false); - flightgear::Options::sharedInstance()->init(argc, argv, dataPath); + flightgear::Options* options = flightgear::Options::sharedInstance(); + options->init(argc, argv, dataPath); + bool loadDefaults = flightgear::Options::sharedInstance()->shouldLoadDefaultConfig(); + if (loadDefaults) { + // Read global preferences from $FG_ROOT/preferences.xml + SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences"); + fgLoadProps("preferences.xml", globals->get_props()); + SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences"); + + // do not load user settings when reset to default is requested + if (flightgear::Options::sharedInstance()->isOptionSet("restore-defaults")) + { + SG_LOG(SG_ALL, SG_ALERT, "Ignoring user settings. Restoring defaults."); + } + else + { + globals->loadUserSettings(dataPath); + } + } else { + SG_LOG(SG_GENERAL, SG_INFO, "not reading default configuration files"); + }// of no-default-config selected - // Read global preferences from $FG_ROOT/preferences.xml - SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences"); - fgLoadProps("preferences.xml", globals->get_props()); - SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences"); - - // do not load user settings when reset to default is requested - if (flightgear::Options::sharedInstance()->isOptionSet("restore-defaults")) - { - SG_LOG(SG_ALL, SG_ALERT, "Ignoring user settings. Restoring defaults."); - } - else - { - globals->loadUserSettings(dataPath); - } - // Scan user config files and command line for a specified aircraft. - flightgear::Options::sharedInstance()->initAircraft(); + options->initAircraft(); FindAndCacheAircraft f(globals->get_props()); if (!f.loadAircraft()) { @@ -441,7 +446,7 @@ bool fgInitConfig ( int argc, char **argv ) // parse options after loading aircraft to ensure any user // overrides of defaults are honored. - flightgear::Options::sharedInstance()->processOptions(); + options->processOptions(); return true; } diff --git a/src/Main/options.cxx b/src/Main/options.cxx index d8a48a9a9..4221df758 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -94,7 +94,8 @@ enum FG_OPTIONS_EXIT = 3, FG_OPTIONS_VERBOSE_HELP = 4, FG_OPTIONS_SHOW_AIRCRAFT = 5, - FG_OPTIONS_SHOW_SOUND_DEVICES = 6 + FG_OPTIONS_SHOW_SOUND_DEVICES = 6, + FG_OPTIONS_NO_DEFAULT_CONFIG = 7 }; static flightgear::Options* shared_instance = NULL; @@ -1509,6 +1510,7 @@ struct OptionDesc { {"version", false, OPTION_FUNC, "", false, "", fgOptVersion }, {"enable-fpe", false, OPTION_IGNORE, "", false, "", 0}, {"fgviewer", false, OPTION_IGNORE, "", false, "", 0}, + {"no-default-config", false, OPTION_IGNORE, "", false, "", 0}, {"prop", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptSetProperty}, {0} }; @@ -1665,7 +1667,8 @@ public: bool showHelp, verbose, - showAircraft; + showAircraft, + shouldLoadDefaultConfig; OptionDescDict options; OptionValueVec values; @@ -1687,6 +1690,7 @@ Options::Options() : p->showHelp = false; p->verbose = false; p->showAircraft = false; + p->shouldLoadDefaultConfig = true; // build option map OptionDesc *desc = &fgOptionArray[ 0 ]; @@ -1732,6 +1736,11 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath) // to show extra (debug/info/warning) messages for the start-up phase. fgOptLogLevel(valueForOption("log-level", "alert").c_str()); + if (!p->shouldLoadDefaultConfig) { + setupRoot(); + return; + } + // then config files SGPath config; @@ -1821,7 +1830,9 @@ void Options::processArgResult(int result) else if (result == FG_OPTIONS_VERBOSE_HELP) p->verbose = true; else if (result == FG_OPTIONS_SHOW_AIRCRAFT) { - p->showAircraft = true; + p->showAircraft = true; + } else if (result == FG_OPTIONS_NO_DEFAULT_CONFIG) { + p->shouldLoadDefaultConfig = false; } else if (result == FG_OPTIONS_SHOW_SOUND_DEVICES) { SGSoundMgr smgr; @@ -1890,6 +1901,8 @@ int Options::parseOption(const string& s) return(FG_OPTIONS_SHOW_AIRCRAFT); } else if ( s.find( "--show-sound-devices") == 0) { return(FG_OPTIONS_SHOW_SOUND_DEVICES); + } else if ( s.find( "--no-default-config") == 0) { + return FG_OPTIONS_NO_DEFAULT_CONFIG; } else if ( s.find( "--prop:") == 0) { // property setting has a slightly different syntax, so fudge things OptionDesc* desc = p->findOption("prop"); @@ -2271,5 +2284,10 @@ void Options::setupRoot() } } +bool Options::shouldLoadDefaultConfig() const +{ + return p->shouldLoadDefaultConfig; +} + } // of namespace flightgear diff --git a/src/Main/options.hxx b/src/Main/options.hxx index c5d7ab862..082d4a430 100644 --- a/src/Main/options.hxx +++ b/src/Main/options.hxx @@ -88,6 +88,16 @@ public: * init the aircraft options */ void initAircraft(); + + /** + * should defualt configuration files be loaded and processed or not? + * There's many configuration files we have historically read by default + * on startup - preferences.xml, fgfs.rc in various places and so on. + * --no-default-config allows this behaviour to be changed, so only + * expicitly listed files are read - this is useful for testing. Expose + * the value of the option here. + */ + bool shouldLoadDefaultConfig() const; private: void showUsage() const;