Ticket #1696: progress_1696_I.patch

File progress_1696_I.patch, 7.4 KB (added by trompetin17, 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

     
    3333
    3434#include "lib/sysdep/filesystem.h"
    3535#include "lib/regex.h"
     36#include <boost/regex.hpp>
    3637
    3738
    3839namespace vfs {
     
    5455    return INFO::OK;
    5556}
    5657
    57 
    58 Status ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb, uintptr_t cbData, const wchar_t* pattern, size_t flags)
     58Status ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb, uintptr_t cbData, const wchar_t* pattern, size_t flags, const wchar_t* excludeFolderPattern)
    5959{
    6060    // (declare here to avoid reallocations)
    6161    CFileInfos files; DirectoryNames subdirectoryNames;
     62    boost::wregex* excludeFolderRegex = NULL;
    6263
    6364    // (a FIFO queue is more efficient than recursion because it uses less
    6465    // stack space and avoids seeks due to breadth-first traversal.)
     
    8384        if(!(flags & DIR_RECURSIVE))
    8485            break;
    8586
    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           
    88106        pendingDirectories.pop();
    89107    }
    90108
  • source/lib/file/vfs/vfs_util.h

     
    6363 * @param pattern that file names must match. '*' and '&' wildcards
    6464 *        are allowed. 0 matches everything.
    6565 * @param flags @ref DirFlags
     66 * @param excludeFolderPattern regular expression to exclude folders
    6667 * @return Status
    6768 **/
    68 extern Status ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const wchar_t* pattern = 0, size_t flags = 0);
     69extern 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);
    6970
    7071
    7172/**
  • source/ps/TemplateLoader.cpp

     
    191191    return INFO::OK;
    192192}
    193193
    194 std::vector<std::string> CTemplateLoader::FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType)
     194std::vector<std::string> CTemplateLoader::FindTemplates(const std::string& path, bool includeSubdirectories, ETemplatesType templatesType, const wchar_t* excludeFolders)
    195195{
    196196    std::vector<std::string> templates;
    197197
     
    202202    {
    203203        templatePath = VfsPath(TEMPLATE_ROOT) / path;
    204204        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);
    206206        else
    207207            ok = vfs::ForEachFile(g_VFS, templatePath, AddToTemplates, (uintptr_t)&templates, L"*.xml");
    208208        WARN_IF_ERR(ok);
  • source/ps/TemplateLoader.h

     
    5353     * Returns a list of strings that could be validly passed as @c templateName to LoadTemplateFile.
    5454     * (This includes "actor|foo" etc names).
    5555     */
    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);
    5757
    5858private:
    5959    /**
  • source/simulation2/components/CCmpTemplateManager.cpp

     
    128128
    129129    virtual std::string GetCurrentTemplateName(entity_id_t ent);
    130130
     131    virtual std::vector<std::string> FindAllTemplates(bool includeActors, const wchar_t* excludeFolders);
     132
    131133    virtual std::vector<std::string> FindAllTemplates(bool includeActors);
    132134
    133135    virtual std::vector<entity_id_t> GetEntitiesUsingTemplate(std::string templateName);
     
    228230
    229231std::vector<std::string> CCmpTemplateManager::FindAllTemplates(bool includeActors)
    230232{
     233    return FindAllTemplates(includeActors, NULL);
     234}
     235
     236std::vector<std::string> CCmpTemplateManager::FindAllTemplates(bool includeActors, const wchar_t* excludeFolders)
     237{
    231238    ETemplatesType templatesType = includeActors ? ALL_TEMPLATES : SIMULATION_TEMPLATES;
    232     return m_templateLoader.FindTemplates("", true, templatesType);
     239    return m_templateLoader.FindTemplates("", true, templatesType, excludeFolders);
    233240}
    234241
    235242/**
  • source/simulation2/components/ICmpTemplateManager.h

     
    9797     * (This includes "actor|foo" etc names).
    9898     * Intended for use by the map editor. This is likely to be quite slow.
    9999     */
     100    virtual std::vector<std::string> FindAllTemplates(bool includeActors, const wchar_t* excludeFolders) = 0;
    100101    virtual std::vector<std::string> FindAllTemplates(bool includeActors) = 0;
    101102
    102103    /**
  • source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp

     
    6565{
    6666    std::vector<sObjectsListItem> objects;
    6767
     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   
    6874    CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
    6975    if (cmpTemplateManager)
    7076    {
    71         std::vector<std::string> names = cmpTemplateManager->FindAllTemplates(true);
     77        std::vector<std::string> names = cmpTemplateManager->FindAllTemplates(true, excludeFolders.c_str());
    7278
    7379        for (std::vector<std::string>::iterator it = names.begin(); it != names.end(); ++it)
    7480        {