|
@@ -63,6 +63,38 @@ static int Atomic_GetParentPath(duk_context* ctx)
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static int FileSystem_ScanDir(duk_context* ctx)
|
|
|
|
|
+{
|
|
|
|
|
+ duk_push_this(ctx);
|
|
|
|
|
+
|
|
|
|
|
+ FileSystem* fs = js_to_class_instance<FileSystem>(ctx, -1, 0);
|
|
|
|
|
+
|
|
|
|
|
+ if ( !duk_is_string(ctx, 0) || !duk_is_string(ctx, 1) ||
|
|
|
|
|
+ !duk_is_number(ctx, 2) || !duk_is_boolean(ctx, 3))
|
|
|
|
|
+ {
|
|
|
|
|
+ duk_push_string(ctx, "FileSystem::ScanDir bad args");
|
|
|
|
|
+ duk_throw(ctx);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const char* pathName = duk_to_string(ctx, 0);
|
|
|
|
|
+ const char* filter = duk_to_string(ctx, 1);
|
|
|
|
|
+ unsigned flags = duk_to_number(ctx, 2);
|
|
|
|
|
+ bool recursive = duk_to_boolean(ctx, 3) ? true : false;
|
|
|
|
|
+
|
|
|
|
|
+ Vector<String> result;
|
|
|
|
|
+
|
|
|
|
|
+ fs->ScanDir(result, pathName, filter, flags, recursive);
|
|
|
|
|
+
|
|
|
|
|
+ duk_push_array(ctx);
|
|
|
|
|
+
|
|
|
|
|
+ for (unsigned i = 0; i < result.Size(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ duk_push_string(ctx, result[i].CString());
|
|
|
|
|
+ duk_put_prop_index(ctx, -2, i);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 1;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
void jsapi_init_filesystem(JSVM* vm)
|
|
void jsapi_init_filesystem(JSVM* vm)
|
|
|
{
|
|
{
|
|
@@ -83,6 +115,12 @@ void jsapi_init_filesystem(JSVM* vm)
|
|
|
duk_put_prop_string(ctx, -2, "getExtension");
|
|
duk_put_prop_string(ctx, -2, "getExtension");
|
|
|
|
|
|
|
|
duk_pop(ctx); // pop Atomic object
|
|
duk_pop(ctx); // pop Atomic object
|
|
|
|
|
+
|
|
|
|
|
+ js_class_get_prototype(ctx, "Atomic", "FileSystem");
|
|
|
|
|
+ duk_push_c_function(ctx, FileSystem_ScanDir, 4);
|
|
|
|
|
+ duk_put_prop_string(ctx, -2, "scanDir");
|
|
|
|
|
+ duk_pop(ctx);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|