mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-10 06:39:49 +00:00
filter resources files based on extension
This commit is contained in:
parent
19828df799
commit
df6996d4ae
@ -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,16 +29,35 @@ 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::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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CSMWorld::Resources::getSize() const
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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"));
|
||||
|
Loading…
Reference in New Issue
Block a user