- Fix a bug where JFileSystem would return duplicate results in function scanfolder (can lead to "card id collision" in the previous builds)

This commit is contained in:
wagic.the.homebrew
2011-08-21 12:53:57 +00:00
parent 87d60cd79e
commit cb0f2b373f
3 changed files with 34 additions and 16 deletions

View File

@@ -385,7 +385,11 @@ std::vector<std::string>& JFileSystem::scanfolder(const std::string& _folderName
if (folderName[folderName.length() - 1] != '/')
folderName.append("/");
//user filesystem
//we scan zips first, then normal folders.
// This is to avoid duplicate folders coming from the real folder
// (a folder "foo" in the zip comes out as "foo/", while on the real FS it comes out as "foo")
//user zips
{
//Scan the zip filesystem
std::vector<std::string> userZips;
@@ -393,18 +397,9 @@ std::vector<std::string>& JFileSystem::scanfolder(const std::string& _folderName
for (size_t i = 0; i < userZips.size(); ++i)
seen[userZips[i]] = true;
//scan the real files
//TODO check for "/"
std::vector<std::string> userReal;
string realFolderName = mUserFSPath;
realFolderName.append(folderName);
scanRealFolder(realFolderName, userReal);
for (size_t i = 0; i < userReal.size(); ++i)
seen[userReal[i]] = true;
}
//system zips
if (mSystemFS)
{
//Scan the zip filesystem
@@ -414,8 +409,28 @@ std::vector<std::string>& JFileSystem::scanfolder(const std::string& _folderName
for (size_t i = 0; i < systemZips.size(); ++i)
seen[systemZips[i]] = true;
}
//user real files
{
//scan the real files
//TODO check for "/"
std::vector<std::string> userReal;
string realFolderName = mUserFSPath;
realFolderName.append(folderName);
scanRealFolder(realFolderName, userReal);
for (size_t i = 0; i < userReal.size(); ++i)
{
string asFolder = userReal[i] + "/";
if (seen.find(asFolder) == seen.end())
seen[userReal[i]] = true;
}
}
//system real files
if (mSystemFS)
{
//scan the real files
std::vector<std::string> systemReal;
string realFolderName = mSystemFSPath;
realFolderName.append(folderName);
@@ -423,10 +438,13 @@ std::vector<std::string>& JFileSystem::scanfolder(const std::string& _folderName
for (size_t i = 0; i < systemReal.size(); ++i)
seen[systemReal[i]] = true;
{
string asFolder = systemReal[i] + "/";
if (seen.find(asFolder) == seen.end())
seen[systemReal[i]] = true;
}
}
for(map<string,bool>::iterator it = seen.begin(); it != seen.end(); ++it)
{
results.push_back(it->first);

View File

@@ -101,7 +101,7 @@ void GameApp::Create()
// Create User Folders (for write access) if they don't exist
{
const char* folders[] = { "ai", "ai/baka", "ai/baka/stats", "campaigns", "graphics", "lang", "packs", "player", "player/stats", "profiles", "rules", "sets", "settings", "sound", "sound/sfx", "themes"};
const char* folders[] = { "ai", "ai/baka", "ai/baka/stats", "campaigns", "graphics", "lang", "packs", "player", "player/stats", "profiles", "rules", "sets", "settings", "sound", "sound/sfx", "themes", "test"};
string userRoot = JFileSystem::GetInstance()->GetUserRoot();
MAKEDIR(userRoot.c_str());

View File

@@ -329,8 +329,8 @@ int MTGAllCards::load(const char * config_file, const char * set_name, int autol
if (!std::getline(stream, s)) return total_cards;
lineNumber++;
if (!s.size()) continue;
if (s[s.size() - 1] == '\r') s.erase(s.size() - 1); // Handle DOS files
if (!s.size()) continue;
switch (conf_read_mode)
{
case MTGAllCards::READ_ANYTHING: