Convert nasal directory() helper to use simgear::Dir
This commit is contained in:
parent
7ccba95b9c
commit
db4b84bc5c
1 changed files with 18 additions and 21 deletions
|
@ -14,12 +14,11 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <plib/ul.h>
|
|
||||||
|
|
||||||
#include <simgear/nasal/nasal.h>
|
#include <simgear/nasal/nasal.h>
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/math/sg_random.h>
|
#include <simgear/math/sg_random.h>
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
|
#include <simgear/misc/sg_dir.hxx>
|
||||||
#include <simgear/misc/interpolator.hxx>
|
#include <simgear/misc/interpolator.hxx>
|
||||||
#include <simgear/scene/material/mat.hxx>
|
#include <simgear/scene/material/mat.hxx>
|
||||||
#include <simgear/structure/commands.hxx>
|
#include <simgear/structure/commands.hxx>
|
||||||
|
@ -364,15 +363,17 @@ static naRef f_directory(naContext c, naRef me, int argc, naRef* args)
|
||||||
{
|
{
|
||||||
if(argc != 1 || !naIsString(args[0]))
|
if(argc != 1 || !naIsString(args[0]))
|
||||||
naRuntimeError(c, "bad arguments to directory()");
|
naRuntimeError(c, "bad arguments to directory()");
|
||||||
naRef ldir = args[0];
|
|
||||||
ulDir* dir = ulOpenDir(naStr_data(args[0]));
|
simgear::Dir d(SGPath(naStr_data(args[0])));
|
||||||
if(!dir) return naNil();
|
if(!d.exists()) return naNil();
|
||||||
naRef result = naNewVector(c);
|
naRef result = naNewVector(c);
|
||||||
ulDirEnt* dent;
|
|
||||||
while((dent = ulReadDir(dir)))
|
simgear::PathList paths = d.children(simgear::Dir::TYPE_FILE | simgear::Dir::TYPE_DIR);
|
||||||
naVec_append(result, naStr_fromdata(naNewString(c), dent->d_name,
|
for (unsigned int i=0; i<paths.size(); ++i) {
|
||||||
strlen(dent->d_name)));
|
std::string p = paths[i].file();
|
||||||
ulCloseDir(dir);
|
naVec_append(result, naStr_fromdata(naNewString(c), p.c_str(), p.size()));
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -722,18 +723,14 @@ void FGNasalSys::init()
|
||||||
hashset(_globals, "__gcsave", _gcHash);
|
hashset(_globals, "__gcsave", _gcHash);
|
||||||
|
|
||||||
// Now load the various source files in the Nasal directory
|
// Now load the various source files in the Nasal directory
|
||||||
SGPath p(globals->get_fg_root());
|
simgear::Dir nasalDir(SGPath(globals->get_fg_root(), "Nasal"));
|
||||||
p.append("Nasal");
|
simgear::PathList scripts = nasalDir.children(simgear::Dir::TYPE_FILE, ".nas");
|
||||||
ulDirEnt* dent;
|
|
||||||
ulDir* dir = ulOpenDir(p.c_str());
|
for (unsigned int i=0; i<scripts.size(); ++i) {
|
||||||
while(dir && (dent = ulReadDir(dir)) != 0) {
|
SGPath fullpath(scripts[i]);
|
||||||
SGPath fullpath(p);
|
SGPath file = fullpath.file();
|
||||||
fullpath.append(dent->d_name);
|
loadModule(fullpath, file.base().c_str());
|
||||||
SGPath file(dent->d_name);
|
|
||||||
if(file.extension() != "nas") continue;
|
|
||||||
loadModule(fullpath, file.base().c_str());
|
|
||||||
}
|
}
|
||||||
ulCloseDir(dir);
|
|
||||||
|
|
||||||
// set signal and remove node to avoid restoring at reinit
|
// set signal and remove node to avoid restoring at reinit
|
||||||
const char *s = "nasal-dir-initialized";
|
const char *s = "nasal-dir-initialized";
|
||||||
|
|
Loading…
Add table
Reference in a new issue