Ticket #1696: progress_1696_I.patch
File progress_1696_I.patch, 7.4 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/simulation/data/atlasFilters.json
1 { 2 "_comments" : "excludeFolders support regular expression to filter folders", 3 "excludeFolders": "(rubble|formations|special)" 4 } 5 No newline at end of file -
source/lib/file/vfs/vfs_util.cpp
33 33 34 34 #include "lib/sysdep/filesystem.h" 35 35 #include "lib/regex.h" 36 #include <boost/regex.hpp> 36 37 37 38 38 39 namespace vfs { … … 54 55 return INFO::OK; 55 56 } 56 57 57 58 Status ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb, uintptr_t cbData, const wchar_t* pattern, size_t flags) 58 Status ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb, uintptr_t cbData, const wchar_t* pattern, size_t flags, const wchar_t* excludeFolderPattern) 59 59 { 60 60 // (declare here to avoid reallocations) 61 61 CFileInfos files; DirectoryNames subdirectoryNames; 62 boost::wregex* excludeFolderRegex = NULL; 62 63 63 64 // (a FIFO queue is more efficient than recursion because it uses less 64 65 // stack space and avoids seeks due to breadth-first traversal.) … … 83 84 if(!(flags & DIR_RECURSIVE)) 84 85 break; 85 86 86 for(size_t i = 0; i < subdirectoryNames.size(); i++) 87 pendingDirectories.push(path / subdirectoryNames[i]/""); 87 for (size_t i = 0; i < subdirectoryNames.size(); i++) 88 { 89 if (excludeFolderPattern != NULL) 90 { 91 if (excludeFolderRegex == NULL) 92 { 93 excludeFolderRegex = new boost::wregex(excludeFolderPattern); 94 } 95 96 if (boost::regex_match(subdirectoryNames[i].string().c_str(), *excludeFolderRegex)) 97 { 98 //Exclude folder 99 continue; 100 } 101 } 102 103 pendingDirectories.push(path / subdirectoryNames[i] / ""); 104 } 105 88 106 pendingDirectories.pop(); 89 107 } 90 108 -
source/lib/file/vfs/vfs_util.h
63 63 * @param pattern that file names must match. '*' and '&' wildcards 64 64 * are allowed. 0 matches everything. 65 65 * @param flags @ref DirFlags 66 * @param excludeFolderPattern regular expression to exclude folders 66 67 * @return Status 67 68 **/ 68 extern Status ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const wchar_t* pattern = 0, size_t flags = 0 );69 extern Status ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const wchar_t* pattern = 0, size_t flags = 0, const wchar_t* excludeFolderPattern = 0); 69 70 70 71 71 72 /** -
source/ps/TemplateLoader.cpp
191 191 return INFO::OK; 192 192 } 193 193 194 std::vector<std::string> CTemplateLoader::FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType )194 std::vector<std::string> CTemplateLoader::FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType, const wchar_t* excludeFolders) 195 195 { 196 196 std::vector<std::string> templates; 197 197 … … 202 202 { 203 203 templatePath = VfsPath(TEMPLATE_ROOT) / path; 204 204 if (includeSubdirectories) 205 ok = vfs::ForEachFile(g_VFS, templatePath, AddToTemplates, (uintptr_t)&templates, L"*.xml", vfs::DIR_RECURSIVE );205 ok = vfs::ForEachFile(g_VFS, templatePath, AddToTemplates, (uintptr_t)&templates, L"*.xml", vfs::DIR_RECURSIVE, excludeFolders); 206 206 else 207 207 ok = vfs::ForEachFile(g_VFS, templatePath, AddToTemplates, (uintptr_t)&templates, L"*.xml"); 208 208 WARN_IF_ERR(ok); -
source/ps/TemplateLoader.h
53 53 * Returns a list of strings that could be validly passed as @c templateName to LoadTemplateFile. 54 54 * (This includes "actor|foo" etc names). 55 55 */ 56 std::vector<std::string> FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType );56 std::vector<std::string> FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType, const wchar_t* excludeFolders = 0); 57 57 58 58 private: 59 59 /** -
source/simulation2/components/CCmpTemplateManager.cpp
128 128 129 129 virtual std::string GetCurrentTemplateName(entity_id_t ent); 130 130 131 virtual std::vector<std::string> FindAllTemplates(bool includeActors, const wchar_t* excludeFolders); 132 131 133 virtual std::vector<std::string> FindAllTemplates(bool includeActors); 132 134 133 135 virtual std::vector<entity_id_t> GetEntitiesUsingTemplate(std::string templateName); … … 228 230 229 231 std::vector<std::string> CCmpTemplateManager::FindAllTemplates(bool includeActors) 230 232 { 233 return FindAllTemplates(includeActors, NULL); 234 } 235 236 std::vector<std::string> CCmpTemplateManager::FindAllTemplates(bool includeActors, const wchar_t* excludeFolders) 237 { 231 238 ETemplatesType templatesType = includeActors ? ALL_TEMPLATES : SIMULATION_TEMPLATES; 232 return m_templateLoader.FindTemplates("", true, templatesType );239 return m_templateLoader.FindTemplates("", true, templatesType, excludeFolders); 233 240 } 234 241 235 242 /** -
source/simulation2/components/ICmpTemplateManager.h
97 97 * (This includes "actor|foo" etc names). 98 98 * Intended for use by the map editor. This is likely to be quite slow. 99 99 */ 100 virtual std::vector<std::string> FindAllTemplates(bool includeActors, const wchar_t* excludeFolders) = 0; 100 101 virtual std::vector<std::string> FindAllTemplates(bool includeActors) = 0; 101 102 102 103 /** -
source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
65 65 { 66 66 std::vector<sObjectsListItem> objects; 67 67 68 ScriptInterface& scriptInterface = g_Game->GetSimulation2()->GetScriptInterface(); 69 70 CScriptValRooted s = scriptInterface.ReadJSONFile("simulation/data/atlasFilters.json"); 71 std::wstring excludeFolders; 72 scriptInterface.GetProperty(s.get(), "excludeFolders", excludeFolders); 73 68 74 CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); 69 75 if (cmpTemplateManager) 70 76 { 71 std::vector<std::string> names = cmpTemplateManager->FindAllTemplates(true );77 std::vector<std::string> names = cmpTemplateManager->FindAllTemplates(true, excludeFolders.c_str()); 72 78 73 79 for (std::vector<std::string>::iterator it = names.begin(); it != names.end(); ++it) 74 80 {