mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-07-03 14:34:34 +00:00
Update Aquaria/BBGE/External sources to comply with the new ttvfs API
This commit is contained in:
parent
8026cdd905
commit
6203bc7ce4
17 changed files with 179 additions and 390 deletions
|
@ -43,6 +43,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
ttvfs::Root vfs; // extern
|
||||
#endif
|
||||
|
||||
Vector getDirVector(Direction dir)
|
||||
{
|
||||
switch(dir)
|
||||
|
@ -489,26 +493,15 @@ void debugLog(const std::string &s)
|
|||
// delete[] when no longer needed.
|
||||
char *readFile(const std::string& path, unsigned long *size_ret)
|
||||
{
|
||||
long fileSize;
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
VFILE *vf = vfs.GetFile(path.c_str());
|
||||
if (!vf)
|
||||
return NULL;
|
||||
char *buffer = (char*)vf->getBuf(NULL, NULL);
|
||||
fileSize = vf->size();
|
||||
vf->dropBuf(false); // unlink buffer from file
|
||||
#else
|
||||
FILE *f = fopen(path.c_str(), "rb");
|
||||
VFILE *f = vfopen(path.c_str(), "rb");
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
|
||||
if (fseek(f, 0, SEEK_END) != 0
|
||||
|| (fileSize = ftell(f)) < 0
|
||||
|| fseek(f, 0, SEEK_SET) != 0)
|
||||
size_t fileSize = 0;
|
||||
if(vfsize(f, &fileSize) < 0)
|
||||
{
|
||||
debugLog(path + ": Failed to get file size");
|
||||
fclose(f);
|
||||
vfclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -519,23 +512,22 @@ char *readFile(const std::string& path, unsigned long *size_ret)
|
|||
os << path << ": Not enough memory for file ("
|
||||
<< (fileSize+1) << " bytes)";
|
||||
debugLog(os.str());
|
||||
fclose(f);
|
||||
vfclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
long bytesRead = fread(buffer, 1, fileSize, f);
|
||||
long bytesRead = vfread(buffer, 1, fileSize, f);
|
||||
if (bytesRead != fileSize)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << path << ": Failed to read file (only got "
|
||||
<< bytesRead << " of " << fileSize << " bytes)";
|
||||
debugLog(os.str());
|
||||
fclose(f);
|
||||
vfclose(f);
|
||||
return NULL;
|
||||
}
|
||||
fclose(f);
|
||||
vfclose(f);
|
||||
buffer[fileSize] = 0;
|
||||
#endif
|
||||
|
||||
if (size_ret)
|
||||
*size_ret = fileSize;
|
||||
|
@ -630,21 +622,19 @@ void forEachFile(std::string path, std::string type, void callback(const std::st
|
|||
{
|
||||
if (path.empty()) return;
|
||||
|
||||
|
||||
#ifdef BBGE_BUILD_VFS
|
||||
ttvfs::VFSDir *vd = vfs.GetDir(path.c_str(), true); // add to tree if it wasn't loaded before
|
||||
if(!vd)
|
||||
ttvfs::DirView view;
|
||||
if(!vfs.FillDirView(path.c_str(), view))
|
||||
{
|
||||
debugLog("Path '" + path + "' does not exist");
|
||||
return;
|
||||
}
|
||||
vd->load(false);
|
||||
vfscallback_s dat;
|
||||
dat.path = &path;
|
||||
dat.ext = type.length() ? type.c_str() : NULL;
|
||||
dat.param = param;
|
||||
dat.callback = callback;
|
||||
vd->forEachFile(forEachFile_vfscallback, &dat, true);
|
||||
view.forEachFile(forEachFile_vfscallback, &dat, true);
|
||||
|
||||
return;
|
||||
// -------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue