aboutsummaryrefslogtreecommitdiff
path: root/common/archive.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2009-09-23 00:15:00 +0000
committerJohannes Schickel2009-09-23 00:15:00 +0000
commitc50940bbf4c9bde173cc3af22cf9b38a25df3514 (patch)
tree54101a22c17e39db13339cd52f4c2909b33b86c4 /common/archive.cpp
parent75113ad5f325f7b6ab802becf845705f97dd629e (diff)
downloadscummvm-rg350-c50940bbf4c9bde173cc3af22cf9b38a25df3514.tar.gz
scummvm-rg350-c50940bbf4c9bde173cc3af22cf9b38a25df3514.tar.bz2
scummvm-rg350-c50940bbf4c9bde173cc3af22cf9b38a25df3514.zip
Got rid of Common::File::addDefaultDirectory, instead implemented the solution proposed in "Case agnostic handling for directories (and files)" on -devel.
svn-id: r44266
Diffstat (limited to 'common/archive.cpp')
-rw-r--r--common/archive.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/common/archive.cpp b/common/archive.cpp
index ecc00f4cff..e815b781bf 100644
--- a/common/archive.cpp
+++ b/common/archive.cpp
@@ -123,6 +123,52 @@ void SearchSet::addDirectory(const String &name, const FSNode &dir, int priority
add(name, new FSDirectory(dir, depth, flat), priority);
}
+void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String pattern, bool ignoreCase, int priority) {
+ FSList subDirs;
+ if (!directory.getChildren(subDirs))
+ return;
+
+ String nextPattern;
+ String::const_iterator sep = Common::find(pattern.begin(), pattern.end(), '/');
+ if (sep != pattern.end()) {
+ pattern = String(pattern.begin(), sep);
+
+ ++sep;
+ if (sep != pattern.end())
+ nextPattern = String(sep, pattern.end());
+ }
+
+ // TODO: The code we have for displaying all matches, which vary only in case, might
+ // be a bit overhead, but as long as we want to display all useful information to the
+ // user we will need to keep track of all directory names added so far. We might
+ // want to reconsider this though.
+ typedef HashMap<String, bool, IgnoreCase_Hash, IgnoreCase_EqualTo> MatchList;
+ MatchList multipleMatches;
+ MatchList::iterator matchIter;
+
+ for (FSList::const_iterator i = subDirs.begin(); i != subDirs.end(); ++i) {
+ String name = i->getName();
+
+ if (Common::matchString(name.c_str(), pattern.c_str(), ignoreCase)) {
+ matchIter = multipleMatches.find(name);
+ if (matchIter == multipleMatches.end()) {
+ multipleMatches[name] = true;
+ } else {
+ if (matchIter->_value) {
+ warning("Clash in case for match of pattern \"%s\" found in directory \"%s\": \"%s\"", pattern.c_str(), directory.getPath().c_str(), matchIter->_key.c_str());
+ matchIter->_value = false;
+ }
+
+ warning("Clash in case for match of pattern \"%s\" found in directory \"%s\": \"%s\"", pattern.c_str(), directory.getPath().c_str(), name.c_str());
+ }
+
+ if (nextPattern.empty())
+ addDirectory(name, *i, priority);
+ else
+ addSubDirectoriesMatching(*i, nextPattern, ignoreCase, priority);
+ }
+ }
+}
void SearchSet::remove(const String &name) {
ArchiveNodeList::iterator it = find(name);