]> git.mxchange.org Git - flightgear.git/commitdiff
Convert scenery path setup to use simgear::Dir
authorJames Turner <jmt@Dulux.local>
Mon, 5 Jul 2010 07:31:09 +0000 (08:31 +0100)
committerJames Turner <zakalawe@mac.com>
Sat, 17 Jul 2010 13:12:52 +0000 (14:12 +0100)
src/Main/globals.cxx
src/Main/options.cxx

index 1ae7c81d22fbb110104ff988720a128e5a32f72d..ad38089194f6af50d08de6be8c83532d445c3048 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <simgear/structure/commands.hxx>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/misc/sg_dir.hxx>
 #include <simgear/timing/sg_time.hxx>
 #include <simgear/ephemeris/ephemeris.hxx>
 #include <simgear/magvar/magvar.hxx>
@@ -189,7 +190,8 @@ void FGGlobals::set_fg_root (const string &root) {
     n->setAttribute(SGPropertyNode::WRITE, false);
 }
 
-void FGGlobals::set_fg_scenery (const string &scenery) {
+void FGGlobals::set_fg_scenery (const string &scenery)
+{
     SGPath s;
     if (scenery.empty()) {
         s.set( fg_root );
@@ -201,38 +203,35 @@ void FGGlobals::set_fg_scenery (const string &scenery) {
     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 );
-            }
-        //}
+        SGPath path(path_list[i]);
+        if (!path.exists()) {
+          SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << path.str());
+          continue;
+        }
+
+        simgear::Dir dir(path);
+        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(path.str());
+        
+        if (terrainDir.exists()) {
+          fg_scenery.push_back(terrainDir.str());
+        }
+        
+        if (objectsDir.exists()) {
+          fg_scenery.push_back(objectsDir.str());
+        }
+        
         // insert a marker for FGTileEntry::load(), so that
         // FG_SCENERY=A:B becomes list ["A/Terrain", "A/Objects", "",
         // "B/Terrain", "B/Objects", ""]
         fg_scenery.push_back("");
-    }
+    } // of path list iteration
 }
 
 
index 388a9c9b053dc87c08b569b31a0aabd8a0ad6488..d3b282be8afd774e71f651069dd0efd1f8519186 100644 (file)
 #include <iostream>
 #include <string>
 
-#include <plib/ul.h>
-
 #include <simgear/math/sg_random.h>
 #include <simgear/props/props_io.hxx>
 #include <simgear/misc/sgstream.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/scene/material/mat.hxx>
 #include <simgear/sound/soundmgr_openal.hxx>
-
-// #include <Include/general.hxx>
-// #include <Airports/simple.hxx>
-// #include <Cockpit/cockpit.hxx>
-// #include <FDM/flight.hxx>
-
 #include <Autopilot/route_mgr.hxx>
 #include <GUI/gui.h>