18 #include "precompiled.h"
31 #define JS_CHECK_FILE_ERR(err)\
33 if (err == ERR::VFS_FILE_NOT_FOUND)\
35 JS_SET_RVAL(cx, vp, JSVAL_NULL);\
101 CStrW filter_str = L
"";
109 const wchar_t* filter = 0;
110 if (!filter_str.empty())
111 filter = filter_str.c_str();
113 bool recursive =
false;
126 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(state.filename_array));
144 Status err =
g_VFS->GetFileInfo(filename, &fileInfo);
165 Status err =
g_VFS->GetFileInfo(filename, &fileInfo);
168 JS_SET_RVAL(cx, vp,
ToJSVal( (
unsigned)fileInfo.
Size() ));
191 JS_SET_RVAL(cx, vp, JSVAL_NULL);
198 contents.Replace(
"\r\n",
"\n");
201 JS_SET_RVAL(cx, vp,
ToJSVal( contents.FromUTF8() ));
224 JS_SET_RVAL(cx, vp, JSVAL_NULL);
231 contents.Replace(
"\r\n",
"\n");
237 std::stringstream ss(contents);
239 JSObject* line_array = JS_NewArrayObject(cx, 0, NULL);
243 while (std::getline(ss, line))
246 jsval val =
ToJSVal(CStr(line).FromUTF8());
247 JS_SetElement(cx, line_array, cur_line++, &val);
250 JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL( line_array ));
264 JS_SET_RVAL(cx, vp, JSVAL_VOID);
BuildDirEntListState(JSContext *cx_)
CStr DecodeUTF8() const
Returns contents of a UTF-8 encoded file as a string with optional BOM removed.
bool ToPrimitive< CStrW >(JSContext *cx, jsval v, CStrW &Storage)
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
const PSRETURN PSRETURN_OK
Reads a file, then gives read-only access to the contents.
bool ToPrimitive< bool >(JSContext *cx, jsval v, bool &Storage)
JSObject * filename_array
JSBool GetFileMTime(JSContext *cx, uintN argc, jsval *vp)
#define UNUSED2(param)
mark a function local variable or parameter as unused and avoid the corresponding compiler warning...
const String & string() const
static Status BuildDirEntListCB(const VfsPath &pathname, const CFileInfo &fileINfo, uintptr_t cbData)
i64 Status
Error handling system.
JSBool ReadFile(JSContext *cx, uintN argc, jsval *vp)
Status ForEachFile(const PIVFS &fs, const VfsPath &startPath, FileCallback cb, uintptr_t cbData, const wchar_t *pattern, size_t flags)
call back for each file in a directory tree
PSRETURN Load(const PIVFS &vfs, const VfsPath &filename)
Returns either PSRETURN_OK or PSRETURN_CVFSFile_LoadFailed.
JSBool BuildDirEntList(JSContext *cx, uintN argc, jsval *vp)
JSBool ReadFileLines(JSContext *cx, uintN argc, jsval *vp)
#define JS_CHECK_FILE_ERR(err)
JSBool ArchiveBuilderCancel(JSContext *cx, uintN argc, jsval *vp)
#define JSU_REQUIRE_MIN_PARAMS(min_number)
JSBool GetFileSize(JSContext *cx, uintN argc, jsval *vp)