-void FGGlobals::set_fg_scenery (const string &scenery) {
- SGPath s;
- if (scenery.empty()) {
- s.set( fg_root );
- s.append( "Scenery" );
- } else
- s.set( scenery );
-
- string_list path_list = sgPathSplit( s.str() );
- fg_scenery.clear();
-
- for (unsigned i = 0; i < path_list.size(); i++) {
-
- ulDir *d = ulOpenDir( path_list[i].c_str() );
- if (d == NULL)
- continue;
- ulCloseDir( d );
-
- SGPath pt( path_list[i] ), po( path_list[i] );
- pt.append("Terrain");
- po.append("Objects");
-
- ulDir *td = ulOpenDir( pt.c_str() );
- ulDir *od = ulOpenDir( po.c_str() );
-
- // "Terrain" and "Airports" directory don't exist. add directory as is
- // otherwise, automatically append either Terrain, Objects, or both
- //if (td == NULL && od == NULL)
- fg_scenery.push_back( path_list[i] );
- //else {
- if (td != NULL) {
- fg_scenery.push_back( pt.str() );
- ulCloseDir( td );
- }
- if (od != NULL) {
- fg_scenery.push_back( po.str() );
- ulCloseDir( od );
- }
- //}
+// set the fg_home path
+void FGGlobals::set_fg_home (const std::string &home) {
+ SGPath tmp(home);
+ fg_home = tmp.realpath();
+}
+
+PathList FGGlobals::get_data_paths() const
+{
+ PathList r(additional_data_paths);
+ r.push_back(SGPath(fg_root));
+ return r;
+}
+
+PathList FGGlobals::get_data_paths(const std::string& suffix) const
+{
+ PathList r;
+ BOOST_FOREACH(SGPath p, get_data_paths()) {
+ p.append(suffix);
+ if (p.exists()) {
+ r.push_back(p);
+ }
+ }
+
+ return r;
+}
+
+void FGGlobals::append_data_path(const SGPath& path)
+{
+ if (!path.exists()) {
+ SG_LOG(SG_GENERAL, SG_WARN, "adding non-existant data path:" << path);
+ }
+
+ additional_data_paths.push_back(path);
+}
+
+SGPath FGGlobals::find_data_dir(const std::string& pathSuffix) const
+{
+ BOOST_FOREACH(SGPath p, additional_data_paths) {
+ p.append(pathSuffix);
+ if (p.exists()) {
+ return p;
+ }
+ }
+
+ SGPath rootPath(fg_root);
+ rootPath.append(pathSuffix);
+ if (rootPath.exists()) {
+ return rootPath;
+ }
+
+ SG_LOG(SG_GENERAL, SG_WARN, "dir not found in any data path:" << pathSuffix);
+ return SGPath();
+}
+
+void FGGlobals::append_fg_scenery (const std::string &paths)
+{
+// fg_scenery.clear();
+ SGPropertyNode* sim = fgGetNode("/sim", true);
+
+ // find first unused fg-scenery property in /sim
+ int propIndex = 0;
+ while (sim->getChild("fg-scenery", propIndex) != NULL) {
+ ++propIndex;
+ }
+
+ BOOST_FOREACH(const SGPath& path, sgPathSplit( paths )) {
+ SGPath abspath(path.realpath());
+ if (!abspath.exists()) {
+ SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << abspath.str());
+ continue;
+ }
+
+ // check for duplicates
+ string_list::const_iterator ex = std::find(fg_scenery.begin(), fg_scenery.end(), abspath.str());
+ if (ex != fg_scenery.end()) {
+ SG_LOG(SG_GENERAL, SG_INFO, "skipping duplicate add of scenery path:" << abspath.str());
+ continue;
+ }
+
+ simgear::Dir dir(abspath);
+ SGPath terrainDir(dir.file("Terrain"));
+ SGPath objectsDir(dir.file("Objects"));
+
+ // this code used to add *either* the base dir, OR add the
+ // Terrain and Objects subdirs, but the conditional logic was commented
+ // out, such that all three dirs are added. Unfortunately there's
+ // no information as to why the change was made.
+ fg_scenery.push_back(abspath.str());
+
+ if (terrainDir.exists()) {
+ fg_scenery.push_back(terrainDir.str());
+ }
+
+ if (objectsDir.exists()) {
+ fg_scenery.push_back(objectsDir.str());
+ }
+