diff --git a/apps/opencs/model/world/resources.cpp b/apps/opencs/model/world/resources.cpp index c819283e18..357661ac39 100644 --- a/apps/opencs/model/world/resources.cpp +++ b/apps/opencs/model/world/resources.cpp @@ -8,7 +8,8 @@ #include -CSMWorld::Resources::Resources (const std::string& baseDirectory) +CSMWorld::Resources::Resources (const std::string& baseDirectory, + const char * const *extensions) : mBaseDirectory (baseDirectory) { int baseSize = mBaseDirectory.size(); @@ -28,14 +29,33 @@ CSMWorld::Resources::Resources (const std::string& baseDirectory) for (Ogre::StringVector::const_iterator iter (resources->begin()); iter!=resources->end(); ++iter) { - if (static_cast (iter->size())>=baseSize+1 && - iter->substr (0, baseSize)==mBaseDirectory && - ((*iter)[baseSize]=='/' || (*iter)[baseSize]=='\\')) + if (static_cast (iter->size())substr (0, baseSize)!=mBaseDirectory || + ((*iter)[baseSize]!='/' && (*iter)[baseSize]!='\\')) + continue; + + if (extensions) { - std::string file = iter->substr (baseSize+1); - mFiles.push_back (file); - mIndex.insert (std::make_pair (file, static_cast (mFiles.size())-1)); + std::string::size_type index = iter->find_last_of ('.'); + + if (index==std::string::npos) + continue; + + std::string extension = iter->substr (index+1); + + int i = 0; + + for (; extensions[i]; ++i) + if (extensions[i]==extension) + break; + + if (!extensions[i]) + continue; } + + std::string file = iter->substr (baseSize+1); + mFiles.push_back (file); + mIndex.insert (std::make_pair (file, static_cast (mFiles.size())-1)); } } } diff --git a/apps/opencs/model/world/resources.hpp b/apps/opencs/model/world/resources.hpp index 54c4fa8214..599f9a35b4 100644 --- a/apps/opencs/model/world/resources.hpp +++ b/apps/opencs/model/world/resources.hpp @@ -15,7 +15,7 @@ namespace CSMWorld public: - Resources (const std::string& baseDirectory); + Resources (const std::string& baseDirectory, const char * const *extensions = 0); int getSize() const; diff --git a/apps/opencs/model/world/resourcesmanager.cpp b/apps/opencs/model/world/resourcesmanager.cpp index 980e099f4b..7c782e7c59 100644 --- a/apps/opencs/model/world/resourcesmanager.cpp +++ b/apps/opencs/model/world/resourcesmanager.cpp @@ -5,7 +5,10 @@ void CSMWorld::ResourcesManager::listResources() { - mResources.insert (std::make_pair (UniversalId::Type_Mesh, "meshes")); + static const char * const sMeshTypes[] = { "nif", 0 }; + + mResources.insert ( + std::make_pair (UniversalId::Type_Mesh, Resources ("meshes", sMeshTypes))); mResources.insert (std::make_pair (UniversalId::Type_Icon, "icons")); mResources.insert (std::make_pair (UniversalId::Type_Music, "music")); mResources.insert (std::make_pair (UniversalId::Type_SoundRes, "sound"));