mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-07 14:51:08 +00:00
Update ttvfs to new version
This commit is contained in:
parent
209ad526c6
commit
8026cdd905
43 changed files with 2124 additions and 2427 deletions
74
ExternalLibs/ttvfs/VFSDirView.cpp
Normal file
74
ExternalLibs/ttvfs/VFSDirView.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
#include "VFSDirView.h"
|
||||
#include "VFSFile.h"
|
||||
|
||||
VFS_NAMESPACE_START
|
||||
|
||||
|
||||
DirView::DirView()
|
||||
: DirBase("")
|
||||
{
|
||||
}
|
||||
|
||||
DirView::~DirView()
|
||||
{
|
||||
}
|
||||
|
||||
void DirView::init(const char *name)
|
||||
{
|
||||
_setName(name);
|
||||
_view.clear();
|
||||
}
|
||||
|
||||
void DirView::add(DirBase *dir)
|
||||
{
|
||||
for(ViewList::iterator it = _view.begin(); it != _view.end(); ++it)
|
||||
if(it->content() == dir)
|
||||
return;
|
||||
_view.push_back(dir);
|
||||
}
|
||||
|
||||
File *DirView::getFileByName(const char *fn, bool lazyLoad /* = true */)
|
||||
{
|
||||
for(ViewList::reverse_iterator it = _view.rbegin(); it != _view.rend(); ++it)
|
||||
if(File *f = (*it)->getFileByName(fn))
|
||||
return f;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void DirView::forEachDir(DirEnumCallback f, void *user, bool safe)
|
||||
{
|
||||
for(ViewList::reverse_iterator it = _view.rbegin(); it != _view.rend(); ++it)
|
||||
(*it)->forEachDir(f, user, safe);
|
||||
}
|
||||
|
||||
static void _addFileCallback(File *f, void *p)
|
||||
{
|
||||
((Files*)p)->insert(std::make_pair(f->name(), f)); // only inserts if not exist
|
||||
}
|
||||
void DirView::forEachFile(FileEnumCallback f, void *user, bool /*ignored*/)
|
||||
{
|
||||
Files flist; // TODO: optimize allocation
|
||||
for(ViewList::reverse_iterator it = _view.rbegin(); it != _view.rend(); ++it)
|
||||
(*it)->forEachFile(_addFileCallback, &flist);
|
||||
|
||||
for(Files::iterator it = flist.begin(); it != flist.end(); ++it)
|
||||
f(it->second, user);
|
||||
}
|
||||
|
||||
bool DirView::_addToView(char *path, DirView& view)
|
||||
{
|
||||
if(_view.empty())
|
||||
return false;
|
||||
|
||||
for(ViewList::const_iterator it = _view.begin(); it != _view.end(); ++it) // not reverse!
|
||||
view.add(const_cast<DirBase*>(it->content()));
|
||||
return true;
|
||||
}
|
||||
|
||||
static void __test__()
|
||||
{
|
||||
new DirView;
|
||||
}
|
||||
|
||||
VFS_NAMESPACE_END
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue