diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index d95acd6ef..445c76d36 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -402,7 +402,7 @@ void FGGlobals::append_fg_scenery (const SGPath &path) return; } - // tell the ResouceManager about the scenery path + // tell the ResourceManager about the scenery path // needed to load Models from this scenery path simgear::ResourceManager::instance()->addBasePath(abspath, simgear::ResourceManager::PRIORITY_DEFAULT); @@ -416,6 +416,35 @@ void FGGlobals::append_fg_scenery (const SGPath &path) // temporary fix so these values survive reset n->setAttribute(SGPropertyNode::PRESERVE, true); + + // Add any sources.xml file to the property tree so we can provide attribution through the GUI + SGPath sources = SGPath(abspath); + sources.append("sources.xml"); + SG_LOG(SG_TERRAIN, SG_DEBUG, "Looking for source file " << sources << ". Exists ? " << sources.exists()); + if (sources.exists()) { + // Determine the next free indice under /scenery/sources + SGPropertyNode* sourcesProp = fgGetNode("/scenery/sources", true); + int propIndex = 0; + while (sourcesProp->getChild("directory", propIndex) != NULL) { + ++propIndex; + } + + sourcesProp = sourcesProp->getChild("directory", propIndex++, true); + + // Add a reference to the path itself + sourcesProp->setStringValue("path", abspath.utf8Str()); + + // Now load the sources file into /scenery/sources/source[n] + if(!fgLoadProps(sources.utf8Str(), sourcesProp, false)) + { + SG_LOG(SG_TERRAIN, SG_ALERT, "Unable to load sources file " << sources.utf8Str()); + } + + // Ensure these properties cannot be over-ridden, and preserve them across a reset. + sourcesProp->setAttribute(SGPropertyNode::WRITE, false); + sourcesProp->setAttribute(SGPropertyNode::PRESERVE, true); + } + } void FGGlobals::append_read_allowed_paths(const SGPath &path)