]> git.mxchange.org Git - flightgear.git/commitdiff
Support a --no-default-config option.
authorJames Turner <zakalawe@mac.com>
Sat, 29 Sep 2012 18:02:03 +0000 (19:02 +0100)
committerJames Turner <zakalawe@mac.com>
Sat, 29 Sep 2012 18:02:03 +0000 (19:02 +0100)
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.

src/Main/fg_init.cxx
src/Main/options.cxx
src/Main/options.hxx

index 38f43dc85deca7ea4f2984eaddb63a6bcb9b8ed6..1def26fe196c996b12330628cc9246912cde7222 100644 (file)
@@ -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;
 }
index d8a48a9a905ab5dc3f97034a341cae4e01eb5db0..4221df758be55285d7bb07edb4ea87b9b00b0876 100644 (file)
@@ -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
 
index c5d7ab86274949aff4f17035553b4a00482d8f0e..082d4a430c7d61c2770663c7aaaf58c445ca894b 100644 (file)
@@ -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;