1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 12:03:51 +00:00
Aquaria/ExternalLibs/ttvfs_zip/VFSDirZip.cpp

77 lines
1.6 KiB
C++
Raw Normal View History

#include "VFSFileZip.h"
#include "VFSDirZip.h"
#include "VFSTools.h"
#include "VFSInternal.h"
#include "miniz.h"
VFS_NAMESPACE_START
2014-04-06 17:19:33 +00:00
ZipDir::ZipDir(ZipArchiveRef *handle, const char *fullpath, bool canLoad)
: Dir(fullpath, NULL)
, _archiveHandle(handle)
, _canLoad(canLoad)
, _couldLoad(canLoad)
{
}
2014-04-06 17:19:33 +00:00
ZipDir::~ZipDir()
{
close();
}
2014-04-06 17:19:33 +00:00
void ZipDir::close()
{
2014-04-06 17:19:33 +00:00
_archiveHandle->close();
_canLoad = _couldLoad; // allow loading again after re-opening (in case archive was replaced)
}
2014-04-06 17:19:33 +00:00
DirBase *ZipDir::createNew(const char *fullpath) const
{
2014-04-06 17:19:33 +00:00
const ZipArchiveRef *czref = _archiveHandle;
ZipArchiveRef *zref = const_cast<ZipArchiveRef*>(czref);
return new ZipDir(zref, fullpath, false);
}
2014-04-06 17:19:33 +00:00
#define MZ ((mz_zip_archive*)_archiveHandle->mz)
void ZipDir::load()
{
2014-04-06 17:19:33 +00:00
if(!_canLoad)
return;
2014-04-06 17:19:33 +00:00
_archiveHandle->openRead();
2014-04-06 17:19:33 +00:00
const unsigned int files = mz_zip_reader_get_num_files(MZ);
2014-04-07 00:25:58 +00:00
const size_t len = fullnameLen() + 1; // +1 for trailing '/' when used as path name in addRecursive()
mz_zip_archive_file_stat fs;
for (unsigned int i = 0; i < files; ++i)
{
2014-04-06 17:19:33 +00:00
if(mz_zip_reader_is_file_encrypted(MZ, i))
continue;
2014-04-06 17:19:33 +00:00
if(!mz_zip_reader_file_stat(MZ, i, &fs))
continue;
2014-04-06 17:19:33 +00:00
if(mz_zip_reader_is_file_a_directory(MZ, i))
{
2014-04-15 13:04:33 +00:00
_createAndInsertSubtree(fs.m_filename);
continue;
2014-04-06 17:19:33 +00:00
}
if(getFile(fs.m_filename))
continue;
ZipFile *vf = new ZipFile(fs.m_filename, _archiveHandle, fs.m_file_index);
2017-01-12 22:52:59 +00:00
_addRecursiveSkip(vf, len);
}
2014-04-06 17:19:33 +00:00
_canLoad = false;
}
2014-04-06 17:19:33 +00:00
VFS_NAMESPACE_END