Fixed Sys_EnumerateFiles(): Doesn't treat directories as files anymore and actually manages to figure out file sizes now.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3494 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Mark Olsen 2010-01-11 18:15:42 +00:00
parent af15a5945c
commit 8901f51133
2 changed files with 30 additions and 36 deletions

View File

@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdarg.h>
#include <stdio.h>
#include <dlfcn.h>
#include <dirent.h>
#ifndef __CYGWIN__
#include <sys/ipc.h>
#include <sys/shm.h>
@ -244,13 +245,13 @@ int Sys_DebugLog(char *file, char *fmt, ...)
int Sys_EnumerateFiles (const char *gpath, const char *match, int (*func)(const char *, int, void *), void *parm)
{
#include <dirent.h>
DIR *dir, *dir2;
DIR *dir;
char apath[MAX_OSPATH];
char file[MAX_OSPATH];
char truepath[MAX_OSPATH];
char *s;
struct dirent *ent;
struct stat st;
//printf("path = %s\n", gpath);
//printf("match = %s\n", match);
@ -291,29 +292,25 @@ int Sys_EnumerateFiles (const char *gpath, const char *match, int (*func)(const
if (!ent)
break;
if (*ent->d_name != '.')
{
if (wildcmp(match, ent->d_name))
{
Q_snprintfz(file, sizeof(file), "%s/%s", gpath, ent->d_name);
//would use stat, but it breaks on fat32.
Q_snprintfz(file, sizeof(file), "%s/%s", truepath, ent->d_name);
if ((dir2 = opendir(file)))
if (stat(file, &st) == 0)
{
closedir(dir2);
Q_snprintfz(file, sizeof(file), "%s%s/", apath, ent->d_name);
//printf("is directory = %s\n", file);
Q_snprintfz(file, sizeof(file), "%s%s%s", apath, ent->d_name, S_ISDIR(st.st_mode)?"/":"");
if (!func(file, st.st_size, parm))
{
closedir(dir);
return false;
}
}
else
{
Q_snprintfz(file, sizeof(file), "%s%s", apath, ent->d_name);
//printf("file = %s\n", file);
}
if (!func(file, -2, parm))
{
closedir(dir);
return false;
}
printf("Stat failed for \"%s\"\n", file);
}
}
} while(1);
closedir(dir);

View File

@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <sys/time.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#ifdef MULTITHREAD
#include <pthread.h>
@ -697,13 +698,13 @@ int main(int argc, char *argv[])
int Sys_EnumerateFiles (const char *gpath, const char *match, int (*func)(const char *, int, void *), void *parm)
{
#include <dirent.h>
DIR *dir, *dir2;
DIR *dir;
char apath[MAX_OSPATH];
char file[MAX_OSPATH];
char truepath[MAX_OSPATH];
char *s;
struct dirent *ent;
struct stat st;
//printf("path = %s\n", gpath);
//printf("match = %s\n", match);
@ -744,29 +745,25 @@ int Sys_EnumerateFiles (const char *gpath, const char *match, int (*func)(const
if (!ent)
break;
if (*ent->d_name != '.')
{
if (wildcmp(match, ent->d_name))
{
Q_snprintfz(file, sizeof(file), "%s/%s", gpath, ent->d_name);
//would use stat, but it breaks on fat32.
Q_snprintfz(file, sizeof(file), "%s/%s", truepath, ent->d_name);
if ((dir2 = opendir(file)))
if (stat(file, &st) == 0)
{
closedir(dir2);
Q_snprintfz(file, sizeof(file), "%s%s/", apath, ent->d_name);
//printf("is directory = %s\n", file);
Q_snprintfz(file, sizeof(file), "%s%s%s", apath, ent->d_name, S_ISDIR(st.st_mode)?"/":"");
if (!func(file, st.st_size, parm))
{
closedir(dir);
return false;
}
}
else
{
Q_snprintfz(file, sizeof(file), "%s%s", apath, ent->d_name);
//printf("file = %s\n", file);
}
if (!func(file, -2, parm))
{
closedir(dir);
return false;
}
printf("Stat failed for \"%s\"\n", file);
}
}
} while(1);
closedir(dir);