forked from 0ad/0ad
buildFileList -> buildDirEntList to emphasize that dirs can be returned. (pt2)
This was SVN commit r4310.
This commit is contained in:
parent
5473187487
commit
c7870cfbb4
@ -27,14 +27,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// state held across multiple BuildFileListCB calls; init by BuildFileList.
|
// state held across multiple BuildDirEntListCB calls; init by BuildDirEntList.
|
||||||
struct BuildFileListState
|
struct BuildDirEntListState
|
||||||
{
|
{
|
||||||
JSContext* cx;
|
JSContext* cx;
|
||||||
JSObject* filename_array;
|
JSObject* filename_array;
|
||||||
int cur_idx;
|
int cur_idx;
|
||||||
|
|
||||||
BuildFileListState(JSContext* cx_)
|
BuildDirEntListState(JSContext* cx_)
|
||||||
: cx(cx_)
|
: cx(cx_)
|
||||||
{
|
{
|
||||||
filename_array = JS_NewArrayObject(cx, 0, NULL);
|
filename_array = JS_NewArrayObject(cx, 0, NULL);
|
||||||
@ -42,16 +42,16 @@ struct BuildFileListState
|
|||||||
cur_idx = 0;
|
cur_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~BuildFileListState()
|
~BuildDirEntListState()
|
||||||
{
|
{
|
||||||
JS_RemoveRoot(cx, &filename_array);
|
JS_RemoveRoot(cx, &filename_array);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// called for each matching directory entry; add its full pathname to array.
|
// called for each matching directory entry; add its full pathname to array.
|
||||||
static void BuildFileListCB(const char* path, const DirEnt* UNUSED(ent), void* context)
|
static void BuildDirEntListCB(const char* path, const DirEnt* UNUSED(ent), void* context)
|
||||||
{
|
{
|
||||||
BuildFileListState* s = (BuildFileListState*)context;
|
BuildDirEntListState* s = (BuildDirEntListState*)context;
|
||||||
|
|
||||||
jsval val = ToJSVal( CStr ( path ) );
|
jsval val = ToJSVal( CStr ( path ) );
|
||||||
// note: <path> is already directory + name!
|
// note: <path> is already directory + name!
|
||||||
@ -63,14 +63,14 @@ static void BuildFileListCB(const char* path, const DirEnt* UNUSED(ent), void* c
|
|||||||
// Return an array of pathname strings, one for each matching entry in the
|
// Return an array of pathname strings, one for each matching entry in the
|
||||||
// specified directory.
|
// specified directory.
|
||||||
//
|
//
|
||||||
// pathnames = buildFileList(start_path [, filter_string [, recursive ] ]);
|
// pathnames = buildDirEntList(start_path [, filter_string [, recursive ] ]);
|
||||||
// directory: VFS path
|
// directory: VFS path
|
||||||
// filter_string: default "" matches everything; otherwise, see vfs_next_dirent.
|
// filter_string: default "" matches everything; otherwise, see vfs_next_dirent.
|
||||||
// recurse: should subdirectories be included in the search? default false.
|
// recurse: should subdirectories be included in the search? default false.
|
||||||
//
|
//
|
||||||
// note: full pathnames of each file/subdirectory are returned,
|
// note: full pathnames of each file/subdirectory are returned,
|
||||||
// ready for use as a "filename" for the other functions.
|
// ready for use as a "filename" for the other functions.
|
||||||
JSBool JSI_VFS::BuildFileList( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
JSBool JSI_VFS::BuildDirEntList( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// get arguments
|
// get arguments
|
||||||
@ -103,8 +103,8 @@ JSBool JSI_VFS::BuildFileList( JSContext* cx, JSObject* UNUSED(obj), uintN argc,
|
|||||||
|
|
||||||
|
|
||||||
// build array in the callback function
|
// build array in the callback function
|
||||||
BuildFileListState state(cx);
|
BuildDirEntListState state(cx);
|
||||||
vfs_dir_enum( path, flags, filter, BuildFileListCB, &state );
|
vfs_dir_enum( path, flags, filter, BuildDirEntListCB, &state );
|
||||||
|
|
||||||
*rval = OBJECT_TO_JSVAL( state.filename_array );
|
*rval = OBJECT_TO_JSVAL( state.filename_array );
|
||||||
return( JS_TRUE );
|
return( JS_TRUE );
|
||||||
|
@ -16,14 +16,14 @@ namespace JSI_VFS
|
|||||||
// Return an array of pathname strings, one for each matching entry in the
|
// Return an array of pathname strings, one for each matching entry in the
|
||||||
// specified directory.
|
// specified directory.
|
||||||
//
|
//
|
||||||
// pathnames = buildFileList(start_path [, filter_string [, recursive ] ]);
|
// pathnames = buildDirEntList(start_path [, filter_string [, recursive ] ]);
|
||||||
// directory: VFS path
|
// directory: VFS path
|
||||||
// filter_string: default "" matches everything; otherwise, see vfs_next_dirent.
|
// filter_string: default "" matches everything; otherwise, see vfs_next_dirent.
|
||||||
// recurse: should subdirectories be included in the search? default false.
|
// recurse: should subdirectories be included in the search? default false.
|
||||||
//
|
//
|
||||||
// note: full pathnames of each file/subdirectory are returned,
|
// note: full pathnames of each file/subdirectory are returned,
|
||||||
// ready for use as a "filename" for the other functions.
|
// ready for use as a "filename" for the other functions.
|
||||||
JSBool BuildFileList( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
|
JSBool BuildDirEntList( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
|
||||||
|
|
||||||
// Return time [seconds since 1970] of the last modification to the specified file.
|
// Return time [seconds since 1970] of the last modification to the specified file.
|
||||||
//
|
//
|
||||||
|
@ -1349,7 +1349,7 @@ JSFunctionSpec ScriptFunctionTable[] =
|
|||||||
JS_FUNC(createServer, createServer, 0)
|
JS_FUNC(createServer, createServer, 0)
|
||||||
|
|
||||||
// VFS (external)
|
// VFS (external)
|
||||||
JS_FUNC(buildFileList, JSI_VFS::BuildFileList, 1)
|
JS_FUNC(buildDirEntList, JSI_VFS::BuildDirEntList, 1)
|
||||||
JS_FUNC(getFileMTime, JSI_VFS::GetFileMTime, 1)
|
JS_FUNC(getFileMTime, JSI_VFS::GetFileMTime, 1)
|
||||||
JS_FUNC(getFileSize, JSI_VFS::GetFileSize, 1)
|
JS_FUNC(getFileSize, JSI_VFS::GetFileSize, 1)
|
||||||
JS_FUNC(readFile, JSI_VFS::ReadFile, 1)
|
JS_FUNC(readFile, JSI_VFS::ReadFile, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user