]> git.mxchange.org Git - flightgear.git/commitdiff
First attempt at support for loading airport XML files via a command
authorJames Turner <zakalawe@mac.com>
Tue, 24 May 2011 23:03:51 +0000 (00:03 +0100)
committerJames Turner <zakalawe@mac.com>
Tue, 24 May 2011 23:03:51 +0000 (00:03 +0100)
src/Airports/xmlloader.cxx
src/Main/fg_commands.cxx
src/Main/globals.cxx

index 9487144c99817ed42361776b9d4c495d19c368c7..b5bce6345883194ddcdf7fb69d3e73979661991a 100644 (file)
@@ -84,11 +84,17 @@ void XMLLoader::load(FGSidStar* p) {
 bool XMLLoader::findAirportData(const std::string& aICAO, 
     const std::string& aFileName, SGPath& aPath)
 {
+  string fileName(aFileName);
+  int extPos = fileName.size() - 4;
+  if ((int) fileName.rfind(".xml") != extPos) {
+    fileName.append(".xml");
+  }
+  
   string_list sc = globals->get_fg_scenery();
   char buffer[128];
-  ::snprintf(buffer, 128, "%c/%c/%c/%s.%s.xml", 
+  ::snprintf(buffer, 128, "%c/%c/%c/%s.%s", 
     aICAO[0], aICAO[1], aICAO[2], 
-    aICAO.c_str(), aFileName.c_str());
+    aICAO.c_str(), fileName.c_str());
 
   for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) {
     SGPath path(*it);
index 6baed83154f5f3b4ec2605ceeb94429e72545fbd..607c11c88aa97e04c1bd90eaa67eddf39224fa94 100644 (file)
@@ -34,6 +34,7 @@
 #include <Scripting/NasalSys.hxx>
 #include <Sound/sample_queue.hxx>
 #include <Time/sunsolver.hxx>
+#include <Airports/xmlloader.hxx>
 
 #include "fg_init.hxx"
 #include "fg_io.hxx"
@@ -1301,11 +1302,20 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
 
     if (file.extension() != "xml")
         file.concat(".xml");
-
-    if (file.isRelative()) {
-      file = globals->resolve_maybe_aircraft_path(file.str());
+    
+    std::string icao = arg->getStringValue("icao");
+    if (icao.empty()) {
+        if (file.isRelative()) {
+          file = globals->resolve_maybe_aircraft_path(file.str());
+        }
+    } else {
+        if (!XMLLoader::findAirportData(icao, file.str(), file)) {
+          SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for "
+            << file.str() << " at ICAO:" << icao);
+          return false;
+        }
     }
-
+    
     if (!fgValidatePath(file.c_str(), false)) {
         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
                 "(unauthorized access)");
index af4e693459bce2da14c45ce1e1ebd9342388142d..b7d9b7d6d9a2eabf0691029ed48a12de7582591d 100644 (file)
@@ -241,7 +241,8 @@ void FGGlobals::set_fg_scenery (const string &scenery)
 
     string_list path_list = sgPathSplit( s.str() );
     fg_scenery.clear();
-
+    SGPropertyNode* sim = fgGetNode("/sim", true);
+    
     for (unsigned i = 0; i < path_list.size(); i++) {
         SGPath path(path_list[i]);
         if (!path.exists()) {
@@ -271,6 +272,12 @@ void FGGlobals::set_fg_scenery (const string &scenery)
         // FG_SCENERY=A:B becomes list ["A/Terrain", "A/Objects", "",
         // "B/Terrain", "B/Objects", ""]
         fg_scenery.push_back("");
+        
+      // make scenery dirs available to Nasal
+        sim->removeChild("fg-scenery", i, false);
+        SGPropertyNode* n = sim->getChild("fg-scenery", i, true);
+        n->setStringValue(path.str());
+        n->setAttribute(SGPropertyNode::WRITE, false);
     } // of path list iteration
 }