mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-17 03:49:28 +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
|
@ -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<ttvfs::VFSDir*> *li = (std::list<ttvfs::VFSDir*>*)user;
|
||||
li->push_back(vd);
|
||||
std::list<std::string> *li = (std::list<std::string>*)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<std::string>*files = (std::set<std::string>*)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<std::string>*files = (std::set<std::string>*)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<ttvfs::VFSDir*> left;
|
||||
std::list<std::string> left;
|
||||
std::set<std::string> 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
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue