1
0
Fork 0

First attempt at support for loading airport XML files via a command

This commit is contained in:
James Turner 2011-05-25 00:03:51 +01:00
parent 0ec9a9492f
commit c09c0e6941
3 changed files with 30 additions and 7 deletions

View 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);

View 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)");

View 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
}