]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/options.cxx
Interim windows build fix
[flightgear.git] / src / Main / options.cxx
index ee3b3aafaf1367676b4b355bb33eb63dc32ef636..c0a955379b7b70cf72af4a5a9edf43bfa0a47382 100644 (file)
@@ -231,7 +231,12 @@ void fgSetDefaults ()
     v->setValueReadOnly("build-number", HUDSON_BUILD_NUMBER);
     v->setValueReadOnly("build-id", HUDSON_BUILD_ID);
     v->setValueReadOnly("hla-support", bool(FG_HAVE_HLA));
-
+#if defined(FG_NIGHTLY)
+    v->setValueReadOnly("nightly-build", true);
+#else
+    v->setValueReadOnly("nightly-build", false);
+#endif
+    
     char* envp = ::getenv( "http_proxy" );
     if( envp != NULL )
       fgSetupProxy( envp );
@@ -251,9 +256,11 @@ public:
     }
     
     
-    void show(const SGPath& path)
+    void show(const vector<SGPath> & path_list)
     {
-        visitDir(path, 0);
+               for (vector<SGPath>::const_iterator p = path_list.begin();
+                        p != path_list.end(); ++p)
+                       visitDir(*p, 0);
         
         simgear::requestConsole(); // ensure console is shown on Windows
         
@@ -348,10 +355,10 @@ private:
  *
  * @parampath the directory to search for configuration files
  */
-void fgShowAircraft(const SGPath &path)
+void fgShowAircraft(const vector<SGPath> &path_list)
 {
     ShowAircraft s;
-    s.show(path);
+    s.show(path_list);
     
 #ifdef _MSC_VER
     cout << "Hit a key to continue..." << endl;
@@ -844,7 +851,7 @@ fgOptRoc( const char *arg )
 static int
 fgOptFgScenery( const char *arg )
 {
-    globals->append_fg_scenery(arg);
+    globals->append_fg_scenery(arg, true);
     return FG_OPTIONS_OK;
 }
 
@@ -1321,6 +1328,7 @@ fgOptVersion( const char *arg )
     }
     cerr << endl;
     cerr << "SimGear version: " << SG_STRINGIZE(SIMGEAR_VERSION) << endl;
+    cerr << "OSG version: " << osgGetVersion() << endl;
     cerr << "PLIB version: " << PLIB_VERSION << endl;
     return FG_OPTIONS_EXIT;
 }
@@ -1355,6 +1363,22 @@ fgOptIgnoreAutosave(const char* arg)
     return FG_OPTIONS_OK;
 }
 
+static int
+fgOptEnableFreeze(const char* arg)
+{
+    fgSetBool("/sim/freeze/master", true);
+    fgSetBool("/sim/freeze/clock", true);
+    return FG_OPTIONS_OK;
+}
+
+static int
+fgOptDisableFreeze(const char* arg)
+{
+    fgSetBool("/sim/freeze/master", false);
+    fgSetBool("/sim/freeze/clock", 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".
 // Examples:  --prop:alpha=1  --prop:bool:beta=true  --prop:d:gamma=0.123
@@ -1417,7 +1441,7 @@ fgOptLoadTape(const char* arg)
 
     virtual ~ DelayedTapeLoader() {}
 
-    virtual void valueChanged(SGPropertyNode * node) 
+    virtual void valueChanged(SGPropertyNode * node)
     {
       node->removeChangeListener( this );
 
@@ -1504,8 +1528,8 @@ struct OptionDesc {
     {"enable-ai-models",             false, OPTION_BOOL,   "/sim/ai/enabled", true, "", 0 },
     {"disable-ai-traffic",           false, OPTION_BOOL,   "/sim/traffic-manager/enabled", false, "", 0 },
     {"enable-ai-traffic",            false, OPTION_BOOL,   "/sim/traffic-manager/enabled", true,  "", 0 },
-    {"disable-freeze",               false, OPTION_BOOL,   "/sim/freeze/master", false, "", 0 },
-    {"enable-freeze",                false, OPTION_BOOL,   "/sim/freeze/master", true, "", 0 },
+    {"disable-freeze",               false, OPTION_FUNC,   "", false, "", fgOptDisableFreeze },
+    {"enable-freeze",                false, OPTION_FUNC,   "", true, "", fgOptEnableFreeze },
     {"disable-fuel-freeze",          false, OPTION_BOOL,   "/sim/freeze/fuel", false, "", 0 },
     {"enable-fuel-freeze",           false, OPTION_BOOL,   "/sim/freeze/fuel", true, "", 0 },
     {"disable-clock-freeze",         false, OPTION_BOOL,   "/sim/freeze/clock", false, "", 0 },
@@ -1597,6 +1621,7 @@ struct OptionDesc {
     {"disable-terrasync",            false, OPTION_BOOL,   "/sim/terrasync/enabled", false, "", 0 },
     {"enable-terrasync",             false, OPTION_BOOL,   "/sim/terrasync/enabled", true, "", 0 },
     {"terrasync-dir",                true,  OPTION_STRING, "/sim/terrasync/scenery-dir", false, "", 0 },
+    {"download-dir",                 true,  OPTION_STRING, "/sim/paths/download-dir", false, "", 0 },
     {"geometry",                     true,  OPTION_FUNC,   "", false, "", fgOptGeometry },
     {"bpp",                          true,  OPTION_FUNC,   "", false, "", fgOptBpp },
     {"units-feet",                   false, OPTION_STRING, "/sim/startup/units", false, "feet", 0 },
@@ -1820,7 +1845,7 @@ public:
   }
   
   /**
-   * given a current iterator into the values, find the preceeding group marker,
+   * given a current iterator into the values, find the preceding group marker,
    * or return the beginning of the value vector.
    */
   OptionValueVec::const_iterator rfindGroup(OptionValueVec::const_iterator pos) const
@@ -1994,16 +2019,37 @@ void Options::initAircraft()
   }
     
   if (p->showAircraft) {
+       vector<SGPath> path_list;
+
     fgOptLogLevel( "alert" );
-    SGPath path( globals->get_fg_root() );
-    path.append("Aircraft");
-    fgShowAircraft(path);
+
+    // First place to check is the 'Aircraft' sub-directory in $FG_ROOT
+
+       path_list.push_back( SGPath( globals->get_fg_root() ) );
+       path_list.back().append("Aircraft");
+
+    // Additionally, aircraft may also be found in user-defined places
+       // (via $FG_AIRCRAFT or with the '--fg-aircraft' option)
+
+       string_list aircraft_paths = globals->get_aircraft_paths();
+       for (string_list::iterator it = aircraft_paths.begin();
+                it != aircraft_paths.end(); ++it)
+         path_list.push_back( SGPath(*it));
+
+    fgShowAircraft(path_list);
     exit(0);
   }
   
   if (isOptionSet("aircraft-dir")) {
-    // set this now, so it's available in FindAndCacheAircraft
-    fgSetString("/sim/aircraft-dir", valueForOption("aircraft-dir"));
+    SGPath aircraftDirPath(valueForOption("aircraft-dir"));
+
+    // Set this now, so it's available in FindAndCacheAircraft. Use realpath()
+    // as in FGGlobals::append_aircraft_path(), otherwise fgValidatePath()
+    // will deny access to resources under this path if one of its components
+    // is a symlink (which is not a problem, since it was given as is by the
+    // user---this is very different from a symlink *under* the aircraft dir
+    // or a scenery dir).
+    fgSetString("/sim/aircraft-dir", aircraftDirPath.realpath().c_str());
   }
 }
   
@@ -2170,20 +2216,17 @@ string_list Options::valuesForOption(const std::string& key) const
   return result;
 }
 
-
-static string defaultTerrasyncDir()
+string defaultDownloadDir()
 {
 #if defined(SG_WINDOWS)
-       SGPath p(SGPath::documents());
-       p.append("FlightGear");
+    SGPath p(SGPath::documents());
+    p.append("FlightGear");
 #else
     SGPath p(globals->get_fg_home());
 #endif
-       p.append("TerraSync");
-       return p.str();
+    return p.str();
 }
 
-
 OptionResult Options::processOptions()
 {
   // establish locale before showing help (this selects the default locale,
@@ -2236,60 +2279,60 @@ OptionResult Options::processOptions()
 // now options are process, do supplemental fixup
   const char *envp = ::getenv( "FG_SCENERY" );
   if (envp) {
-    globals->append_fg_scenery(envp);
+    globals->append_fg_scenery(envp, true);
   }
-    
+
+// download dir fix-up
+    string downloadDir = simgear::strutils::strip(fgGetString("/sim/paths/download-dir"));
+    if (downloadDir.empty()) {
+        downloadDir = defaultDownloadDir();
+        SG_LOG(SG_GENERAL, SG_INFO, "Using default download dir: " << downloadDir);
+    } else {
+        simgear::Dir d(downloadDir);
+        if (!d.exists()) {
+            SG_LOG(SG_GENERAL, SG_INFO, "Creating requested download dir: " << downloadDir);
+            d.create(0755);
+        }
+    }
+
 // terrasync directory fixup
     string terrasyncDir = simgear::strutils::strip(fgGetString("/sim/terrasync/scenery-dir"));
   if (terrasyncDir.empty()) {
-         terrasyncDir = defaultTerrasyncDir();
-         // auto-save it for next time
-         
-         SG_LOG(SG_GENERAL, SG_INFO,
-                 "Using default TerraSync: " << terrasyncDir);
-      fgSetString("/sim/terrasync/scenery-dir", terrasyncDir);
-  }
+      SGPath p(downloadDir);
+      p.append("TerraSync");
+      terrasyncDir = p.str();
 
-  SGPath p(terrasyncDir);
+      simgear::Dir d(terrasyncDir);
+      if (!d.exists()) {
+          d.create(0755);
+      }
 
-  // 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);
+         SG_LOG(SG_GENERAL, SG_INFO, "Using default TerraSync: " << terrasyncDir);
+      fgSetString("/sim/terrasync/scenery-dir", p.str());
+  } else {
+      SG_LOG(SG_GENERAL, SG_INFO, "Using explicit TerraSync dir: " << terrasyncDir);
   }
 
-    // check the above actuall worked
-    if (!objectsDir.exists() || !terrainDir.exists()) {
-        std::stringstream ss;
-        ss << "Scenery download will be disabled. The configured location is '" << terrasyncDir << "'.";
-        flightgear::modalMessageBox("Invalid scenery download location",
-                                    "Automatic scenery download is configured to use a location (path) which invalid.",
-                                    ss.str());
-        fgSetBool("/sim/terrasync/enabled", false);
-    }
+    // check if we setup a scenery path so far
+    bool addFGDataScenery = globals->get_fg_scenery().empty();
 
-  if (fgGetBool("/sim/terrasync/enabled")) {
+    // always add the terrasync location, regardless of whether terrasync
+    // is enabled or not. This allows us to toggle terrasync on/off at
+    // runtime and have things work as expected
     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
-      globals->append_fg_scenery(terrasyncDir);
+        // terrasync dir is not in the scenery paths, add it
+        globals->append_fg_scenery(terrasyncDir);
     }
-  }
-  
-  if (globals->get_fg_scenery().empty()) {
-    // no scenery paths set *at all*, use the data in FG_ROOT
-    SGPath root(globals->get_fg_root());
-    root.append("Scenery");
-    globals->append_fg_scenery(root.str());
-  }
-    
+
+    if (addFGDataScenery) {
+        // no scenery paths set at all, use the data in FG_ROOT
+        // ensure this path is added last
+        SGPath root(globals->get_fg_root());
+        root.append("Scenery");
+        globals->append_fg_scenery(root.str());
+    }
+
   return FG_OPTIONS_OK;
 }
   
@@ -2470,7 +2513,7 @@ void Options::setupRoot(int argc, char **argv)
 
 #if defined(HAVE_QT)
     if (base_version != required_version) {
-        QtLauncher::initApp(argc, argv);
+        flightgear::initApp(argc, argv);
         if (SetupRootDialog::restoreUserSelectedRoot()) {
             SG_LOG(SG_GENERAL, SG_INFO, "restored user selected fg_root = " << globals->get_fg_root() );
             return;