#include <simgear/compiler.h>
-#include <plib/ul.h>
-
#include <Environment/environment_mgr.hxx>
#include <Environment/environment.hxx>
#include <simgear/misc/sg_path.hxx>
#include <iostream>
#include <cstring>
#include <sys/types.h>
-#include <plib/ul.h>
#include <plib/pu.h>
-#include <plib/ul.h>
#include <simgear/compiler.h>
#include <simgear/structure/exception.hxx>
#include <simgear/props/props_io.hxx>
+#include <simgear/misc/sg_dir.hxx>
#include <boost/algorithm/string/case_conv.hpp>
NewGUI::init ()
{
setStyle();
- char path1[1024];
- char path2[1024];
- ulMakePath(path1, globals->get_fg_root().c_str(), "gui");
- ulMakePath(path2, path1, "dialogs");
- readDir(path2);
+ SGPath p(globals->get_fg_root(), "gui/dialogs");
+ readDir(p);
_menubar->init();
}
_menubar->hide();
}
-static bool
-test_extension (const char * path, const char * ext)
-{
- int pathlen = strlen(path);
- int extlen = strlen(ext);
-
- for (int i = 1; i <= pathlen && i <= extlen; i++) {
- if (path[pathlen-i] != ext[extlen-i])
- return false;
- }
- return true;
-}
-
void
NewGUI::newDialog (SGPropertyNode* props)
{
}
void
-NewGUI::readDir (const char * path)
+NewGUI::readDir (const SGPath& path)
{
- ulDir * dir = ulOpenDir(path);
-
- if (dir == 0) {
- SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
- << path);
- return;
- }
-
- for (ulDirEnt * dirEnt = ulReadDir(dir);
- dirEnt != 0;
- dirEnt = ulReadDir(dir)) {
-
- char subpath[1024];
-
- ulMakePath(subpath, path, dirEnt->d_name);
-
- if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) {
- SGPropertyNode * props = new SGPropertyNode;
- try {
- readProperties(subpath, props);
- } catch (const sg_exception &) {
- SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
- << subpath);
- delete props;
- continue;
- }
- SGPropertyNode *nameprop = props->getNode("name");
- if (!nameprop) {
- SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
- << " has no name; skipping.");
- delete props;
- continue;
- }
- string name = nameprop->getStringValue();
- if (_dialog_props[name])
- delete (SGPropertyNode *)_dialog_props[name];
-
- _dialog_props[name] = props;
- }
+ simgear::Dir dir(path);
+ simgear::PathList xmls = dir.children(simgear::Dir::TYPE_FILE, ".xml");
+
+ for (unsigned int i=0; i<xmls.size(); ++i) {
+ SGPropertyNode * props = new SGPropertyNode;
+ try {
+ readProperties(xmls[i].str(), props);
+ } catch (const sg_exception &) {
+ SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
+ << xmls[i].str());
+ delete props;
+ continue;
+ }
+ SGPropertyNode *nameprop = props->getNode("name");
+ if (!nameprop) {
+ SG_LOG(SG_INPUT, SG_WARN, "dialog " << xmls[i].str()
+ << " has no name; skipping.");
+ delete props;
+ continue;
+ }
+ string name = nameprop->getStringValue();
+ if (_dialog_props[name])
+ delete (SGPropertyNode *)_dialog_props[name];
+
+ _dialog_props[name] = props;
}
- ulCloseDir(dir);
}
void clear_colors();
// Read all the configuration files in a directory.
- void readDir (const char * path);
+ void readDir (const SGPath& path);
FGMenuBar * _menubar;
FGDialog * _active_dialog;
#include <vector>
#include <simgear/structure/SGBinding.hxx>
-#include <plib/ul.h>
#if defined( UL_WIN32 )
#define TGT_PLATFORM "windows"
#include "FGDeviceConfigurationMap.hxx"
-#include <plib/ul.h>
-
+#include <simgear/misc/sg_dir.hxx>
#include <simgear/props/props_io.hxx>
#include <Main/globals.hxx>
base(aBase),
childname(aChildname)
{
- SGPath path(globals->get_fg_root());
- path.append( relative_path );
-
int index = 1000;
- scan_dir( path, &index);
+ scan_dir( SGPath(globals->get_fg_root(), relative_path), &index);
PropertyList childNodes = base->getChildren(childname);
for (int k = (int)childNodes.size() - 1; k >= 0; k--) {
base->removeChildren( childname );
}
-void FGDeviceConfigurationMap::scan_dir( SGPath & path, int *index)
+void FGDeviceConfigurationMap::scan_dir(const SGPath & path, int *index)
{
- ulDir *dir = ulOpenDir(path.c_str());
- if (dir) {
- ulDirEnt* dent;
- while ((dent = ulReadDir(dir)) != 0) {
- if (dent->d_name[0] == '.')
- continue;
+ simgear::Dir dir(path);
+ simgear::PathList children = dir.children(simgear::Dir::TYPE_FILE |
+ simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT);
- SGPath p(path.str());
- p.append(dent->d_name);
- scan_dir(p, index);
+ for (unsigned int c=0; c<children.size(); ++c) {
+ SGPath path(children[c]);
+ if (path.isDir()) {
+ scan_dir(path, index);
+ } else if (path.extension() == "xml") {
+ SG_LOG(SG_INPUT, SG_DEBUG, "Reading joystick file " << path.str());
+ SGPropertyNode_ptr n = base->getChild(childname, (*index)++, true);
+ readProperties(path.str(), n);
+ n->setStringValue("source", path.c_str());
}
- ulCloseDir(dir);
-
- } else if (path.extension() == "xml") {
- SG_LOG(SG_INPUT, SG_DEBUG, "Reading joystick file " << path.str());
- SGPropertyNode_ptr n = base->getChild(childname, (*index)++, true);
- readProperties(path.str(), n);
- n->setStringValue("source", path.c_str());
}
}
#endif
#include <simgear/props/props.hxx>
-#include <simgear/misc/sg_path.hxx>
#include <map>
+class SGPath;
+
class FGDeviceConfigurationMap : public std::map<std::string,SGPropertyNode_ptr> {
public:
FGDeviceConfigurationMap ( const char * relative_path, SGPropertyNode_ptr base, const char * childname );
virtual ~FGDeviceConfigurationMap();
private:
- void scan_dir( SGPath & path, int *index);
+ void scan_dir(const SGPath & path, int *index);
SGPropertyNode_ptr base;
const char * childname;
};
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <errno.h>
+
#include <stdio.h> //snprintf
#ifdef _WIN32
# include <io.h> //lseek, read, write
#include <string>
-#include <plib/ul.h>
-
#include <simgear/debug/logstream.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/io/iochannel.hxx>
#include <vector>
#include <algorithm>
-#include <plib/ul.h>
-
#include <simgear/compiler.h>
#include <simgear/misc/sg_path.hxx>
+#include <simgear/misc/sg_dir.hxx>
#include <simgear/props/props.hxx>
#include <simgear/route/waypoint.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
void FGTrafficManager::init()
{
- ulDir *d, *d2;
- ulDirEnt *dent, *dent2;
-
heuristicsVector heuristics;
HeuristicMap heurMap;
if (string(fgGetString("/sim/traffic-manager/datafile")) == string("")) {
- SGPath aircraftDir = globals->get_fg_root();
- SGPath path = aircraftDir;
-
- aircraftDir.append("AI/Traffic");
- if ((d = ulOpenDir(aircraftDir.c_str())) != NULL) {
- while ((dent = ulReadDir(d)) != NULL) {
- if (string(dent->d_name) != string(".") &&
- string(dent->d_name) != string("..") && dent->d_isdir) {
- SGPath currACDir = aircraftDir;
- currACDir.append(dent->d_name);
- if ((d2 = ulOpenDir(currACDir.c_str())) == NULL)
- return;
- while ((dent2 = ulReadDir(d2)) != NULL) {
- SGPath currFile = currACDir;
- currFile.append(dent2->d_name);
- if (currFile.extension() == string("xml")) {
- SGPath currFile = currACDir;
- currFile.append(dent2->d_name);
- SG_LOG(SG_GENERAL, SG_DEBUG,
- "Scanning " << currFile.
- str() << " for traffic");
- readXML(currFile.str(), *this);
- }
- }
- ulCloseDir(d2);
- }
- }
- ulCloseDir(d);
+ simgear::Dir trafficDir(SGPath(globals->get_fg_root(), "AI/Traffic"));
+ simgear::PathList d = trafficDir.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT);
+
+ for (unsigned int i=0; i<d.size(); ++i) {
+ simgear::Dir d2(d[i]);
+ simgear::PathList trafficFiles = d2.children(simgear::Dir::TYPE_FILE, ".xml");
+ for (unsigned int j=0; j<trafficFiles.size(); ++j) {
+ SGPath curFile = trafficFiles[j];
+ SG_LOG(SG_GENERAL, SG_DEBUG,
+ "Scanning " << curFile.str() << " for traffic");
+ readXML(curFile.str(), *this);
+ }
}
} else {
fgSetBool("/sim/traffic-manager/heuristics", false);