now identical handling to linux.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@570 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2004-12-05 11:40:15 +00:00
parent b255ce926b
commit c692ef4d5e

View file

@ -246,6 +246,40 @@ qboolean Sys_remove (char *path)
return true; return true;
} }
//1 if match
int wildcmp(char *wild, char *string) {
char *cp=NULL, *mp=NULL;
while ((*string) && (*wild != '*')) {
if ((*wild != *string) && (*wild != '?')) {
return 0;
}
wild++;
string++;
}
while (*string) {
if (*wild == '*') {
if (!*++wild) {
return 1;
}
mp = wild;
cp = string+1;
} else if ((*wild == *string) || (*wild == '?')) {
wild++;
string++;
} else {
wild = mp;
string = cp++;
}
}
while (*wild == '*') {
wild++;
}
return !*wild;
}
int Sys_EnumerateFiles (char *gpath, char *match, int (*func)(char *, int, void *), void *parm) int Sys_EnumerateFiles (char *gpath, char *match, int (*func)(char *, int, void *), void *parm)
{ {
HANDLE r; HANDLE r;
@ -254,37 +288,54 @@ int Sys_EnumerateFiles (char *gpath, char *match, int (*func)(char *, int, void
char file[MAX_OSPATH]; char file[MAX_OSPATH];
char *s; char *s;
int go; int go;
strcpy(apath, match); if (!gpath)
// sprintf(apath, "%s%s", gpath, match); return 0;
for (s = apath+strlen(apath)-1; s>= apath; s--) // strcpy(apath, match);
sprintf(apath, "%s/%s", gpath, match);
for (s = apath+strlen(apath)-1; s> apath; s--)
{ {
if (*s == '/') if (*s == '/')
break; break;
} }
s++; *s = '\0';
*s = '\0';
//this is what we ask windows for.
sprintf(file, "%s/*.*", apath);
//we need to make apath contain the path in match but not gpath
strcpy(apath, match);
match = s+1;
for (s = apath+strlen(apath)-1; s> apath; s--)
{
if (*s == '/')
break;
}
*s = '\0';
if (s != apath)
strcat(apath, "/");
if (gpath)
sprintf(file, "%s/%s", gpath, match);
else
strcpy(file, match);
r = FindFirstFile(file, &fd); r = FindFirstFile(file, &fd);
if (r==(HANDLE)-1) if (r==(HANDLE)-1)
return 1; return 1;
go = true; go = true;
do do
{ {
if (*fd.cFileName == '.'); if (*fd.cFileName == '.'); //don't ever find files with a name starting with '.'
else if (fd.dwFileAttributes != 16) //is a directory else if (fd.dwFileAttributes != 16) //is a directory
{ {
sprintf(file, "%s%s", apath, fd.cFileName); if (wildcmp(match, fd.cFileName))
go = func(file, fd.nFileSizeLow, parm); {
sprintf(file, "%s%s", apath, fd.cFileName);
go = func(file, fd.nFileSizeLow, parm);
}
} }
else else
{ {
sprintf(file, "%s%s/", apath, fd.cFileName); if (wildcmp(match, fd.cFileName))
go = func(file, fd.nFileSizeLow, parm); {
sprintf(file, "%s%s/", apath, fd.cFileName);
go = func(file, fd.nFileSizeLow, parm);
}
} }
} }
while(FindNextFile(r, &fd) && go); while(FindNextFile(r, &fd) && go);