You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/components/vfs/filesystemarchive.cpp

69 lines
1.9 KiB
C++

#include "filesystemarchive.hpp"
#include <iostream>
#include <boost/filesystem.hpp>
namespace VFS
{
FileSystemArchive::FileSystemArchive(const std::string &path)
: mBuiltIndex(false)
, mPath(path)
{
}
void FileSystemArchive::listResources(std::map<std::string, File *> &out, char (*normalize_function)(char))
{
if (!mBuiltIndex)
{
typedef boost::filesystem::recursive_directory_iterator directory_iterator;
directory_iterator end;
size_t prefix = mPath.size ();
if (mPath.size () > 0 && mPath [prefix - 1] != '\\' && mPath [prefix - 1] != '/')
++prefix;
for (directory_iterator i (mPath); i != end; ++i)
{
if(boost::filesystem::is_directory (*i))
continue;
std::string proper = i->path ().string ();
FileSystemArchiveFile file(proper);
std::string searchable;
std::transform(proper.begin() + prefix, proper.end(), std::back_inserter(searchable), normalize_function);
if (!mIndex.insert (std::make_pair (searchable, file)).second)
std::cerr << "Warning: found duplicate file for '" << proper << "', please check your file system for two files with the same name in different cases." << std::endl;
}
mBuiltIndex = true;
}
for (index::iterator it = mIndex.begin(); it != mIndex.end(); ++it)
{
out[it->first] = &it->second;
}
}
// ----------------------------------------------------------------------------------
FileSystemArchiveFile::FileSystemArchiveFile(const std::string &path)
: mPath(path)
{
}
Files::IStreamPtr FileSystemArchiveFile::open()
{
return Files::openConstrainedFileStream(mPath.c_str());
}
}