1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Fix issue #2068 - maps list update

This commit is contained in:
Vadim Markovtsev 2016-10-16 22:09:57 +02:00
parent 5506ae036a
commit 89f506658e
9 changed files with 39 additions and 8 deletions

View File

@ -1103,6 +1103,10 @@ void SelectionTab::filter( int size, bool selectFirst )
std::unordered_set<ResourceID> SelectionTab::getFiles(std::string dirURI, int resType)
{
boost::to_upper(dirURI);
CResourceHandler::get()->updateFilteredFiles([&](const std::string & mount)
{
return boost::algorithm::starts_with(mount, dirURI);
});
std::unordered_set<ResourceID> ret = CResourceHandler::get()->getFilteredFiles([&](const ResourceID & ident)
{
@ -1115,6 +1119,7 @@ std::unordered_set<ResourceID> SelectionTab::getFiles(std::string dirURI, int re
void SelectionTab::parseMaps(const std::unordered_set<ResourceID> &files)
{
logGlobal->debug("Parsing %d maps", files.size());
allItems.clear();
for(auto & file : files)
{

View File

@ -102,6 +102,12 @@ std::set<boost::filesystem::path> CFilesystemList::getResourceNames(const Resour
return std::move(paths);
}
void CFilesystemList::updateFilteredFiles(std::function<bool(const std::string &)> filter) const
{
for (auto & loader : loaders)
loader->updateFilteredFiles(filter);
}
std::unordered_set<ResourceID> CFilesystemList::getFilteredFiles(std::function<bool(const ResourceID &)> filter) const
{
std::unordered_set<ResourceID> ret;

View File

@ -41,6 +41,7 @@ public:
bool existsResource(const ResourceID & resourceName) const override;
std::string getMountPoint() const override;
boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override {}
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
private:
@ -71,6 +72,7 @@ public:
std::string getMountPoint() const override;
boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const override;
std::set<boost::filesystem::path> getResourceNames(const ResourceID & resourceName) const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override;
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
bool createResource(std::string filename, bool update = false) override;
std::vector<const ISimpleResourceLoader *> getResourcesWithName(const ResourceID & resourceName) const override;

View File

@ -61,6 +61,7 @@ public:
std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
bool existsResource(const ResourceID & resourceName) const override;
std::string getMountPoint() const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override {}
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
private:

View File

@ -38,6 +38,14 @@ boost::optional<boost::filesystem::path> CFilesystemLoader::getResourceName(cons
return baseDirectory / fileList.at(resourceName);
}
void CFilesystemLoader::updateFilteredFiles(std::function<bool(const std::string &)> filter) const
{
if (filter(mountPoint))
{
fileList = listFiles(mountPoint, 1, false);
}
}
std::unordered_set<ResourceID> CFilesystemLoader::getFilteredFiles(std::function<bool(const ResourceID &)> filter) const
{
std::unordered_set<ResourceID> foundID;

View File

@ -38,6 +38,7 @@ public:
std::string getMountPoint() const override;
bool createResource(std::string filename, bool update = false) override;
boost::optional<boost::filesystem::path> getResourceName(const ResourceID & resourceName) const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override;
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
private:
@ -50,7 +51,7 @@ private:
* key = ResourceID for resource loader
* value = name that can be used to access file
*/
std::unordered_map<ResourceID, boost::filesystem::path> fileList;
mutable std::unordered_map<ResourceID, boost::filesystem::path> fileList;
/**
* Returns a list of pathnames denoting the files in the directory denoted by this pathname.

View File

@ -56,6 +56,7 @@ public:
std::unique_ptr<CInputStream> load(const ResourceID & resourceName) const override;
bool existsResource(const ResourceID & resourceName) const override;
std::string getMountPoint() const override;
void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override {}
std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
};

View File

@ -70,7 +70,14 @@ public:
}
/**
* Get list of files that matches filter function
* Update lists of files that match filter function
*
* @param filter Filter that returns true if specified mount point matches filter
*/
virtual void updateFilteredFiles(std::function<bool(const std::string &)> filter) const = 0;
/**
* Get list of files that match filter function
*
* @param filter Filter that returns true if specified ID matches filter
* @return Returns list of flies