fix up data file search order

master
John Bartholomew 2012-07-13 00:54:29 +01:00 committed by Robert Norris
parent 28b04b2b38
commit 6dcffe48bb
3 changed files with 20 additions and 12 deletions

View File

@ -172,6 +172,11 @@ namespace FileSystem {
return RefCountedPtr<FileData>();
}
// Merge two sets of FileInfo's, by path.
// Input vectors must be sorted. Output will be sorted.
// Where a path is present in both inputs, directories are selected
// in preference to non-directories; otherwise, the FileInfo from the
// first vector is selected in preference to the second vector.
static void file_union_merge(
std::vector<FileInfo>::const_iterator a, std::vector<FileInfo>::const_iterator aend,
std::vector<FileInfo>::const_iterator b, std::vector<FileInfo>::const_iterator bend,
@ -207,24 +212,24 @@ namespace FileSystem {
}
bool founddir = false;
size_t headsize = output.size();
std::vector<FileInfo> merged;
for (std::vector<FileSource*>::const_iterator
it = m_sources.begin(); it != m_sources.end(); ++it)
{
size_t prevsize = output.size();
assert(prevsize >= headsize);
std::vector<FileInfo> temp1;
if ((*it)->ReadDirectory(path, temp1))
std::vector<FileInfo> nextfiles;
if ((*it)->ReadDirectory(path, nextfiles)) {
founddir = true;
std::vector<FileInfo> temp2;
temp2.swap(merged);
file_union_merge(
temp1.begin(), temp1.end(),
temp2.begin(), temp2.end(),
merged);
std::vector<FileInfo> prevfiles;
prevfiles.swap(merged);
// merge order is important
// file_union_merge selects from its first input preferentially
file_union_merge(
prevfiles.begin(), prevfiles.end(),
nextfiles.begin(), nextfiles.end(),
merged);
}
}
output.reserve(output.size() + merged.size());

View File

@ -176,6 +176,9 @@ namespace FileSystem {
FileSourceUnion();
~FileSourceUnion();
// add and remove sources
// note: order is important. The array of sources works like a PATH array:
// that is, earlier sources take priority over later sources
void PrependSource(FileSource *fs);
void AppendSource(FileSource *fs);
void RemoveSource(FileSource *fs);

View File

@ -12,7 +12,7 @@ void ModManager::Init() {
const std::string &zipPath = info.GetPath();
if (ends_with(zipPath, ".zip")) {
printf("adding mod: %s\n", zipPath.c_str());
FileSystem::gameDataFiles.AppendSource(new FileSystem::FileSourceZip(FileSystem::JoinPathBelow(modFiles.GetRoot(), zipPath)));
FileSystem::gameDataFiles.PrependSource(new FileSystem::FileSourceZip(FileSystem::JoinPathBelow(modFiles.GetRoot(), zipPath)));
}
}
}