mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-23 12:54:11 +00:00
Expose the same FileExists to JS GUI, simulation and rmgen.
Thus restrict rmgen FileExists from871ed04521to rmgen/ and simulation/. Refs #4868,8de5c26540Differential Revision: https://code.wildfiregames.com/D1104 Same rap as in0cfe9ab153,7fda43d14e. This was SVN commit r20588.
This commit is contained in:
@@ -102,9 +102,9 @@ JS::Value JSI_VFS::BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const
|
||||
}
|
||||
|
||||
// Return true iff the file exits
|
||||
bool JSI_VFS::FileExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const CStrW& filename)
|
||||
bool JSI_VFS::FileExists(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStrW>& validPaths, const CStrW& filename)
|
||||
{
|
||||
return (g_VFS->GetFileInfo(filename, 0) == INFO::OK);
|
||||
return PathRestrictionMet(pCxPrivate, validPaths, filename) && g_VFS->GetFileInfo(filename, 0) == INFO::OK;
|
||||
}
|
||||
|
||||
// Return time [seconds since 1970] of the last modification to the specified file.
|
||||
@@ -240,6 +240,10 @@ JS::Value Script_ListDirectoryFiles_##context(ScriptInterface::CxPrivate* pCxPri
|
||||
{\
|
||||
return JSI_VFS::BuildDirEntList(pCxPrivate, PathRestriction_##context, path, filterStr, recurse);\
|
||||
}\
|
||||
bool Script_FileExists_##context(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filePath)\
|
||||
{\
|
||||
return JSI_VFS::FileExists(pCxPrivate, PathRestriction_##context, filePath);\
|
||||
}\
|
||||
|
||||
VFS_ScriptFunctions(GUI);
|
||||
VFS_ScriptFunctions(Simulation);
|
||||
@@ -249,7 +253,7 @@ VFS_ScriptFunctions(Maps);
|
||||
void JSI_VFS::RegisterScriptFunctions_GUI(const ScriptInterface& scriptInterface)
|
||||
{
|
||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &Script_ListDirectoryFiles_GUI>("ListDirectoryFiles");
|
||||
scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists");
|
||||
scriptInterface.RegisterFunction<bool, std::wstring, Script_FileExists_GUI>("FileExists");
|
||||
scriptInterface.RegisterFunction<double, std::wstring, &JSI_VFS::GetFileMTime>("GetFileMTime");
|
||||
scriptInterface.RegisterFunction<unsigned int, std::wstring, &JSI_VFS::GetFileSize>("GetFileSize");
|
||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &JSI_VFS::ReadFile>("ReadFile");
|
||||
@@ -261,12 +265,13 @@ void JSI_VFS::RegisterScriptFunctions_GUI(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<bool, std::wstring, Script_FileExists_Simulation>("FileExists");
|
||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &Script_ReadJSONFile_Simulation>("ReadJSONFile");
|
||||
}
|
||||
|
||||
void JSI_VFS::RegisterScriptFunctions_Maps(const ScriptInterface& scriptInterface)
|
||||
{
|
||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, std::wstring, bool, &Script_ListDirectoryFiles_Maps>("ListDirectoryFiles");
|
||||
scriptInterface.RegisterFunction<bool, CStrW, JSI_VFS::FileExists>("FileExists");
|
||||
scriptInterface.RegisterFunction<bool, std::wstring, Script_FileExists_Maps>("FileExists");
|
||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &Script_ReadJSONFile_Maps>("ReadJSONFile");
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace JSI_VFS
|
||||
JS::Value BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStrW>& validPaths, const std::wstring& path, const std::wstring& filterStr, bool recurse);
|
||||
|
||||
// Return true iff the file exists
|
||||
bool FileExists(ScriptInterface::CxPrivate* pCxPrivate, const CStrW& filename);
|
||||
bool FileExists(ScriptInterface::CxPrivate* pCxPrivate, const std::vector<CStrW>& validPaths, const CStrW& filename);
|
||||
|
||||
// Return time [seconds since 1970] of the last modification to the specified file.
|
||||
double GetFileMTime(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename);
|
||||
|
||||
@@ -85,7 +85,6 @@ CComponentManager::CComponentManager(CSimContext& context, shared_ptr<ScriptRunt
|
||||
m_ScriptInterface.RegisterFunction<int, std::string, CComponentManager::Script_AddLocalEntity> ("AddLocalEntity");
|
||||
m_ScriptInterface.RegisterFunction<void, int, CComponentManager::Script_DestroyEntity> ("DestroyEntity");
|
||||
m_ScriptInterface.RegisterFunction<void, CComponentManager::Script_FlushDestroyedEntities> ("FlushDestroyedEntities");
|
||||
m_ScriptInterface.RegisterFunction<bool, std::wstring, CComponentManager::Script_DataFileExists> ("DataFileExists");
|
||||
}
|
||||
|
||||
// Define MT_*, IID_* as script globals, and store their names
|
||||
@@ -1184,9 +1183,3 @@ std::string CComponentManager::GenerateSchema() const
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
bool CComponentManager::Script_DataFileExists(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& fileName)
|
||||
{
|
||||
VfsPath path = VfsPath(L"simulation/data") / fileName;
|
||||
return VfsFileExists(path);
|
||||
}
|
||||
|
||||
@@ -326,7 +326,6 @@ private:
|
||||
static int Script_AddLocalEntity(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName);
|
||||
static void Script_DestroyEntity(ScriptInterface::CxPrivate* pCxPrivate, int ent);
|
||||
static void Script_FlushDestroyedEntities(ScriptInterface::CxPrivate* pCxPrivate);
|
||||
static bool Script_DataFileExists(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& fileName);
|
||||
|
||||
CMessage* ConstructMessage(int mtid, JS::HandleValue data);
|
||||
void SendGlobalMessage(entity_id_t ent, const CMessage& msg);
|
||||
|
||||
Reference in New Issue
Block a user