From 8901f51133f94a1bc9b57455aee0404ab9f19d48 Mon Sep 17 00:00:00 2001 From: Mark Olsen Date: Mon, 11 Jan 2010 18:15:42 +0000 Subject: [PATCH] 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 --- engine/client/sys_linux.c | 33 +++++++++++++++------------------ engine/server/sv_sys_unix.c | 33 +++++++++++++++------------------ 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/engine/client/sys_linux.c b/engine/client/sys_linux.c index b28d9e8a..a564761d 100644 --- a/engine/client/sys_linux.c +++ b/engine/client/sys_linux.c @@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #ifndef __CYGWIN__ #include #include @@ -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 - 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); diff --git a/engine/server/sv_sys_unix.c b/engine/server/sv_sys_unix.c index aba86331..83419d88 100644 --- a/engine/server/sv_sys_unix.c +++ b/engine/server/sv_sys_unix.c @@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #ifdef MULTITHREAD #include @@ -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 - 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);