mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-30 05:47:57 +03:00
Imported Upstream version 0.26.0
This commit is contained in:
commit
9a2b6c69b6
1398 changed files with 212217 additions and 0 deletions
64
components/files/collections.cpp
Normal file
64
components/files/collections.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
|
||||
#include "collections.hpp"
|
||||
|
||||
namespace Files
|
||||
{
|
||||
Collections::Collections()
|
||||
: mDirectories()
|
||||
, mFoldCase(false)
|
||||
, mCollections()
|
||||
{
|
||||
}
|
||||
|
||||
Collections::Collections(const Files::PathContainer& directories, bool foldCase)
|
||||
: mDirectories(directories)
|
||||
, mFoldCase(foldCase)
|
||||
, mCollections()
|
||||
{
|
||||
}
|
||||
|
||||
const MultiDirCollection& Collections::getCollection(const std::string& extension) const
|
||||
{
|
||||
MultiDirCollectionContainer::iterator iter = mCollections.find(extension);
|
||||
if (iter==mCollections.end())
|
||||
{
|
||||
std::pair<MultiDirCollectionContainer::iterator, bool> result =
|
||||
mCollections.insert(std::make_pair(extension, MultiDirCollection(mDirectories, extension, mFoldCase)));
|
||||
|
||||
iter = result.first;
|
||||
}
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
boost::filesystem::path Collections::getPath(const std::string& file) const
|
||||
{
|
||||
for (Files::PathContainer::const_iterator iter = mDirectories.begin();
|
||||
iter != mDirectories.end(); ++iter)
|
||||
{
|
||||
const boost::filesystem::path path = *iter / file;
|
||||
if (boost::filesystem::exists(path))
|
||||
return path.string();
|
||||
}
|
||||
|
||||
throw std::runtime_error ("file " + file + " not found");
|
||||
}
|
||||
|
||||
bool Collections::doesExist(const std::string& file) const
|
||||
{
|
||||
for (Files::PathContainer::const_iterator iter = mDirectories.begin();
|
||||
iter != mDirectories.end(); ++iter)
|
||||
{
|
||||
const boost::filesystem::path path = *iter / file;
|
||||
if (boost::filesystem::exists(path))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const Files::PathContainer& Collections::getPaths() const
|
||||
{
|
||||
return mDirectories;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue