From 63f37017719d01f9ea72fb1f1e1722918a368755 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 13 Feb 2017 15:25:21 +0300 Subject: Remove from resourcemanager function for add/remove archives from directory. --- src/client.cpp | 8 ++-- src/dyetool/client.cpp | 4 +- src/resources/resourcemanager/resourcemanager.cpp | 46 ----------------------- src/resources/resourcemanager/resourcemanager.h | 15 -------- src/utils/virtfs.cpp | 46 +++++++++++++++++++++++ src/utils/virtfs.h | 5 +++ 6 files changed, 57 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 29fdc971a..79d4ce339 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1074,7 +1074,7 @@ int Client::gameExec() if (settings.options.dataPath.empty()) { // Add customdata directory - resourceManager->searchAndRemoveArchives( + VirtFs::searchAndRemoveArchives( "customdata/", "zip"); } @@ -1087,7 +1087,7 @@ int Client::gameExec() if (!settings.options.skipUpdate) { - resourceManager->searchAndRemoveArchives( + VirtFs::searchAndRemoveArchives( settings.updatesDir + "/local/", "zip"); @@ -1302,7 +1302,7 @@ int Client::gameExec() if (settings.options.dataPath.empty()) { // Add customdata directory - resourceManager->searchAndAddArchives( + VirtFs::searchAndAddArchives( "customdata/", "zip", Append_false); @@ -1310,7 +1310,7 @@ int Client::gameExec() if (!settings.options.skipUpdate) { - resourceManager->searchAndAddArchives( + VirtFs::searchAndAddArchives( settings.updatesDir + "/local/", "zip", Append_false); diff --git a/src/dyetool/client.cpp b/src/dyetool/client.cpp index 19ad331a3..c601881f7 100644 --- a/src/dyetool/client.cpp +++ b/src/dyetool/client.cpp @@ -628,7 +628,7 @@ int Client::gameExec() if (settings.options.dataPath.empty()) { // Add customdata directory - resourceManager->searchAndAddArchives( + VirtFs::searchAndAddArchives( "customdata/", "zip", Append_false); @@ -636,7 +636,7 @@ int Client::gameExec() if (!settings.options.skipUpdate) { - resourceManager->searchAndAddArchives( + VirtFs::searchAndAddArchives( settings.updatesDir + "/local/", "zip", Append_false); diff --git a/src/resources/resourcemanager/resourcemanager.cpp b/src/resources/resourcemanager/resourcemanager.cpp index 530d45902..244f657e2 100644 --- a/src/resources/resourcemanager/resourcemanager.cpp +++ b/src/resources/resourcemanager/resourcemanager.cpp @@ -335,52 +335,6 @@ void ResourceManager::clearDeleted(const bool full) } } -void ResourceManager::searchAndAddArchives(const std::string &restrict path, - const std::string &restrict ext, - const Append append) const -{ - const char *const dirSep = dirSeparator; - char **list = VirtFs::enumerateFiles(path.c_str()); - - for (char **i = list; *i; i++) - { - const size_t len = strlen(*i); - - if (len > ext.length() && !ext.compare((*i) + (len - ext.length()))) - { - const std::string file = path + (*i); - const std::string realPath = std::string( - VirtFs::getRealDir(file.c_str())); - VirtFs::addZipToSearchPath(std::string(realPath).append( - dirSep).append(file), append); - } - } - - VirtFs::freeList(list); -} - -void ResourceManager::searchAndRemoveArchives(const std::string &restrict path, - const std::string &restrict ext) - const -{ - const char *const dirSep = dirSeparator; - char **list = VirtFs::enumerateFiles(path.c_str()); - - for (char **i = list; *i; i++) - { - const size_t len = strlen(*i); - if (len > ext.length() && !ext.compare((*i) + (len - ext.length()))) - { - const std::string file = path + (*i); - const std::string realPath = std::string( - VirtFs::getRealDir(file.c_str())); - VirtFs::removeZipFromSearchPath(std::string(realPath).append( - dirSep).append(file)); - } - } - - VirtFs::freeList(list); -} bool ResourceManager::addResource(const std::string &idPath, Resource *const resource) diff --git a/src/resources/resourcemanager/resourcemanager.h b/src/resources/resourcemanager/resourcemanager.h index b9732947f..6fff83df0 100644 --- a/src/resources/resourcemanager/resourcemanager.h +++ b/src/resources/resourcemanager/resourcemanager.h @@ -25,8 +25,6 @@ #include "resources/memorycounter.h" -#include "enums/simpletypes/append.h" - #include #include @@ -59,19 +57,6 @@ class ResourceManager final : public MemoryCounter */ ~ResourceManager(); - /** - * Searches for zip files and adds them to the search path. - */ - void searchAndAddArchives(const std::string &restrict path, - const std::string &restrict ext, - const Append append) const; - - /** - * Searches for zip files and remove them from the search path. - */ - void searchAndRemoveArchives(const std::string &restrict path, - const std::string &restrict ext) const; - /** * Creates a resource and adds it to the resource map. * diff --git a/src/utils/virtfs.cpp b/src/utils/virtfs.cpp index 0ab3b668f..e5b407f35 100644 --- a/src/utils/virtfs.cpp +++ b/src/utils/virtfs.cpp @@ -299,4 +299,50 @@ namespace VirtFs { return PHYSFS_eof(file->mPrivate->mFile); } + + void searchAndAddArchives(const std::string &restrict path, + const std::string &restrict ext, + const Append append) + { + char **list = VirtFs::enumerateFiles(path.c_str()); + + for (char **i = list; *i; i++) + { + const size_t len = strlen(*i); + + if (len > ext.length() && + !ext.compare((*i) + (len - ext.length()))) + { + const std::string file = path + (*i); + const std::string realPath = std::string( + VirtFs::getRealDir(file.c_str())); + VirtFs::addZipToSearchPath(std::string(realPath).append( + dirSeparator).append(file), append); + } + } + VirtFs::freeList(list); + } + + void searchAndRemoveArchives(const std::string &restrict path, + const std::string &restrict ext) + { + char **list = VirtFs::enumerateFiles(path.c_str()); + + for (char **i = list; *i; i++) + { + const size_t len = strlen(*i); + if (len > ext.length() && + !ext.compare((*i) + (len - ext.length()))) + { + const std::string file = path + (*i); + const std::string realPath = std::string( + VirtFs::getRealDir(file.c_str())); + VirtFs::removeZipFromSearchPath(std::string( + realPath).append( + dirSeparator).append( + file)); + } + } + VirtFs::freeList(list); + } } // namespace PhysFs diff --git a/src/utils/virtfs.h b/src/utils/virtfs.h index f28354790..05243817f 100644 --- a/src/utils/virtfs.h +++ b/src/utils/virtfs.h @@ -70,6 +70,11 @@ namespace VirtFs int seek(VirtFile *const file, const uint64_t pos); int eof(VirtFile *const file); + void searchAndAddArchives(const std::string &restrict path, + const std::string &restrict ext, + const Append append); + void searchAndRemoveArchives(const std::string &restrict path, + const std::string &restrict ext); } // namespace VirtFs extern const char *dirSeparator; -- cgit v1.2.3-70-g09d2