Changeset View
Changeset View
Standalone View
Standalone View
source/ps/scripting/JSInterface_VFS.cpp
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
// | // | ||||
// pathnames = buildDirEntList(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. | ||||
JS::Value JSI_VFS::BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& path, const std::wstring& filterStr, bool recurse) | JS::Value JSI_VFS::BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStrW>& validPaths, const std::wstring& path, const std::wstring& filterStr, bool recurse) | ||||
s0600204: Don't forget to update this function's block comment as appropriate. (And there's a copy in the… | |||||
{ | { | ||||
if (!PathRestrictionMet(pCxPrivate, validPaths, path)) | |||||
return JS::NullValue(); | |||||
// convert to const wchar_t*; if there's no filter, pass 0 for speed | // convert to const wchar_t*; if there's no filter, pass 0 for speed | ||||
// (interpreted as: "accept all files without comparing"). | // (interpreted as: "accept all files without comparing"). | ||||
const wchar_t* filter = 0; | const wchar_t* filter = 0; | ||||
if (!filterStr.empty()) | if (!filterStr.empty()) | ||||
filter = filterStr.c_str(); | filter = filterStr.c_str(); | ||||
int flags = recurse ? vfs::DIR_RECURSIVE : 0; | int flags = recurse ? vfs::DIR_RECURSIVE : 0; | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | bool JSI_VFS::PathRestrictionMet(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStrW>& validPaths, const CStrW& filePath) | ||||
return false; | return false; | ||||
} | } | ||||
#define VFS_ScriptFunctions(context)\ | #define VFS_ScriptFunctions(context)\ | ||||
JS::Value Script_ReadJSONFile_##context(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filePath)\ | JS::Value Script_ReadJSONFile_##context(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filePath)\ | ||||
{\ | {\ | ||||
return JSI_VFS::ReadJSONFile(pCxPrivate, PathRestriction_##context, filePath);\ | return JSI_VFS::ReadJSONFile(pCxPrivate, PathRestriction_##context, filePath);\ | ||||
} | }\ | ||||
JS::Value Script_ListDirectoryFiles_##context(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& path, const std::wstring& filterStr, bool recurse)\ | |||||
{\ | |||||
return JSI_VFS::BuildDirEntList(pCxPrivate, PathRestriction_##context, path, filterStr, recurse);\ | |||||
}\ | |||||
VFS_ScriptFunctions(GUI); | VFS_ScriptFunctions(GUI); | ||||
VFS_ScriptFunctions(Simulation); | VFS_ScriptFunctions(Simulation); | ||||
VFS_ScriptFunctions(Maps); | VFS_ScriptFunctions(Maps); | ||||
#undef VFS_ScriptFunctions | #undef VFS_ScriptFunctions | ||||
void JSI_VFS::RegisterScriptFunctions_GUI(const ScriptInterface& scriptInterface) | void JSI_VFS::RegisterScriptFunctions_GUI(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &JSI_VFS::BuildDirEntList>("BuildDirEntList"); | scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &Script_ListDirectoryFiles_GUI>("ListDirectoryFiles"); | ||||
scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists"); | scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists"); | ||||
scriptInterface.RegisterFunction<double, std::wstring, &JSI_VFS::GetFileMTime>("GetFileMTime"); | scriptInterface.RegisterFunction<double, std::wstring, &JSI_VFS::GetFileMTime>("GetFileMTime"); | ||||
scriptInterface.RegisterFunction<unsigned int, std::wstring, &JSI_VFS::GetFileSize>("GetFileSize"); | scriptInterface.RegisterFunction<unsigned int, std::wstring, &JSI_VFS::GetFileSize>("GetFileSize"); | ||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &JSI_VFS::ReadFile>("ReadFile"); | scriptInterface.RegisterFunction<JS::Value, std::wstring, &JSI_VFS::ReadFile>("ReadFile"); | ||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &JSI_VFS::ReadFileLines>("ReadFileLines"); | scriptInterface.RegisterFunction<JS::Value, std::wstring, &JSI_VFS::ReadFileLines>("ReadFileLines"); | ||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &Script_ReadJSONFile_GUI>("ReadJSONFile"); | scriptInterface.RegisterFunction<JS::Value, std::wstring, &Script_ReadJSONFile_GUI>("ReadJSONFile"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, &WriteJSONFile>("WriteJSONFile"); | scriptInterface.RegisterFunction<void, std::wstring, JS::HandleValue, &WriteJSONFile>("WriteJSONFile"); | ||||
} | } | ||||
void JSI_VFS::RegisterScriptFunctions_Simulation(const ScriptInterface& scriptInterface) | void JSI_VFS::RegisterScriptFunctions_Simulation(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &Script_ListDirectoryFiles_Simulation>("ListDirectoryFiles"); | |||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &Script_ReadJSONFile_Simulation>("ReadJSONFile"); | scriptInterface.RegisterFunction<JS::Value, std::wstring, &Script_ReadJSONFile_Simulation>("ReadJSONFile"); | ||||
} | } | ||||
void JSI_VFS::RegisterScriptFunctions_Maps(const ScriptInterface& scriptInterface) | void JSI_VFS::RegisterScriptFunctions_Maps(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &JSI_VFS::BuildDirEntList>("BuildDirEntList"); | scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &Script_ListDirectoryFiles_Maps>("ListDirectoryFiles"); | ||||
scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists"); | scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists"); | ||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &Script_ReadJSONFile_Maps>("ReadJSONFile"); | scriptInterface.RegisterFunction<JS::Value, std::wstring, &Script_ReadJSONFile_Maps>("ReadJSONFile"); | ||||
} | } |
Wildfire Games · Phabricator
Don't forget to update this function's block comment as appropriate. (And there's a copy in the .h file to deal with as well.)