From fed3fbee5dc330c57df92ef8eb1a34c324dc9018 Mon Sep 17 00:00:00 2001 From: elexis Date: Tue, 5 Dec 2017 00:22:03 +0000 Subject: [PATCH] Expose the same FileExists to JS GUI, simulation and rmgen. Thus restrict rmgen FileExists from 871ed04521 to rmgen/ and simulation/. Refs #4868, 8de5c26540 Differential Revision: https://code.wildfiregames.com/D1104 Same rap as in 0cfe9ab153, 7fda43d14e. This was SVN commit r20588. --- source/ps/scripting/JSInterface_VFS.cpp | 13 +++++++++---- source/ps/scripting/JSInterface_VFS.h | 2 +- source/simulation2/system/ComponentManager.cpp | 7 ------- source/simulation2/system/ComponentManager.h | 1 - 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/source/ps/scripting/JSInterface_VFS.cpp b/source/ps/scripting/JSInterface_VFS.cpp index e642af7824..8a22660c08 100644 --- a/source/ps/scripting/JSInterface_VFS.cpp +++ b/source/ps/scripting/JSInterface_VFS.cpp @@ -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& 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("ListDirectoryFiles"); - scriptInterface.RegisterFunction("FileExists"); + scriptInterface.RegisterFunction("FileExists"); scriptInterface.RegisterFunction("GetFileMTime"); scriptInterface.RegisterFunction("GetFileSize"); scriptInterface.RegisterFunction("ReadFile"); @@ -261,12 +265,13 @@ void JSI_VFS::RegisterScriptFunctions_GUI(const ScriptInterface& scriptInterface void JSI_VFS::RegisterScriptFunctions_Simulation(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("ListDirectoryFiles"); + scriptInterface.RegisterFunction("FileExists"); scriptInterface.RegisterFunction("ReadJSONFile"); } void JSI_VFS::RegisterScriptFunctions_Maps(const ScriptInterface& scriptInterface) { scriptInterface.RegisterFunction("ListDirectoryFiles"); - scriptInterface.RegisterFunction("FileExists"); + scriptInterface.RegisterFunction("FileExists"); scriptInterface.RegisterFunction("ReadJSONFile"); } diff --git a/source/ps/scripting/JSInterface_VFS.h b/source/ps/scripting/JSInterface_VFS.h index dde6dd2506..e438b9c91d 100644 --- a/source/ps/scripting/JSInterface_VFS.h +++ b/source/ps/scripting/JSInterface_VFS.h @@ -33,7 +33,7 @@ namespace JSI_VFS JS::Value BuildDirEntList(ScriptInterface::CxPrivate* pCxPrivate, const std::vector& 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& 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); diff --git a/source/simulation2/system/ComponentManager.cpp b/source/simulation2/system/ComponentManager.cpp index 219c4deff8..e1c77f2aa2 100644 --- a/source/simulation2/system/ComponentManager.cpp +++ b/source/simulation2/system/ComponentManager.cpp @@ -85,7 +85,6 @@ CComponentManager::CComponentManager(CSimContext& context, shared_ptr ("AddLocalEntity"); m_ScriptInterface.RegisterFunction ("DestroyEntity"); m_ScriptInterface.RegisterFunction ("FlushDestroyedEntities"); - m_ScriptInterface.RegisterFunction ("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); -} diff --git a/source/simulation2/system/ComponentManager.h b/source/simulation2/system/ComponentManager.h index 8413cbc7fd..06dd87e8a5 100644 --- a/source/simulation2/system/ComponentManager.h +++ b/source/simulation2/system/ComponentManager.h @@ -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);