X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAirports%2Fxmlloader.cxx;h=8b35cabd5b03bab346f5df79fd9f2ec9f8a83219;hb=72131a4a4971df690ec5004977ee8eca1d0aa114;hp=205defa8207c2d9fb68c96a67aad9139d5ad7dd1;hpb=4238a46faa8fc8e9ac9174fe960eb7c5df188a4c;p=flightgear.git diff --git a/src/Airports/xmlloader.cxx b/src/Airports/xmlloader.cxx index 205defa82..8b35cabd5 100644 --- a/src/Airports/xmlloader.cxx +++ b/src/Airports/xmlloader.cxx @@ -13,53 +13,83 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include +#include +#include + #include
+#include
#include "xmlloader.hxx" #include "dynamicloader.hxx" #include "runwayprefloader.hxx" #include "dynamics.hxx" +#include "simple.hxx" #include "runwayprefs.hxx" +using std::string; + XMLLoader::XMLLoader() {} XMLLoader::~XMLLoader() {} -void XMLLoader::load(FGAirportDynamics* d) { +void XMLLoader::load(FGAirportDynamics* d) +{ FGAirportDynamicsXMLLoader visitor(d); - - SGPath parkpath( globals->get_fg_root() ); - parkpath.append( "/AI/Airports/" ); - parkpath.append( d->getId() ); - parkpath.append( "parking.xml" ); - - if (parkpath.exists()) { - try { - readXML(parkpath.str(), visitor); - d->init(); - } catch (const sg_exception &e) { - //cerr << "unable to read " << parkpath.str() << endl; - } + if(loadAirportXMLDataIntoVisitor(d->parent()->ident(), "groundnet", visitor)) { + d->init(); } - } void XMLLoader::load(FGRunwayPreference* p) { FGRunwayPreferenceXMLLoader visitor(p); + loadAirportXMLDataIntoVisitor(p->getId(), "rwyuse", visitor); +} - SGPath rwyPrefPath( globals->get_fg_root() ); - rwyPrefPath.append( "AI/Airports/" ); - rwyPrefPath.append( p->getId() ); - rwyPrefPath.append( "rwyuse.xml" ); +bool XMLLoader::findAirportData(const std::string& aICAO, + const std::string& aFileName, SGPath& aPath) +{ + string fileName(aFileName); + if (!simgear::strutils::ends_with(aFileName, ".xml")) { + fileName.append(".xml"); + } + + string_list sc = globals->get_fg_scenery(); + char buffer[128]; + ::snprintf(buffer, 128, "%c/%c/%c/%s.%s", + aICAO[0], aICAO[1], aICAO[2], + aICAO.c_str(), fileName.c_str()); - //if (ai_dirs.find(id.c_str()) != ai_dirs.end() - // && rwyPrefPath.exists()) - if (rwyPrefPath.exists()) { - try { - readXML(rwyPrefPath.str(), visitor); - } catch (const sg_exception &e) { - //cerr << "unable to read " << rwyPrefPath.str() << endl; + for (string_list_iterator it = sc.begin(); it != sc.end(); ++it) { + // fg_senery contains empty strings as "markers" (see FGGlobals::set_fg_scenery) + if (!it->empty()) { + SGPath path(*it); + path.append("Airports"); + path.append(string(buffer)); + if (path.exists()) { + aPath = path; + return true; + } // of path exists } + } // of scenery path iteration + return false; +} + +bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO, + const string& aFileName, XMLVisitor& aVisitor) +{ + SGPath path; + if (!findAirportData(aICAO, aFileName, path)) { + SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName); + return false; } + + SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: loading from " << path.str()); + readXML(path.str(), aVisitor); + return true; } +