X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=filematch.c;h=e06439614c2174927168128adf5b1fcbe8fa268d;hp=42f9f9dbcbeb8f3d0e31d64d6138a51112ddae9e;hb=49f0e1cbc8bc4ea8a165e8b86092c40bf4599a8e;hpb=e97faa7f06e7821c32fb675cecb474e07ce55df6 diff --git a/filematch.c b/filematch.c index 42f9f9db..e0643961 100644 --- a/filematch.c +++ b/filematch.c @@ -5,9 +5,9 @@ #include #endif -#include "quakedef.h" +#include "darkplaces.h" -// LordHavoc: some portable directory listing code I wrote for lmp2pcx, now used in darkplaces to load id1/*.pak and such... +// LadyHavoc: some portable directory listing code I wrote for lmp2pcx, now used in darkplaces to load id1/*.pak and such... int matchpattern(const char *in, const char *pattern, int caseinsensitive) { @@ -16,7 +16,7 @@ int matchpattern(const char *in, const char *pattern, int caseinsensitive) // wildcard_least_one: if true * matches 1 or more characters // if false * matches 0 or more characters -int matchpattern_with_separator(const char *in, const char *pattern, int caseinsensitive, const char *separators, qboolean wildcard_least_one) +int matchpattern_with_separator(const char *in, const char *pattern, int caseinsensitive, const char *separators, qbool wildcard_least_one) { int c1, c2; while (*pattern) @@ -122,9 +122,11 @@ static int stringlistsort_cmp(const void *a, const void *b) return strcasecmp(*(const char **)a, *(const char **)b); } -void stringlistsort(stringlist_t *list, qboolean uniq) +void stringlistsort(stringlist_t *list, qbool uniq) { int i, j; + if(list->numstrings < 1) + return; qsort(&list->strings[0], list->numstrings, sizeof(list->strings[0]), stringlistsort_cmp); if(uniq) { @@ -162,8 +164,7 @@ static void adddirentry(stringlist_t *list, const char *path, const char *name) #ifdef WIN32 void listdirectory(stringlist_t *list, const char *basepath, const char *path) { - int i; - char pattern[4096], *c; + char pattern[4096]; WIN32_FIND_DATA n_file; HANDLE hFile; strlcpy (pattern, basepath, sizeof(pattern)); @@ -177,12 +178,6 @@ void listdirectory(stringlist_t *list, const char *basepath, const char *path) adddirentry(list, path, n_file.cFileName); } while (FindNextFile(hFile, &n_file) != 0); FindClose(hFile); - - // convert names to lowercase because windows does not care, but pattern matching code often does - for (i = 0;i < list->numstrings;i++) - for (c = list->strings[i];*c;c++) - if (*c >= 'A' && *c <= 'Z') - *c += 'a' - 'A'; } #else void listdirectory(stringlist_t *list, const char *basepath, const char *path) @@ -190,10 +185,36 @@ void listdirectory(stringlist_t *list, const char *basepath, const char *path) char fullpath[MAX_OSPATH]; DIR *dir; struct dirent *ent; - dpsnprintf(fullpath, sizeof(fullpath), "%s%s", basepath, *path ? path : "./"); + dpsnprintf(fullpath, sizeof(fullpath), "%s%s", basepath, path); +#ifdef __ANDROID__ + // SDL currently does not support listing assets, so we have to emulate + // it. We're using relative paths for assets, so that will do. + if (basepath[0] != '/') + { + char listpath[MAX_OSPATH]; + qfile_t *listfile; + dpsnprintf(listpath, sizeof(listpath), "%sls.txt", fullpath); + char *buf = (char *) FS_SysLoadFile(listpath, tempmempool, true, NULL); + if (!buf) + return; + char *p = buf; + for (;;) + { + char *q = strchr(p, '\n'); + if (q == NULL) + break; + *q = 0; + adddirentry(list, path, p); + p = q + 1; + } + Mem_Free(buf); + return; + } +#endif dir = opendir(fullpath); if (!dir) return; + while ((ent = readdir(dir))) adddirentry(list, path, ent->d_name); closedir(dir);