2004-08-24 04:26:32 -07:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "VFSUtil.h"
|
2005-08-12 10:06:53 -07:00
|
|
|
#include "lib/res/file/vfs.h"
|
2004-08-24 04:26:32 -07:00
|
|
|
|
|
|
|
|
#include "CLogger.h"
|
|
|
|
|
#define LOG_CATEGORY "vfs"
|
|
|
|
|
|
2005-05-17 22:32:09 -07:00
|
|
|
#include <deque>
|
|
|
|
|
|
2004-08-24 04:26:32 -07:00
|
|
|
using namespace VFSUtil;
|
|
|
|
|
|
|
|
|
|
// Because I'm lazy, and it saves a few lines of code in other places:
|
2005-03-29 12:50:04 -08:00
|
|
|
bool VFSUtil::FindFiles (const CStr& dirname, const char* filter, FileList& files)
|
2004-08-24 04:26:32 -07:00
|
|
|
{
|
|
|
|
|
files.clear();
|
|
|
|
|
|
2005-08-09 08:55:44 -07:00
|
|
|
Handle dir = vfs_dir_open(dirname);
|
2004-08-24 04:26:32 -07:00
|
|
|
if (dir <= 0)
|
|
|
|
|
{
|
|
|
|
|
LOG(ERROR, LOG_CATEGORY, "Error opening directory '%s' (%lld)", dirname.c_str(), dir);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int err;
|
2005-08-09 08:55:44 -07:00
|
|
|
DirEnt entry;
|
|
|
|
|
while ((err = vfs_dir_next_ent(dir, &entry, filter)) == 0)
|
2004-08-24 04:26:32 -07:00
|
|
|
{
|
2006-05-17 07:48:18 -07:00
|
|
|
CStr path = dirname+entry.name;
|
|
|
|
|
if(DIRENT_IS_DIR(&entry))
|
|
|
|
|
path += '/';
|
|
|
|
|
files.push_back(path);
|
2004-08-24 04:26:32 -07:00
|
|
|
}
|
2004-11-23 13:11:00 -08:00
|
|
|
|
2004-12-01 13:37:01 -08:00
|
|
|
if (err != ERR_DIR_END)
|
2004-08-24 04:26:32 -07:00
|
|
|
{
|
|
|
|
|
LOG(ERROR, LOG_CATEGORY, "Error reading files from directory '%s' (%d)", dirname.c_str(), err);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-09 08:55:44 -07:00
|
|
|
vfs_dir_close(dir);
|
2004-08-24 04:26:32 -07:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
2004-11-07 13:30:47 -08:00
|
|
|
}
|
2005-03-26 17:44:41 -08:00
|
|
|
|