1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 21:42:13 +00:00

filter resources files based on extension

This commit is contained in:
Marc Zinnschlag 2014-07-07 11:34:24 +02:00
parent 19828df799
commit df6996d4ae
3 changed files with 32 additions and 9 deletions

View File

@ -8,7 +8,8 @@
#include <components/misc/stringops.hpp>
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<int> (iter->size())>=baseSize+1 &&
iter->substr (0, baseSize)==mBaseDirectory &&
((*iter)[baseSize]=='/' || (*iter)[baseSize]=='\\'))
if (static_cast<int> (iter->size())<baseSize+1 ||
iter->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<int> (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<int> (mFiles.size())-1));
}
}
}

View File

@ -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;

View File

@ -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"));