Adapt RGSS archivers and filesystem to physfs 3.0 API

This commit is contained in:
Carsten Teibes 2017-10-08 23:11:18 +02:00 committed by Jonas Kulla
parent b1bdf1e445
commit d427df0c2b
2 changed files with 45 additions and 32 deletions

View File

@ -398,8 +398,8 @@ struct CacheEnumData
}
};
static void cacheEnumCB(void *d, const char *origdir,
const char *fname)
static PHYSFS_EnumerateCallbackResult
cacheEnumCB(void *d, const char *origdir, const char *fname)
{
CacheEnumData &data = *static_cast<CacheEnumData*>(d);
char fullPath[512];
@ -426,7 +426,7 @@ static void cacheEnumCB(void *d, const char *origdir,
/* Iterate over its contents */
data.fileLists.push(&list);
PHYSFS_enumerateFilesCallback(fullPath, cacheEnumCB, d);
PHYSFS_enumerate(fullPath, cacheEnumCB, d);
data.fileLists.pop();
}
else
@ -441,13 +441,15 @@ static void cacheEnumCB(void *d, const char *origdir,
/* Add the lower -> mixed mapping of the file's full path */
data.p->pathCache.insert(lowerCase, mixedCase);
}
return PHYSFS_ENUM_OK;
}
void FileSystem::createPathCache()
{
CacheEnumData data(p);
data.fileLists.push(&p->fileLists[""]);
PHYSFS_enumerateFilesCallback("", cacheEnumCB, &data);
PHYSFS_enumerate("", cacheEnumCB, &data);
p->havePathCache = true;
}
@ -458,8 +460,8 @@ struct FontSetsCBData
SharedFontState *sfs;
};
static void fontSetEnumCB(void *data, const char *dir,
const char *fname)
static PHYSFS_EnumerateCallbackResult
fontSetEnumCB (void *data, const char *dir, const char *fname)
{
FontSetsCBData *d = static_cast<FontSetsCBData*>(data);
@ -467,7 +469,7 @@ static void fontSetEnumCB(void *data, const char *dir,
const char *ext = findExt(fname);
if (!ext)
return;
return PHYSFS_ENUM_STOP;
char lowExt[8];
size_t i;
@ -477,7 +479,7 @@ static void fontSetEnumCB(void *data, const char *dir,
lowExt[i] = '\0';
if (strcmp(lowExt, "ttf") && strcmp(lowExt, "otf"))
return;
return PHYSFS_ENUM_STOP;
char filename[512];
snprintf(filename, sizeof(filename), "%s/%s", dir, fname);
@ -485,7 +487,7 @@ static void fontSetEnumCB(void *data, const char *dir,
PHYSFS_File *handle = PHYSFS_openRead(filename);
if (!handle)
return;
return PHYSFS_ENUM_ERROR;
SDL_RWops ops;
initReadOps(handle, ops, false);
@ -493,12 +495,14 @@ static void fontSetEnumCB(void *data, const char *dir,
d->sfs->initFontSetCB(ops, filename);
SDL_RWclose(&ops);
return PHYSFS_ENUM_OK;
}
/* Basically just a case-insensitive search
* for the folder "Fonts"... */
static void findFontsFolderCB(void *data, const char *,
const char *fname)
static PHYSFS_EnumerateCallbackResult
findFontsFolderCB(void *data, const char *, const char *fname)
{
size_t i = 0;
char buffer[512];
@ -510,14 +514,16 @@ static void findFontsFolderCB(void *data, const char *,
buffer[i] = '\0';
if (strcmp(buffer, "fonts") == 0)
PHYSFS_enumerateFilesCallback(fname, fontSetEnumCB, data);
PHYSFS_enumerate(fname, fontSetEnumCB, data);
return PHYSFS_ENUM_OK;
}
void FileSystem::initFontSets(SharedFontState &sfs)
{
FontSetsCBData d = { p, &sfs };
PHYSFS_enumerateFilesCallback(".", findFontsFolderCB, &d);
PHYSFS_enumerate(".", findFontsFolderCB, &d);
}
struct OpenReadEnumData
@ -550,19 +556,19 @@ struct OpenReadEnumData
{}
};
static void openReadEnumCB(void *d, const char *dirpath,
const char *filename)
static PHYSFS_EnumerateCallbackResult
openReadEnumCB(void *d, const char *dirpath, const char *filename)
{
OpenReadEnumData &data = *static_cast<OpenReadEnumData*>(d);
char buffer[512];
const char *fullPath;
if (data.stopSearching)
return;
return PHYSFS_ENUM_STOP;
/* If there's not even a partial match, continue searching */
if (strncmp(filename, data.filename, data.filenameN) != 0)
return;
return PHYSFS_ENUM_OK;
if (!*dirpath)
{
@ -580,7 +586,7 @@ static void openReadEnumCB(void *d, const char *dirpath,
* of the extension), or up to a following '\0' (full match), we've
* found our file */
if (last != '.' && last != '\0')
return;
return PHYSFS_ENUM_STOP;
/* If the path cache is active, translate from lower case
* to mixed case path */
@ -595,9 +601,9 @@ static void openReadEnumCB(void *d, const char *dirpath,
* be a deeper rooted problem somewhere within PhysFS.
* Just abort alltogether. */
data.stopSearching = true;
data.physfsError = PHYSFS_getLastError();
data.physfsError = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
return;
return PHYSFS_ENUM_ERROR;
}
initReadOps(phys, data.ops, false);
@ -608,6 +614,7 @@ static void openReadEnumCB(void *d, const char *dirpath,
data.stopSearching = true;
++data.matchCount;
return PHYSFS_ENUM_OK;
}
void FileSystem::openRead(OpenHandler &handler, const char *filename)
@ -653,7 +660,7 @@ void FileSystem::openRead(OpenHandler &handler, const char *filename)
}
else
{
PHYSFS_enumerateFilesCallback(dir, openReadEnumCB, &data);
PHYSFS_enumerate(dir, openReadEnumCB, &data);
}
if (data.physfsError)

View File

@ -331,14 +331,16 @@ verifyHeader(PHYSFS_Io *io, char version)
}
static void*
RGSS_openArchive(PHYSFS_Io *io, const char *, int forWrite)
RGSS_openArchive(PHYSFS_Io *io, const char *, int forWrite, int *claimed)
{
if (forWrite)
return 0;
return NULL;
/* Version 1 */
if (!verifyHeader(io, 1))
return 0;
return NULL;
else
*claimed = 1;
RGSS_archiveData *data = new RGSS_archiveData;
data->archiveIo = io;
@ -389,9 +391,9 @@ RGSS_openArchive(PHYSFS_Io *io, const char *, int forWrite)
return data;
}
static void
static PHYSFS_EnumerateCallbackResult
RGSS_enumerateFiles(void *opaque, const char *dirname,
PHYSFS_EnumFilesCallback cb,
PHYSFS_EnumerateCallback cb,
const char *origdir, void *callbackdata)
{
RGSS_archiveData *data = static_cast<RGSS_archiveData*>(opaque);
@ -399,13 +401,15 @@ RGSS_enumerateFiles(void *opaque, const char *dirname,
std::string _dirname(dirname);
if (!data->dirHash.contains(_dirname))
return;
return PHYSFS_ENUM_STOP;
const BoostSet<std::string> &entries = data->dirHash[_dirname];
BoostSet<std::string>::const_iterator iter;
for (iter = entries.cbegin(); iter != entries.cend(); ++iter)
cb(callbackdata, origdir, iter->c_str());
return PHYSFS_ENUM_OK;
}
static PHYSFS_Io*
@ -536,19 +540,21 @@ readUint32AndXor(PHYSFS_Io *io, uint32_t &result, uint32_t key)
}
static void*
RGSS3_openArchive(PHYSFS_Io *io, const char *, int forWrite)
RGSS3_openArchive(PHYSFS_Io *io, const char *, int forWrite, int *claimed)
{
if (forWrite)
return 0;
return NULL;
/* Version 3 */
if (!verifyHeader(io, 3))
return 0;
return NULL;
else
*claimed = 1;
uint32_t baseMagic;
if (!readUint32(io, baseMagic))
return 0;
return NULL;
baseMagic = (baseMagic * 9) + 3;
@ -605,7 +611,7 @@ RGSS3_openArchive(PHYSFS_Io *io, const char *, int forWrite)
error:
delete data;
return 0;
return NULL;
}
return data;