X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInput%2FFGDeviceConfigurationMap.cxx;h=b4b6b1baf24d278812efb5990cc3df4e7f0f8bce;hb=f6207d5cb8eeb2ed83e1873dd2f621785832a3f3;hp=5ad2a0bd7435f3786c0049777386bcce6ed52e91;hpb=3872fce78202fc89ffba5f79f2f11bec36d91e7f;p=flightgear.git diff --git a/src/Input/FGDeviceConfigurationMap.cxx b/src/Input/FGDeviceConfigurationMap.cxx index 5ad2a0bd7..b4b6b1baf 100644 --- a/src/Input/FGDeviceConfigurationMap.cxx +++ b/src/Input/FGDeviceConfigurationMap.cxx @@ -26,12 +26,9 @@ # include #endif -#include - #include "FGDeviceConfigurationMap.hxx" -#include - +#include #include #include
@@ -41,11 +38,9 @@ FGDeviceConfigurationMap::FGDeviceConfigurationMap( const char * relative_path, 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_home(), relative_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--) { @@ -59,29 +54,28 @@ FGDeviceConfigurationMap::FGDeviceConfigurationMap( const char * relative_path, FGDeviceConfigurationMap::~FGDeviceConfigurationMap() { - base->removeChildren( childname ); + // Ensure that the children don't hang around when deleted, as if + // re-created, we need to ensure that the set of names doesn't contain + // any unexpected history. + base->removeChildren( childname, false ); } -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; cgetChild(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()); } }