diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp index cb5accf..f718025 100644 --- a/Aquaria/DSQ.cpp +++ b/Aquaria/DSQ.cpp @@ -2142,7 +2142,7 @@ void DSQ::applyPatches() // This is to allow files in patches to override files in mods on non-win32 systems (theoretically) if(!vfs.GetDir("_mods")) { - vfs.MountExternalPath(mod.getBaseModPath().c_str(), "_mods"); + vfs.Mount(mod.getBaseModPath().c_str(), "_mods"); } loadMods(); @@ -2159,23 +2159,23 @@ void DSQ::applyPatches() #ifdef BBGE_BUILD_VFS -static void refr_pushback(ttvfs::VFSDir *vd, void *user) +static void refr_pushback(ttvfs::DirBase *vd, void *user) { - std::list *li = (std::list*)user; - li->push_back(vd); + std::list *li = (std::list*)user; + li->push_back(vd->fullname()); } static void refr_insert(VFILE *vf, void *user) { - // texture names are like: "naija/naija2-frontleg3" - no .png extension, and no gfx/ path - std::set*files = (std::set*)user; - std::string t = vf->fullname(); - size_t dotpos = t.rfind('.'); - size_t pathstart = t.find("gfx/"); - if(dotpos == std::string::npos || pathstart == std::string::npos || dotpos < pathstart) - return; // whoops + // texture names are like: "naija/naija2-frontleg3" - no .png extension, and no gfx/ path + std::set*files = (std::set*)user; + std::string t = vf->fullname(); + size_t dotpos = t.rfind('.'); + size_t pathstart = t.find("gfx/"); + if(dotpos == std::string::npos || pathstart == std::string::npos || dotpos < pathstart) + return; // whoops - files->insert(t.substr(pathstart + 4, dotpos - (pathstart + 4))); + files->insert(t.substr(pathstart + 4, dotpos - (pathstart + 4))); } @@ -2184,20 +2184,19 @@ static void refr_insert(VFILE *vf, void *user) // thus directly using "gfx" subdir should be fine... void DSQ::refreshResourcesForPatch(const std::string& name) { - ttvfs::VFSDir *vd = vfs.GetDir((mod.getBaseModPath() + name + "/gfx").c_str()); // only textures are resources, anyways - if(!vd) - return; - - std::list left; + std::list left; std::set files; - left.push_back(vd); - + left.push_back(mod.getBaseModPath() + name + "/gfx"); + ttvfs::DirView view; do { - vd = left.front(); + std::string dirname = left.front(); left.pop_front(); - vd->forEachDir(refr_pushback, &left); - vd->forEachFile(refr_insert, &files); + if(vfs.FillDirView(dirname.c_str(), view)) + { + view.forEachDir(refr_pushback, &left); + view.forEachFile(refr_insert, &files); + } } while(left.size()); @@ -2205,11 +2204,14 @@ void DSQ::refreshResourcesForPatch(const std::string& name) os << "refreshResourcesForPatch - " << files.size() << " to refresh"; debugLog(os.str()); - for(int i = 0; i < dsq->resources.size(); ++i) + if(files.size()) { - Resource *r = dsq->resources[i]; - if(files.find(r->name) != files.end()) - r->reload(); + for(int i = 0; i < dsq->resources.size(); ++i) + { + Resource *r = dsq->resources[i]; + if(files.find(r->name) != files.end()) + r->reload(); + } } } #else @@ -2226,7 +2228,7 @@ void DSQ::applyPatch(const std::string& name) std::string src = mod.getBaseModPath(); src += name; debugLog("Apply patch: " + src); - vfs.Mount(src.c_str(), "", true); + vfs.Mount(src.c_str(), ""); activePatches.insert(name); refreshResourcesForPatch(name); @@ -2797,10 +2799,22 @@ bool DSQ::modIsKnown(const std::string& name) bool DSQ::mountModPackage(const std::string& pkg) { #ifdef BBGE_BUILD_VFS - ttvfs::VFSDir *vd = vfs.AddArchive(pkg.c_str(), false, mod.getBaseModPath().c_str()); + ttvfs::DirBase *vd = vfs.GetDir(pkg.c_str()); if (!vd) { - debugLog("Package: Unable to load " + pkg); + // Load archive only if no such directory exists already (prevent loading multiple times) + vd = vfs.AddArchive(pkg.c_str()); + if(vd) + debugLog("Package: Loaded file " + pkg); + else + { + debugLog("Package: Unable to load " + pkg); + return false; + } + } + if(!vfs.Mount(pkg.c_str(), mod.getBaseModPath().c_str())) + { + debugLog("Package: Failed to mount: " + pkg); return false; } debugLog("Package: Mounted " + pkg + " as archive in _mods"); @@ -2812,12 +2826,9 @@ bool DSQ::mountModPackage(const std::string& pkg) } #ifdef BBGE_BUILD_VFS -static void _CloseSubdirCallback(ttvfs::VFSDir *vd, void*) +static void _CloseSubdirCallback(ttvfs::DirBase *vd, void*) { vd->close(); - ttvfs::VFSBase *origin = vd->getOrigin(); - if(origin) - origin->close(); } #endif @@ -2825,9 +2836,9 @@ static void _CloseSubdirCallback(ttvfs::VFSDir *vd, void*) void DSQ::unloadMods() { #ifdef BBGE_BUILD_VFS - ttvfs::VFSDir *mods = vfs.GetDir(mod.getBaseModPath().c_str()); - if(mods) - mods->forEachDir(_CloseSubdirCallback); + ttvfs::DirView view; + if(vfs.FillDirView(mod.getBaseModPath().c_str(), view)) + view.forEachDir(_CloseSubdirCallback); #endif } diff --git a/Aquaria/ModDownloader.cpp b/Aquaria/ModDownloader.cpp index 2a34ed3..30bb2b7 100644 --- a/Aquaria/ModDownloader.cpp +++ b/Aquaria/ModDownloader.cpp @@ -108,10 +108,6 @@ void ModDL::init() { tempDir = dsq->getUserDataFolder() + "/webcache"; createDir(tempDir.c_str()); - - ttvfs::VFSDir *vd = vfs.GetDir(tempDir.c_str()); - if(vd) - vd->load(false); } bool ModDL::hasUrlFileCached(const std::string& url) @@ -372,7 +368,7 @@ bool ModDL::ParseModXML(const std::string& fn, bool allowChaining) std::string localIcon = remoteToLocalName(iconurl); size_t localIconSize = 0; - if(ttvfs::VFSFile *vf = vfs.GetFile(localIcon.c_str())) + if(ttvfs::File *vf = vfs.GetFile(localIcon.c_str())) { localIconSize = vf->size(); } @@ -396,7 +392,7 @@ bool ModDL::ParseModXML(const std::string& fn, bool allowChaining) { std::string modpkg = dsq->mod.getBaseModPath() + localname; modpkg += ".aqmod"; - ttvfs::VFSFile *vf = vfs.GetFile(modpkg.c_str()); + ttvfs::File *vf = vfs.GetFile(modpkg.c_str()); if(vf) { size_t sz = vf->size(); @@ -498,13 +494,9 @@ void ModDL::NotifyMod(ModRequest *rq, NetEvent ev, size_t recvd, size_t total) // the mod file can already exist, and if it does, it will most likely be mounted. // zip archives are locked and cannot be deleted/replaced, so we need to unload it first. // this effectively closes the file handle only, nothing else. - ttvfs::VFSDir *vd = vfs.GetDir(moddir.c_str()); + ttvfs::DirBase *vd = vfs.GetDir(moddir.c_str()); if(vd) - { - ttvfs::VFSBase *origin = vd->getOrigin(); - if(origin) - origin->close(); - } + vd->close(); std::string archiveFile = moddir + ".aqmod"; @@ -520,8 +512,7 @@ void ModDL::NotifyMod(ModRequest *rq, NetEvent ev, size_t recvd, size_t total) if(vd) { - // Dir already exists, just remount everything - vfs.Reload(); + // Nothing to do } else if(!dsq->mountModPackage(archiveFile)) { diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 503f68b..fe78cdb 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -815,16 +815,17 @@ static bool findFile_helper(const char *rawname, std::string &fname) static int loadFile_helper(lua_State *L, const char *fn) { #ifdef BBGE_BUILD_VFS - VFILE *vf = vfs.GetFile(fn); - if (!vf) + unsigned long size = 0; + const char *data = readFile(fn, &size); + if (!data) { lua_pushfstring(L, "cannot open %s", fn); return LUA_ERRFILE; } else { - int result = luaL_loadbuffer(L, (const char*)vf->getBuf(), vf->size(), fn); - vf->dropBuf(true); + int result = luaL_loadbuffer(L, data, size, fn); + delete [] data; return result; } #else diff --git a/BBGE/Base.cpp b/BBGE/Base.cpp index 65b98f7..4db485d 100644 --- a/BBGE/Base.cpp +++ b/BBGE/Base.cpp @@ -43,6 +43,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include +#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; // ------------------------------------- diff --git a/BBGE/Base.h b/BBGE/Base.h index 805fd79..e1aa120 100644 --- a/BBGE/Base.h +++ b/BBGE/Base.h @@ -141,7 +141,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Rect.h" #include "math.h" -#include "FileAPI.h" +#include "ttvfs_stdio.h" #ifdef BBGE_BUILD_LINUX # include @@ -173,16 +173,6 @@ enum Direction #include "Vector.h" -#define FOR_ALL(object, type, object_iterator)\ - {\ - for (type::iterator object_iterator = object.begin(); object_iterator != object.end(); ++object_iterator)\ - {\ - -#define END_FOR_ALL\ - }\ - }\ - - const float SQRT2 = 1.41421356; const float PI = 3.14159265; @@ -304,5 +294,8 @@ void triggerBreakpoint(); bool createDir(const std::string& d); +#ifdef BBGE_BUILD_VFS +extern ttvfs::Root vfs; // in Base.cpp +#endif #endif diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 459ceb3..b7cb112 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -5136,34 +5136,22 @@ void Core::setupFileAccess() if(!ttvfs::checkCompat()) exit_error("ttvfs not compatible"); - vfs.AddArchiveLoader(new ttvfs::VFSZipArchiveLoader); - - if(!vfs.LoadFileSysRoot(false)) - { - exit_error("Failed to setup file access"); - } - - vfs.Prepare(); + ttvfs_setroot(&vfs); + vfs.AddLoader(new ttvfs::DiskLoader); + vfs.AddArchiveLoader(new ttvfs::VFSZipArchiveLoader); - ttvfs::VFSDir *override = vfs.GetDir("override"); - if(override) - { - debugLog("Mounting override dir..."); - override->load(true); - vfs.Mount("override", "", true); - } + vfs.Mount("override", ""); // If we ever want to read from a container... - //vfs.AddArchive("aqfiles.zip", false, ""); + //vfs.AddArchive("aqfiles.zip"); if(_extraDataDir.length()) { debugLog("Mounting extra data dir: " + _extraDataDir); - vfs.MountExternalPath(_extraDataDir.c_str(), "", true, true); + vfs.Mount(_extraDataDir.c_str(), ""); } - debugLog("Done"); #endif } diff --git a/BBGE/FmodOpenALBridge.cpp b/BBGE/FmodOpenALBridge.cpp index 320f4b4..23b88cb 100644 --- a/BBGE/FmodOpenALBridge.cpp +++ b/BBGE/FmodOpenALBridge.cpp @@ -42,7 +42,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "ogg/ogg.h" #include "vorbis/vorbisfile.h" -#include "FileAPI.h" #include "MT.h" #ifndef _DEBUG @@ -1488,7 +1487,6 @@ FMOD_RESULT OpenALSystem::createSound(const char *name_or_data, const FMOD_MODE long nread = vfread(data, 1, size, io); vfclose(io); - vfclear(io); if (nread != size) { debugLog("Failed to read data from " + std::string(fname)); diff --git a/BBGE/Texture.cpp b/BBGE/Texture.cpp index 97cd22b..9f04a4c 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -437,19 +437,11 @@ void Texture::loadPNG(const std::string &file) pngType = PNG_LUMINANCEALPHA; } -#ifdef BBGE_BUILD_VFS - ttvfs::VFSFile *vf = vfs.GetFile(file.c_str()); - const char *memptr = vf ? (const char*)vf->getBuf() : NULL; - if(!memptr) - { - debugLog("Can't load PNG file: " + file); - width = 64; - height = 64; - Texture::textureError = TEXERR_FILENOTFOUND; - return; - } + unsigned long memsize = 0; + const char *memptr = readFile(file, &memsize); + if(!memptr || !memsize) + goto fail; - int memsize = vf->size(); if (filter == GL_NEAREST) { textures[0] = pngBindMem(memptr, memsize, PNG_NOMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, filter, filter); @@ -458,18 +450,6 @@ void Texture::loadPNG(const std::string &file) { textures[0] = pngBindMem(memptr, memsize, PNG_BUILDMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, GL_LINEAR_MIPMAP_LINEAR, filter); } - vf->dropBuf(true); - -#else - if (filter == GL_NEAREST) - { - textures[0] = pngBind(file.c_str(), PNG_NOMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, filter, filter); - } - else - { - textures[0] = pngBind(file.c_str(), PNG_BUILDMIPMAPS, pngType, &info, GL_CLAMP_TO_EDGE, GL_LINEAR_MIPMAP_LINEAR, filter); - } -#endif if (textures[0] != 0) { @@ -478,12 +458,16 @@ void Texture::loadPNG(const std::string &file) } else { + fail: + debugLog("Can't load PNG file: " + file); width = 64; height = 64; Texture::textureError = TEXERR_FILENOTFOUND; } + if(memptr) + delete [] memptr; #endif } diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c2d623..ea7c03b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -236,7 +236,7 @@ INCLUDE_DIRECTORIES(${OGGVORBIS_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${EXTLIBDIR}) -INCLUDE_DIRECTORIES(${EXTLIBDIR}/ttvfs) + # Custom build ID: e.g. "-custom", " (my very own build)" @@ -280,6 +280,10 @@ ADD_DEFINITIONS(-DBBGE_BUILD_OPENGL_DYNAMIC=1) ADD_DEFINITIONS(-DBBGE_BUILD_FMOD_OPENAL_BRIDGE=1) IF(AQUARIA_USE_VFS) ADD_DEFINITIONS(-DBBGE_BUILD_VFS=1) + ADD_DEFINITIONS(-VFS_ENABLE_C_API=1) + INCLUDE_DIRECTORIES(${EXTLIBDIR}/ttvfs) + INCLUDE_DIRECTORIES(${EXTLIBDIR}/ttvfs_zip) + INCLUDE_DIRECTORIES(${EXTLIBDIR}/ttvfs_cfileapi) ENDIF(AQUARIA_USE_VFS) IF(AQUARIA_USE_SDL2) @@ -680,8 +684,10 @@ SET(LUA_SRCS IF(AQUARIA_USE_VFS) ADD_SUBDIRECTORY("${EXTLIBDIR}/ttvfs") ADD_SUBDIRECTORY("${EXTLIBDIR}/ttvfs_zip") + ADD_SUBDIRECTORY("${EXTLIBDIR}/ttvfs_cfileapi") SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "ttvfs") SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "ttvfs_zip") + SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "ttvfs_cfileapi") ENDIF(AQUARIA_USE_VFS) IF(WIN32) diff --git a/ExternalLibs/FileAPI.cpp b/ExternalLibs/FileAPI.cpp deleted file mode 100644 index 02b0378..0000000 --- a/ExternalLibs/FileAPI.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#ifdef BBGE_BUILD_VFS - -#include "FileAPI.h" -#include "ttvfs_zip/VFSZipArchiveLoader.h" -#include - - -ttvfs::VFSHelper vfs; - - -VFILE *vfopen(const char *fn, const char *mode) -{ - if (strchr(mode, 'w')) - { - fprintf(stderr, "FileAPI.h: File writing via VFS not yet supported!"); - return NULL; - } - - VFILE *vf = vfs.GetFile(fn); - if (!vf || !vf->open(mode)) - return NULL; - ++(vf->ref); // keep the file alive until closed. - return vf; -} - -size_t vfread(void *ptr, size_t size, size_t count, VFILE *vf) -{ - return vf->read(ptr, size * count) / size; -} - -int vfclose(VFILE *vf) -{ - bool closed = vf->close(); - vf->ref--; - return closed ? 0 : EOF; -} - -size_t vfwrite(const void *ptr, size_t size, size_t count, VFILE *vf) -{ - return vf->write(ptr, size * count) / size; -} - -// return 0 on success, -1 on error -int vfseek(VFILE *vf, long int offset, int origin) -{ - bool ok = false; - switch(origin) - { - case SEEK_SET: ok = vf->seek(offset); break; - case SEEK_CUR: ok = vf->seekRel(offset); break; - case SEEK_END: ok = vf->seek((long int)(vf->size() - offset)); break; - } - return ok ? 0 : -1; -} - -char *vfgets(char *str, int num, VFILE *vf) -{ - char *s = str; - if (vf->iseof()) - return NULL; - char *ptr = (char*)vf->getBuf() + vf->getpos(); - unsigned int remain = int(vf->size() - vf->getpos()); - if (remain < (unsigned int)num) - num = remain; - else - --num; // be sure to keep space for the final null char - int i = 0; - char c; - for( ; i < num && *ptr; ++i) - { - c = (*s++ = *ptr++); - if(c == '\n' || c == '\r') - { - ++i; - c = *ptr++; // because windows linebreaks suck. - if(c == '\n' || c == '\r') - ++i; - break; - } - } - - vf->seekRel(i); - *s++ = 0; - return str; -} - -void vfclear(VFILE *vf) -{ - vf->dropBuf(true); -} - -long int vftell(VFILE *vf) -{ - return (long int)vf->getpos(); -} - - -InStream::InStream(const std::string& fn) -: std::istringstream() -{ - open(fn.c_str()); -} - -InStream::InStream(const char *fn) -: std::istringstream() -{ - open(fn); -} - -bool InStream::open(const char *fn) -{ - ttvfs::VFSFile *vf = vfs.GetFile(fn); - if(vf) - { - vf->open("r"); - str((char*)vf->getBuf()); // stringstream will always make a copy - vf->close(); - vf->dropBuf(true); - return true; - } - setstate(std::ios::failbit); - return false; -} - -#endif diff --git a/ExternalLibs/FileAPI.h b/ExternalLibs/FileAPI.h deleted file mode 100644 index 6641c2c..0000000 --- a/ExternalLibs/FileAPI.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef FILE_API_H -#define FILE_API_H - -// TODO: need VFS output functions? - -#ifdef BBGE_BUILD_VFS - -#include "ttvfs/VFS.h" -#include - -extern ttvfs::VFSHelper vfs; -typedef ttvfs::VFSFile VFILE; - - -VFILE *vfopen(const char *fn, const char *mode); -size_t vfread(void *ptr, size_t size, size_t count, VFILE *vf); -int vfclose(VFILE *vf); -size_t vfwrite(const void *ptr, size_t size, size_t count, VFILE *vf); -int vfseek(VFILE *vf, long int offset, int origin); -char *vfgets(char *str, int num, VFILE *vf); -void vfclear(VFILE *vf); -long int vftell(VFILE *vf); - -// This class is a minimal adapter to support STL-like read-only file streams for VFS files, using std::istringstream. -class InStream : public std::istringstream -{ -public: - InStream(const char *fn); - InStream(const std::string& fn); - bool open(const char *fn); - inline bool is_open() { return good(); } - inline void close() {} -private: - void _init(const char *fn); -}; - -#else // BBGE_BUILD_VFS - -#include -#include -typedef std::ifstream InStream; -typedef FILE VFILE; -#define vfopen fopen -#define vfread fread -#define vfclose fclose -#define vfwrite fwrite -#define vfseek fseek -#define vfgets fgets -#define vftell ftell -#define vfclear - -#endif // BBGE_BUILD_VFS - - -#endif // FILE_API_H diff --git a/ExternalLibs/glfont2/glfont2.cpp b/ExternalLibs/glfont2/glfont2.cpp index bb8e9ca..93cd491 100644 --- a/ExternalLibs/glfont2/glfont2.cpp +++ b/ExternalLibs/glfont2/glfont2.cpp @@ -7,7 +7,7 @@ //STL headers #include -#include "FileAPI.h" +#include "ttvfs_stdio.h" #include "ByteBuffer.h" using namespace std; @@ -53,26 +53,22 @@ bool GLFont::Create (const char *file_name, int tex, bool loadTexture) //Destroy the old font if there was one, just to be safe Destroy(); - -#ifdef BBGE_BUILD_VFS - //Open input file - ttvfs::VFSFile *vf = vfs.GetFile(file_name); - if (!vf) - return false; - ByteBuffer bb((void*)vf->getBuf(), vf->size(), ByteBuffer::TAKE_OVER); - vf->dropBuf(false); -#else + VFILE *fh = vfopen(file_name, "rb"); if (!fh) return false; - vfseek(fh, 0, SEEK_END); - long int sz = vftell(fh); - vfseek(fh, 0, SEEK_SET); + + size_t sz = 0; + if(vfsize(fh, &sz) < 0) + { + vfclose(fh); + return false; + } + ByteBuffer bb(sz); bb.resize(sz); vfread(bb.contents(), 1, sz, fh); vfclose(fh); -#endif // Read the header from file header.tex = tex; diff --git a/ExternalLibs/tinyxml.cpp b/ExternalLibs/tinyxml.cpp index e44627c..3f73156 100644 --- a/ExternalLibs/tinyxml.cpp +++ b/ExternalLibs/tinyxml.cpp @@ -953,17 +953,10 @@ bool TiXmlDocument::LoadFile( VFILE* file, TiXmlEncoding encoding ) location.Clear(); // Get the file size, so we can pre-allocate the string. HUGE speed impact. - long length = 0; -#ifdef BBGE_BUILD_VFS - length = file->size(); -#else - fseek( file, 0, SEEK_END ); - length = ftell( file ); - fseek( file, 0, SEEK_SET ); -#endif + size_t length = 0; // Strange case, but good to handle up front. - if ( length <= 0 ) + if ( vfsize(file, &length) < 0 || length <= 0 ) { SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; @@ -990,15 +983,6 @@ bool TiXmlDocument::LoadFile( VFILE* file, TiXmlEncoding encoding ) } */ -#ifdef BBGE_BUILD_VFS - char *buf = (char*)file->getBuf(); - file->dropBuf(false); - if (!buf) - { - SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); - return false; - } -#else char* buf = new char[ length+1 ]; buf[0] = 0; @@ -1007,7 +991,6 @@ bool TiXmlDocument::LoadFile( VFILE* file, TiXmlEncoding encoding ) SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); return false; } -#endif return LoadMem(buf, length, encoding); } diff --git a/ExternalLibs/tinyxml.h b/ExternalLibs/tinyxml.h index dd0b7a9..9bfa1a0 100644 --- a/ExternalLibs/tinyxml.h +++ b/ExternalLibs/tinyxml.h @@ -36,7 +36,7 @@ distribution. #pragma warning( disable : 4786 ) #endif -#include "FileAPI.h" +#include "ttvfs_stdio.h" #include #include diff --git a/win/vc90/Aquaria.vcproj b/win/vc90/Aquaria.vcproj index 207d1da..0b704d5 100644 --- a/win/vc90/Aquaria.vcproj +++ b/win/vc90/Aquaria.vcproj @@ -41,8 +41,8 @@ - - - - @@ -1065,7 +1057,7 @@ Name="ttvfs" > + + + + + + + + @@ -1188,6 +1196,14 @@ RelativePath="..\..\ExternalLibs\ttvfs_zip\VFSZipArchiveLoader.h" > + + + + + + + + + +