]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/options.cxx
Crash-fix: mat-lib is now reference-counted.
[flightgear.git] / src / Main / options.cxx
index 53887aa2f3cc9fd4cd3101f0511c051bc27e7b98..3c20cdee8a8154d97cdeab7822e9feaa46bf50eb 100644 (file)
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/misc/strutils.hxx>
 #include <Autopilot/route_mgr.hxx>
+
 #include <GUI/gui.h>
+#include <GUI/MessageBox.hxx>
 
+#include <Main/locale.hxx>
 #include "globals.hxx"
 #include "fg_init.hxx"
 #include "fg_props.hxx"
 #include "options.hxx"
 #include "util.hxx"
-#include "viewmgr.hxx"
-#include <Main/viewer.hxx>
+#include "main.hxx"
+#include "locale.hxx"
+#include <Viewer/viewer.hxx>
+#include <Viewer/viewmgr.hxx>
 #include <Environment/presets.hxx>
+#include "AircraftDirVisitorBase.hxx"
 
 #include <osg/Version>
 
 #  include <Include/no_version.h>
 #endif
 
-#ifdef __APPLE__
-#  include <CoreFoundation/CoreFoundation.h>
-#endif
-
 using std::string;
 using std::sort;
 using std::cout;
@@ -82,22 +84,9 @@ using std::endl;
 using std::vector;
 using std::cin;
 
-#define NEW_DEFAULT_MODEL_HZ 120
-
-// defined in bootstrap.cxx
-extern char *homedir;
-extern char *hostname;
+using namespace flightgear;
 
-enum
-{
-    FG_OPTIONS_OK = 0,
-    FG_OPTIONS_HELP = 1,
-    FG_OPTIONS_ERROR = 2,
-    FG_OPTIONS_EXIT = 3,
-    FG_OPTIONS_VERBOSE_HELP = 4,
-    FG_OPTIONS_SHOW_AIRCRAFT = 5,
-    FG_OPTIONS_SHOW_SOUND_DEVICES = 6
-};
+#define NEW_DEFAULT_MODEL_HZ 120
 
 static flightgear::Options* shared_instance = NULL;
 
@@ -122,8 +111,7 @@ static int fgSetupProxy( const char *arg );
  * in case, we provide some initial sane values here. This method
  * should be invoked *before* reading any init files.
  */
-static void
-fgSetDefaults ()
+void fgSetDefaults ()
 {
 
                                // Position (deliberately out of range)
@@ -169,25 +157,12 @@ fgSetDefaults ()
     fgSetBool("/sim/presets/trim", false);
 
                                // Miscellaneous
-    fgSetBool("/sim/startup/game-mode", false);
     fgSetBool("/sim/startup/splash-screen", true);
-    fgSetBool("/sim/startup/intro-music", true);
     // we want mouse-pointer to have an undefined value if nothing is
     // specified so we can do the right thing for voodoo-1/2 cards.
     // fgSetString("/sim/startup/mouse-pointer", "disabled");
     fgSetString("/sim/control-mode", "joystick");
-    fgSetBool("/sim/auto-coordination", false);
-#if defined(WIN32)
-    fgSetString("/sim/startup/browser-app", "webrun.bat");
-#elif defined(__APPLE__)
-    fgSetString("/sim/startup/browser-app", "open");
-#elif defined(sgi)
-    fgSetString("/sim/startup/browser-app", "launchWebJumper");
-#else
-    const char* browserEnv = ::getenv( "WEBBROWSER" );
-    if (!browserEnv) browserEnv = "netscape";
-    fgSetString("/sim/startup/browser-app", browserEnv);
-#endif
+    fgSetBool("/controls/flight/auto-coordination", false);
     fgSetString("/sim/logging/priority", "alert");
 
                                // Features
@@ -197,19 +172,19 @@ fgSetDefaults ()
     fgSetBool("/sim/panel/visibility", true);
     fgSetBool("/sim/sound/enabled", true);
     fgSetBool("/sim/sound/working", true);
+    fgSetBool("/sim/fgcom/enabled", false);
 
                                // Flight Model options
     fgSetString("/sim/flight-model", "jsb");
     fgSetString("/sim/aero", "c172");
     fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
-    fgSetInt("/sim/speed-up", 1);
+    fgSetDouble("/sim/speed-up", 1.0);
 
                                // Rendering options
     fgSetString("/sim/rendering/fog", "nicest");
     fgSetBool("/environment/clouds/status", true);
     fgSetBool("/sim/startup/fullscreen", false);
     fgSetBool("/sim/rendering/shading", true);
-    fgSetBool("/sim/rendering/skyblend", true);
     fgSetBool("/sim/rendering/textures", true);
     fgTie( "/sim/rendering/filtering", SGGetTextureFilter, SGSetTextureFilter, false);
     fgSetInt("/sim/rendering/filtering", 1);
@@ -219,9 +194,9 @@ fgSetDefaults ()
     fgSetBool("/sim/rendering/distance-attenuation", false);
     fgSetBool("/sim/rendering/specular-highlight", true);
     fgSetString("/sim/rendering/materials-file", "materials.xml");
-    fgSetInt("/sim/startup/xsize", 800);
-    fgSetInt("/sim/startup/ysize", 600);
-    fgSetInt("/sim/rendering/bits-per-pixel", 16);
+    fgSetInt("/sim/startup/xsize", 1024);
+    fgSetInt("/sim/startup/ysize", 768);
+    fgSetInt("/sim/rendering/bits-per-pixel", 32);
     fgSetString("/sim/view-mode", "pilot");
     fgSetDouble("/sim/current-view/heading-offset-deg", 0);
 
@@ -246,18 +221,145 @@ fgSetDefaults ()
     fgSetInt("/sim/multiplay/rxport", 0);
     fgSetInt("/sim/multiplay/txport", 0);
     
-    fgSetString("/sim/version/flightgear", FLIGHTGEAR_VERSION);
-    fgSetString("/sim/version/simgear", SG_STRINGIZE(SIMGEAR_VERSION));
-    fgSetString("/sim/version/openscenegraph", osgGetVersion());
-    fgSetString("/sim/version/revision", REVISION);
-    fgSetInt("/sim/version/build-number", HUDSON_BUILD_NUMBER);
-    fgSetString("/sim/version/build-id", HUDSON_BUILD_ID);
-  
-  char* envp = ::getenv( "http_proxy" );
+    SGPropertyNode* v = globals->get_props()->getNode("/sim/version", true);
+    v->setValueReadOnly("flightgear", FLIGHTGEAR_VERSION);
+    v->setValueReadOnly("simgear", SG_STRINGIZE(SIMGEAR_VERSION));
+    v->setValueReadOnly("openscenegraph", osgGetVersion());
+    v->setValueReadOnly("openscenegraph-thread-safe-reference-counting",
+                         osg::Referenced::getThreadSafeReferenceCounting());
+    v->setValueReadOnly("revision", REVISION);
+    v->setValueReadOnly("build-number", HUDSON_BUILD_NUMBER);
+    v->setValueReadOnly("build-id", HUDSON_BUILD_ID);
+    v->setValueReadOnly("hla-support", bool(FG_HAVE_HLA));
+
+    char* envp = ::getenv( "http_proxy" );
     if( envp != NULL )
       fgSetupProxy( envp );
 }
 
+///////////////////////////////////////////////////////////////////////////////
+// helper object to implement the --show-aircraft command.
+// resides here so we can share the fgFindAircraftInDir template above,
+// and hence ensure this command lists exectly the same aircraft as the normal
+// loading path.
+class ShowAircraft : public AircraftDirVistorBase
+{
+public:
+    ShowAircraft()
+    {
+        _minStatus = getNumMaturity(fgGetString("/sim/aircraft-min-status", "all"));
+    }
+    
+    
+    void show(const SGPath& path)
+    {
+        visitDir(path, 0);
+        
+        simgear::requestConsole(); // ensure console is shown on Windows
+        
+        std::sort(_aircraft.begin(), _aircraft.end(), ciLessLibC());
+        cout << "Available aircraft:" << endl;
+        for ( unsigned int i = 0; i < _aircraft.size(); i++ ) {
+            cout << _aircraft[i] << endl;
+        }
+    }
+    
+private:
+    virtual VisitResult visit(const SGPath& path)
+    {
+        SGPropertyNode root;
+        try {
+            readProperties(path.str(), &root);
+        } catch (sg_exception& ) {
+            return VISIT_CONTINUE;
+        }
+        
+        int maturity = 0;
+        string descStr("   ");
+        descStr += path.file();
+        // trim common suffix from file names
+        int nPos = descStr.rfind("-set.xml");
+        if (nPos == (int)(descStr.size() - 8)) {
+            descStr.resize(nPos);
+        }
+        
+        SGPropertyNode *node = root.getNode("sim");
+        if (node) {
+            SGPropertyNode* desc = node->getNode("description");
+            // if a status tag is found, read it in
+            if (node->hasValue("status")) {
+                maturity = getNumMaturity(node->getStringValue("status"));
+            }
+            
+            if (desc) {
+                if (descStr.size() <= 27+3) {
+                    descStr.append(29+3-descStr.size(), ' ');
+                } else {
+                    descStr += '\n';
+                    descStr.append( 32, ' ');
+                }
+                descStr += desc->getStringValue();
+            }
+        } // of have 'sim' node
+        
+        if (maturity >= _minStatus) {
+            _aircraft.push_back(descStr);
+        }
+        
+        return VISIT_CONTINUE;
+    }
+    
+    
+    int getNumMaturity(const char * str)
+    {
+        // changes should also be reflected in $FG_ROOT/data/options.xml &
+        // $FG_ROOT/data/Translations/string-default.xml
+        const char* levels[] = {"alpha","beta","early-production","production"};
+        
+        if (!strcmp(str, "all")) {
+            return 0;
+        }
+        
+        for (size_t i=0; i<(sizeof(levels)/sizeof(levels[0]));i++)
+            if (strcmp(str,levels[i])==0)
+                return i;
+        
+        return 0;
+    }
+    
+    // recommended in Meyers, Effective STL when internationalization and embedded
+    // NULLs aren't an issue.  Much faster than the STL or Boost lex versions.
+    struct ciLessLibC : public std::binary_function<string, string, bool>
+    {
+        bool operator()(const std::string &lhs, const std::string &rhs) const
+        {
+            return strcasecmp(lhs.c_str(), rhs.c_str()) < 0 ? 1 : 0;
+        }
+    };
+    
+    int _minStatus;
+    string_list _aircraft;
+};
+
+/*
+ * Search in the current directory, and in on directory deeper
+ * for <aircraft>-set.xml configuration files and show the aircaft name
+ * and the contents of the<description> tag in a sorted manner.
+ *
+ * @parampath the directory to search for configuration files
+ */
+void fgShowAircraft(const SGPath &path)
+{
+    ShowAircraft s;
+    s.show(path);
+    
+#ifdef _MSC_VER
+    cout << "Hit a key to continue..." << endl;
+    std::cin.get();
+#endif
+}
+
+
 static bool
 parse_wind (const string &wind, double * min_hdg, double * max_hdg,
            double * speed, double * gust)
@@ -423,8 +525,8 @@ parse_date( const string& date, const char* timeType)
     int year,month,day,hour,minute,second;
     char *argument, *date_str;
 
-    SGTime CurrentTime = SGTime();
-    CurrentTime.update(0,0,0,0);
+    SGTime CurrentTime;
+    CurrentTime.update(SGGeod(),0,0);
 
     // FIXME This should obtain system/aircraft/GMT time depending on timeType
     pCurrentTime = CurrentTime.getGmt();
@@ -562,13 +664,6 @@ add_channel( const string& type, const string& channel_str ) {
     return true;
 }
 
-static int
-fgOptLanguage( const char *arg )
-{
-    globals->set_locale( fgInitLocale( arg ) );
-    return FG_OPTIONS_OK;
-}
-
 static void
 clearLocation ()
 {
@@ -742,7 +837,7 @@ fgOptMach( const char *arg )
 static int
 fgOptRoc( const char *arg )
 {
-    fgSetDouble("/velocities/vertical-speed-fps", atof(arg)/60);
+    fgSetDouble("/sim/presets/vertical-speed-fps", atof(arg)/60);
     return FG_OPTIONS_OK;
 }
 
@@ -1029,12 +1124,12 @@ fgOptConfig( const char *arg )
 {
     string file = arg;
     try {
-       readProperties(file, globals->get_props());
+        readProperties(file, globals->get_props());
     } catch (const sg_exception &e) {
-       string message = "Error loading config file: ";
-       message += e.getFormattedMessage() + e.getOrigin();
-       SG_LOG(SG_INPUT, SG_ALERT, message);
-       exit(2);
+        string message = "Error loading config file: ";
+        message += e.getFormattedMessage() + e.getOrigin();
+        SG_LOG(SG_INPUT, SG_ALERT, message);
+        return FG_OPTIONS_ERROR;
     }
     return FG_OPTIONS_OK;
 }
@@ -1165,16 +1260,6 @@ fgOptScenario( const char *arg )
     }
     SGPropertyNode_ptr scenario = ai_node->getNode( "scenario", index + 1, true );
     scenario->setStringValue( arg );
-    ai_node->setBoolValue( "enabled", true );
-    return FG_OPTIONS_OK;
-}
-
-static int
-fgOptNoScenarios( const char *arg )
-{
-    SGPropertyNode_ptr ai_node = fgGetNode( "/sim/ai", true );
-    ai_node->removeChildren("scenario",false);
-    ai_node->setBoolValue( "enabled", false );
     return FG_OPTIONS_OK;
 }
 
@@ -1202,7 +1287,7 @@ fgOptVersion( const char *arg )
     cerr << "Revision: " << REVISION << endl;
     cerr << "Build-Id: " << HUDSON_BUILD_ID << endl;
     cerr << "FG_ROOT=" << globals->get_fg_root() << endl;
-    cerr << "FG_HOME=" << fgGetString("/sim/fg-home") << endl;
+    cerr << "FG_HOME=" << globals->get_fg_home() << endl;
     cerr << "FG_SCENERY=";
 
     int didsome = 0;
@@ -1240,6 +1325,14 @@ fgOptCallSign(const char * arg)
     return FG_OPTIONS_OK;
 }
 
+static int
+fgOptIgnoreAutosave(const char* arg)
+{
+    fgSetBool("/sim/startup/ignore-autosave", true);
+    // don't overwrite autosave on exit
+    fgSetBool("/sim/startup/save-on-exit", false);
+    return FG_OPTIONS_OK;
+}
 
 // Set a property for the --prop: option. Syntax: --prop:[<type>:]<name>=<value>
 // <type> can be "double" etc. but also only the first letter "d".
@@ -1330,17 +1423,21 @@ struct OptionDesc {
     int (*func)( const char * );
     } fgOptionArray[] = {
 
-    {"language",                     true,  OPTION_FUNC,   "", false, "", fgOptLanguage },
-    {"disable-game-mode",            false, OPTION_BOOL,   "/sim/startup/game-mode", false, "", 0 },
-    {"enable-game-mode",             false, OPTION_BOOL,   "/sim/startup/game-mode", true, "", 0 },
+    {"language",                     true,  OPTION_IGNORE, "", false, "", 0 },
+       {"console",                      false, OPTION_IGNORE,   "", false, "", 0 },
+    {"disable-rembrandt",            false, OPTION_BOOL,   "/sim/rendering/rembrandt/enabled", false, "", 0 },
+    {"enable-rembrandt",             false, OPTION_BOOL,   "/sim/rendering/rembrandt/enabled", true, "", 0 },
+    {"renderer",                     true,  OPTION_STRING, "/sim/rendering/rembrandt/renderer", false, "", 0 },
     {"disable-splash-screen",        false, OPTION_BOOL,   "/sim/startup/splash-screen", false, "", 0 },
     {"enable-splash-screen",         false, OPTION_BOOL,   "/sim/startup/splash-screen", true, "", 0 },
-    {"disable-intro-music",          false, OPTION_BOOL,   "/sim/startup/intro-music", false, "", 0 },
-    {"enable-intro-music",           false, OPTION_BOOL,   "/sim/startup/intro-music", true, "", 0 },
     {"disable-mouse-pointer",        false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "disabled", 0 },
     {"enable-mouse-pointer",         false, OPTION_STRING, "/sim/startup/mouse-pointer", false, "enabled", 0 },
     {"disable-random-objects",       false, OPTION_BOOL,   "/sim/rendering/random-objects", false, "", 0 },
     {"enable-random-objects",        false, OPTION_BOOL,   "/sim/rendering/random-objects", true, "", 0 },
+    {"disable-random-vegetation",    false, OPTION_BOOL,   "/sim/rendering/random-vegetation", false, "", 0 },
+    {"enable-random-vegetation",     false, OPTION_BOOL,   "/sim/rendering/random-vegetation", true, "", 0 },
+    {"disable-random-buildings",     false, OPTION_BOOL,   "/sim/rendering/random-buildings", false, "", 0 },
+    {"enable-random-buildings",      false, OPTION_BOOL,   "/sim/rendering/random-buildings", true, "", 0 },
     {"disable-real-weather-fetch",   false, OPTION_BOOL,   "/environment/realwx/enabled", false, "", 0 },
     {"enable-real-weather-fetch",    false, OPTION_BOOL,   "/environment/realwx/enabled", true,  "", 0 },
     {"metar",                        true,  OPTION_STRING, "/environment/metar/data", false, "", 0 },
@@ -1359,8 +1456,8 @@ struct OptionDesc {
     {"disable-anti-alias-hud",       false, OPTION_BOOL,   "/sim/hud/color/antialiased", false, "", 0 },
     {"enable-anti-alias-hud",        false, OPTION_BOOL,   "/sim/hud/color/antialiased", true, "", 0 },
     {"control",                      true,  OPTION_STRING, "/sim/control-mode", false, "", 0 },
-    {"disable-auto-coordination",    false, OPTION_BOOL,   "/sim/auto-coordination", false, "", 0 },
-    {"enable-auto-coordination",     false, OPTION_BOOL,   "/sim/auto-coordination", true, "", 0 },
+    {"disable-auto-coordination",    false, OPTION_BOOL,   "/controls/flight/auto-coordination", false, "", 0 },
+    {"enable-auto-coordination",     false, OPTION_BOOL,   "/controls/flight/auto-coordination", true, "", 0 },
     {"browser-app",                  true,  OPTION_STRING, "/sim/startup/browser-app", false, "", 0 },
     {"disable-hud",                  false, OPTION_BOOL,   "/sim/hud/visibility[1]", false, "", 0 },
     {"enable-hud",                   false, OPTION_BOOL,   "/sim/hud/visibility[1]", true, "", 0 },
@@ -1403,7 +1500,8 @@ struct OptionDesc {
     {"aero",                         true,  OPTION_STRING, "/sim/aero", false, "", 0 },
     {"aircraft-dir",                 true,  OPTION_IGNORE,   "", false, "", 0 },
     {"model-hz",                     true,  OPTION_INT,    "/sim/model-hz", false, "", 0 },
-    {"speed",                        true,  OPTION_INT,    "/sim/speed-up", false, "", 0 },
+    {"max-fps",                      true,  OPTION_DOUBLE, "/sim/frame-rate-throttle-hz", false, "", 0 },
+    {"speed",                        true,  OPTION_DOUBLE, "/sim/speed-up", false, "", 0 },
     {"trim",                         false, OPTION_BOOL,   "/sim/presets/trim", true, "", 0 },
     {"notrim",                       false, OPTION_BOOL,   "/sim/presets/trim", false, "", 0 },
     {"on-ground",                    false, OPTION_BOOL,   "/sim/presets/onground", true, "", 0 },
@@ -1429,10 +1527,11 @@ struct OptionDesc {
     {"enable-fullscreen",            false, OPTION_BOOL,   "/sim/startup/fullscreen", true, "", 0 },
     {"disable-save-on-exit",         false, OPTION_BOOL,   "/sim/startup/save-on-exit", false, "", 0 },
     {"enable-save-on-exit",          false, OPTION_BOOL,   "/sim/startup/save-on-exit", true, "", 0 },
+    {"read-only",                    false, OPTION_BOOL,   "/sim/fghome-readonly", true, "", 0 },
+    {"ignore-autosave",              false, OPTION_FUNC,   "", false, "", fgOptIgnoreAutosave },
+    {"restore-defaults",             false, OPTION_BOOL,   "/sim/startup/restore-defaults", true, "", 0 },
     {"shading-flat",                 false, OPTION_BOOL,   "/sim/rendering/shading", false, "", 0 },
     {"shading-smooth",               false, OPTION_BOOL,   "/sim/rendering/shading", true, "", 0 },
-    {"disable-skyblend",             false, OPTION_BOOL,   "/sim/rendering/skyblend", false, "", 0 },
-    {"enable-skyblend",              false, OPTION_BOOL,   "/sim/rendering/skyblend", true, "", 0 },
     {"disable-textures",             false, OPTION_BOOL,   "/sim/rendering/textures", false, "", 0 },
     {"enable-textures",              false, OPTION_BOOL,   "/sim/rendering/textures", true, "", 0 },
     {"texture-filtering",            false, OPTION_INT,    "/sim/rendering/filtering", 1, "", 0 },
@@ -1472,6 +1571,7 @@ struct OptionDesc {
     {"AV400WSimA",                   true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
     {"AV400WSimB",                   true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
     {"garmin",                       true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
+    {"igc",                          true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
     {"nmea",                         true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
     {"generic",                      true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
     {"props",                        true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
@@ -1484,8 +1584,9 @@ struct OptionDesc {
     {"proxy",                        true,  OPTION_FUNC,    "", false, "", fgSetupProxy },
     {"callsign",                     true,  OPTION_FUNC,    "", false, "", fgOptCallSign},
     {"multiplay",                    true,  OPTION_CHANNEL | OPTION_MULTI, "", false, "", 0 },
-#ifdef FG_HAVE_HLA
+#if FG_HAVE_HLA
     {"hla",                          true,  OPTION_CHANNEL, "", false, "", 0 },
+    {"hla-local",                    true,  OPTION_CHANNEL, "", false, "", 0 },
 #endif
     {"trace-read",                   true,  OPTION_FUNC | OPTION_MULTI,   "", false, "", fgOptTraceRead },
     {"trace-write",                  true,  OPTION_FUNC | OPTION_MULTI,   "", false, "", fgOptTraceWrite },
@@ -1504,6 +1605,10 @@ struct OptionDesc {
     {"aircraft",                     true,  OPTION_STRING, "/sim/aircraft", false, "", 0 },
     {"vehicle",                      true,  OPTION_STRING, "/sim/aircraft", false, "", 0 },
     {"failure",                      true,  OPTION_FUNC | OPTION_MULTI,   "", false, "", fgOptFailure },
+#ifdef ENABLE_IAX
+    {"enable-fgcom",                 false, OPTION_BOOL,   "/sim/fgcom/enabled", true, "", 0 },
+    {"disable-fgcom",                false, OPTION_BOOL,   "/sim/fgcom/enabled", false, "", 0 },
+#endif
     {"com1",                         true,  OPTION_DOUBLE, "/instrumentation/comm[0]/frequencies/selected-mhz", false, "", 0 },
     {"com2",                         true,  OPTION_DOUBLE, "/instrumentation/comm[1]/frequencies/selected-mhz", false, "", 0 },
     {"nav1",                         true,  OPTION_FUNC,   "", false, "", fgOptNAV1 },
@@ -1515,11 +1620,11 @@ struct OptionDesc {
     {"min-status",                   true,  OPTION_STRING,  "/sim/aircraft-min-status", false, "all", 0 },
     {"livery",                       true,  OPTION_FUNC,   "", false, "", fgOptLivery },
     {"ai-scenario",                  true,  OPTION_FUNC | OPTION_MULTI,   "", false, "", fgOptScenario },
-    {"disable-ai-scenarios",         false, OPTION_FUNC,   "", false, "", fgOptNoScenarios},
     {"parking-id",                   true,  OPTION_FUNC,   "", false, "", fgOptParking  },
     {"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}
 };
@@ -1676,8 +1781,9 @@ public:
   
   bool showHelp,
     verbose,
-    showAircraft;
-
+    showAircraft,
+    shouldLoadDefaultConfig;
+    
   OptionDescDict options;
   OptionValueVec values;
   simgear::PathList propertyFiles;
@@ -1698,6 +1804,7 @@ Options::Options() :
   p->showHelp = false;
   p->verbose = false;
   p->showAircraft = false;
+  p->shouldLoadDefaultConfig = true;
   
 // build option map
   OptionDesc *desc = &fgOptionArray[ 0 ];
@@ -1713,8 +1820,6 @@ Options::~Options()
   
 void Options::init(int argc, char **argv, const SGPath& appDataPath)
 {
-  fgSetDefaults();
-  
 // first, process the command line
   bool inOptions = true;
   for (int i=1; i<argc; ++i) {
@@ -1739,10 +1844,23 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
   } // of arguments iteration
   p->insertGroupMarker(); // command line is one group
   
+  // establish log-level before anything else - otherwise it is not possible
+  // 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;
-  
-  if( homedir && hostname && strlen(hostname) > 0 ) {
+  std::string homedir;
+  if (getenv("HOME")) {
+    homedir = getenv("HOME");
+  }
+    
+  if( !homedir.empty() && !hostname.empty() ) {
     // Check for ~/.fgfsrc.hostname
     config.set(homedir);
     config.append(".fgfsrc");
@@ -1752,7 +1870,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
   }
   
 // Check for ~/.fgfsrc
-  if( homedir ) {
+  if( !homedir.empty() ) {
     config.set(homedir);
     config.append(".fgfsrc");
     readConfig(config);
@@ -1769,7 +1887,7 @@ void Options::init(int argc, char **argv, const SGPath& appDataPath)
   setupRoot();
   
 // system.fgfsrc handling
-  if( hostname && strlen(hostname) > 0 ) {
+  if( ! hostname.empty() ) {
     config.set(globals->get_fg_root());
     config.append( "system.fgfsrc" );
     config.concat( "." );
@@ -1807,6 +1925,10 @@ void Options::initAircraft()
     SG_LOG(SG_INPUT, SG_INFO, "No user specified aircraft, using default" );
   }
   
+// persist across reset
+  SGPropertyNode* aircraftProp = fgGetNode("/sim/aircraft", true);
+  aircraftProp->setAttribute(SGPropertyNode::PRESERVE, true);
+    
   if (p->showAircraft) {
     fgOptLogLevel( "alert" );
     SGPath path( globals->get_fg_root() );
@@ -1828,7 +1950,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;
     
@@ -1843,6 +1967,7 @@ void Options::processArgResult(int result)
       cout << i << ".  \"" << devices[i] << "\"" << endl;
     }
     devices.clear();
+    smgr.stop();
     exit(0);
   } else if (result == FG_OPTIONS_EXIT) {
     exit(0);
@@ -1888,6 +2013,9 @@ int Options::parseOption(const string& s)
   } else if ( (s == "--verbose") || (s == "-v") ) {
     // verbose help/usage request
     return FG_OPTIONS_VERBOSE_HELP;
+  } else if ((s == "--console") || (s == "-c")) {
+         simgear::requestConsole();
+         return FG_OPTIONS_OK;
   } else if (s.find("-psn") == 0) {
     // on Mac, when launched from the GUI, we are passed the ProcessSerialNumber
     // as an argument (and no others). Silently ignore the argument here.
@@ -1896,6 +2024,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");
@@ -1975,14 +2105,18 @@ string_list Options::valuesForOption(const std::string& key) const
   
   return result;
 }
-  
-void Options::processOptions()
+
+OptionResult Options::processOptions()
 {
+  // establish locale before showing help (this selects the default locale,
+  // when no explicit option was set)
+  globals->get_locale()->selectLanguage(valueForOption("language").c_str());
+
   // now FG_ROOT is setup, process various command line options that bail us
   // out quickly, but rely on aircraft / root settings
   if (p->showHelp) {
     showUsage();
-    exit(0);
+      return FG_OPTIONS_EXIT;
   }
   
   // processing order is complicated. We must process groups LIFO, but the
@@ -1991,22 +2125,30 @@ void Options::processOptions()
   // in practice this means system.fgfsrc must be *processed* before
   // .fgfsrc, which must be processed before the command line args, and so on.
   OptionValueVec::const_iterator groupEnd = p->values.end();
-    
+
   while (groupEnd != p->values.begin()) {
     OptionValueVec::const_iterator groupBegin = p->rfindGroup(groupEnd);
   // run over the group in FIFO order
     OptionValueVec::const_iterator it;
     for (it = groupBegin; it != groupEnd; ++it) {      
       int result = p->processOption(it->desc, it->value);
-      if (result == FG_OPTIONS_ERROR) {
-        showUsage();
-        exit(-1);
+      switch(result)
+      {
+          case FG_OPTIONS_ERROR:
+              showUsage();
+              return FG_OPTIONS_ERROR;
+              
+          case FG_OPTIONS_EXIT:
+              return FG_OPTIONS_EXIT;
+              
+          default:
+              break;
       }
     }
     
     groupEnd = groupBegin;
   }
-  
+
   BOOST_FOREACH(const SGPath& file, p->propertyFiles) {
     if (!file.exists()) {
       SG_LOG(SG_GENERAL, SG_ALERT, "config file not found:" << file.str());
@@ -2025,22 +2167,30 @@ void Options::processOptions()
   }
     
 // terrasync directory fixup
+  string terrasyncDir = fgGetString("/sim/terrasync/scenery-dir");
+  if (terrasyncDir.empty()) {
+    SGPath p(globals->get_fg_home());
+    p.append("TerraSync");
+    terrasyncDir = p.str();
+    SG_LOG(SG_GENERAL, SG_INFO,
+           "Using default TerraSync dir: " << terrasyncDir);
+    fgSetString("/sim/terrasync/scenery-dir", terrasyncDir);
+  }
+  
+  SGPath p(terrasyncDir);
+  // following is necessary to ensure NavDataCache sees stable scenery paths from
+  // terrasync. Ensure the Terrain and Objects subdirs exist immediately, rather
+  // than waiting for the first tiles to be scheduled.
+  simgear::Dir terrainDir(SGPath(p, "Terrain")),
+    objectsDir(SGPath(p, "Objects"));
+  if (!terrainDir.exists()) {
+      terrainDir.create(0755);
+  }
+  
+  if (!objectsDir.exists()) {
+      objectsDir.create(0755);
+  }
   if (fgGetBool("/sim/terrasync/enabled")) {
-    string terrasyncDir = fgGetString("/sim/terrasync/scenery-dir");
-    if (terrasyncDir.empty()) {
-      SGPath p(fgGetString("/sim/fg-home"));
-      p.append("TerraSync");
-      if (!p.exists()) {
-        simgear::Dir dd(p);
-        dd.create(0700);
-      }
-      
-      terrasyncDir = p.str();
-      SG_LOG(SG_GENERAL, SG_INFO,
-             "Using default TerraSync dir: " << terrasyncDir);
-      fgSetString("/sim/terrasync/scenery-dir", terrasyncDir);
-    }
-    
     const string_list& scenery_paths(globals->get_fg_scenery());
     if (std::find(scenery_paths.begin(), scenery_paths.end(), terrasyncDir) == scenery_paths.end()) {
       // terrasync dir is not in the scenery paths, add it
@@ -2054,18 +2204,20 @@ void Options::processOptions()
     root.append("Scenery");
     globals->append_fg_scenery(root.str());
   }
+    
+  return FG_OPTIONS_OK;
 }
   
 void Options::showUsage() const
 {
   fgOptLogLevel( "alert" );
   
-  SGPropertyNode *locale = globals->get_locale();
+  FGLocale *locale = globals->get_locale();
   SGPropertyNode options_root;
   
-  SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on Windows
+  simgear::requestConsole(); // ensure console is shown on Windows
   cout << endl;
-  
+
   try {
     fgLoadProps("options.xml", &options_root);
   } catch (const sg_exception &) {
@@ -2076,17 +2228,23 @@ void Options::showUsage() const
     
     exit(-1);
   }
-  
+
   SGPropertyNode *options = options_root.getNode("options");
   if (!options) {
     SG_LOG( SG_GENERAL, SG_ALERT,
            "Error reading options.xml: <options> directive not found." );
     exit(-1);
   }
-  
-  SGPropertyNode *usage = locale->getNode(options->getStringValue("usage"));
+
+  if (!locale->loadResource("options"))
+  {
+      cout << "Unable to read the language resource." << endl;
+      exit(-1);
+  }
+
+  const char* usage = locale->getLocalizedString(options->getStringValue("usage"), "options");
   if (usage) {
-    cout << "Usage: " << usage->getStringValue() << endl;
+    cout << usage << endl;
   }
   
   vector<SGPropertyNode_ptr>section = options->getChildren("section");
@@ -2127,21 +2285,17 @@ void Options::showUsage() const
           msg += tmp + '\n';
           msg.append(32, ' ');
         }
-        // There may be more than one <description> tag assosiated
+        // There may be more than one <description> tag associated
         // with one option
         
         vector<SGPropertyNode_ptr> desc;
         desc = option[k]->getChildren("description");
-        if (desc.size() > 0) {
+        if (! desc.empty()) {
           for ( unsigned int l = 0; l < desc.size(); l++) {
-            
-            // There may be more than one translation line.
-            
             string t = desc[l]->getStringValue();
-            SGPropertyNode *n = locale->getNode("strings");
-            vector<SGPropertyNode_ptr>trans_desc =
-            n->getChildren(t.substr(8).c_str());
-            
+
+            // There may be more than one translation line.
+            vector<SGPropertyNode_ptr>trans_desc = locale->getLocalizedStrings(t.c_str(),"options");
             for ( unsigned int m = 0; m < trans_desc.size(); m++ ) {
               string t_str = trans_desc[m]->getStringValue();
               
@@ -2167,19 +2321,18 @@ void Options::showUsage() const
       }
     }
     
-    SGPropertyNode *name;
-    name = locale->getNode(section[j]->getStringValue("name"));
-    
+    const char* name = locale->getLocalizedString(section[j]->getStringValue("name"),"options");
     if (!msg.empty() && name) {
-      cout << endl << name->getStringValue() << ":" << endl;
+      cout << endl << name << ":" << endl;
       cout << msg;
       msg.erase();
     }
   }
   
   if ( !p->verbose ) {
-    cout << endl;
-    cout << "For a complete list of options use --help --verbose" << endl;
+    const char* verbose_help = locale->getLocalizedString(options->getStringValue("verbose-help"),"options");
+    if (verbose_help)
+        cout << endl << verbose_help << endl;
   }
 #ifdef _MSC_VER
   std::cout << "Hit a key to continue..." << std::endl;
@@ -2193,33 +2346,13 @@ string Options::platformDefaultRoot() const
   return "../data";
 }
 
-#elif defined(_WIN32)
+#elif defined(SG_WINDOWS)
 string Options::platformDefaultRoot() const
 {
   return "..\\data";
 }
-#elif defined(__APPLE__)
-string Options::platformDefaultRoot() const
-{
-  /*
-   The following code looks for the base package inside the application 
-   bundle, in the standard Contents/Resources location. 
-   */
-  CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
-  
-  // look for a 'data' subdir
-  CFURLRef dataDir = CFURLCreateCopyAppendingPathComponent(NULL, resourcesUrl, CFSTR("data"), true);
-  
-  // now convert down to a path, and the a c-string
-  CFStringRef path = CFURLCopyFileSystemPath(dataDir, kCFURLPOSIXPathStyle);
-  string root = CFStringGetCStringPtr(path, CFStringGetSystemEncoding());
-  
-  CFRelease(resourcesUrl);
-  CFRelease(dataDir);
-  CFRelease(path);
-  
-  return root;
-}
+#elif defined(SG_MAC)
+// platformDefaultRoot defined in CocoaHelpers.mm
 #else
 string Options::platformDefaultRoot() const
 {
@@ -2246,25 +2379,33 @@ void Options::setupRoot()
   globals->set_fg_root(root);
   
 // validate it
-  static char required_version[] = "2.6.0";
+  static char required_version[] = FLIGHTGEAR_VERSION;
   string base_version = fgBasePackageVersion();
-  if ( !(base_version == required_version) ) {
-    // tell the operator how to use this application
+    if (base_version.empty()) {
+        flightgear::fatalMessageBox("Base package not found",
+                                    "Required data files not found, check your installation.",
+                                    "Looking for base-package files at: '" + root + "'");
+
+        exit(-1);
+    }
     
-    SG_LOG( SG_GENERAL, SG_ALERT, "" ); // To popup the console on windows
-    cerr << endl << "Base package check failed:" << endl \
-    << "  Version " << base_version << " found at: " \
-    << globals->get_fg_root() << endl \
-    << "  Version " << required_version << " is required." << endl \
-    << "Please upgrade/downgrade base package and set the path to your fgdata" << endl \
-    << "with --fg-root=path_to_your_fgdata" << endl;
-#ifdef _MSC_VER
-    cerr << "Hit a key to continue..." << endl;
-    cin.get();
-#endif
+ if (base_version != required_version) {
+    // tell the operator how to use this application
+   
+      flightgear::fatalMessageBox("Base package version mismatch",
+                                  "Version check failed: please check your installation.",
+                                  "Found data files for version '" + base_version +
+                                  "' at '" + globals->get_fg_root() + "', version '"
+                                  + required_version + "' is required.");
+
     exit(-1);
   }
 }
   
+bool Options::shouldLoadDefaultConfig() const
+{
+  return p->shouldLoadDefaultConfig;
+}
+  
 } // of namespace flightgear