From bbb9bff23969617595c41859a9e25aeb07751224 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Wed, 15 Jan 2014 01:51:56 +0100 Subject: [PATCH] FileSystem: Fix path cache for mounted zip archives --- src/filesystem.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 5be95b1..d679a41 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -309,7 +309,7 @@ RGSS_openArchive(PHYSFS_Io *io, const char *, int forWrite) uint32_t magic = RGSS_MAGIC; /* Top level entry list */ - BoostSet &topLevel = data->dirHash["."]; + BoostSet &topLevel = data->dirHash[""]; while (true) { @@ -694,17 +694,23 @@ static void cacheEnumCB(void *d, const char *origdir, char buf[512]; - if (*origdir != '.') - snprintf(buf, sizeof(buf), "%s/%s", origdir, fname); - else + if (*origdir == '\0') strncpy(buf, fname, sizeof(buf)); + else + snprintf(buf, sizeof(buf), "%s/%s", origdir, fname); - std::string mixedCase(buf); + char *ptr = buf; + + /* Trim leading slash */ + if (*ptr == '/') + ++ptr; + + std::string mixedCase(ptr); for (char *p = buf; *p; ++p) *p = tolower(*p); - std::string lowerCase(buf); + std::string lowerCase(ptr); p->pathCache.insert(lowerCase, mixedCase); @@ -713,7 +719,7 @@ static void cacheEnumCB(void *d, const char *origdir, void FileSystem::createPathCache() { - PHYSFS_enumerateFilesCallback(".", cacheEnumCB, p); + PHYSFS_enumerateFilesCallback("", cacheEnumCB, p); p->havePathCache = true; }