X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=filematch.c;h=b95951d7089ecdc14d0b8d2b67f19b483f271501;hb=HEAD;hp=47aeb35e21ae2be1720d5aa936e833cec4a6c62a;hpb=0a05c446ba26bd5897645a37ceec8646c5bc93eb;p=xonotic%2Fdarkplaces.git diff --git a/filematch.c b/filematch.c index 47aeb35e..38ee0372 100644 --- a/filematch.c +++ b/filematch.c @@ -5,7 +5,11 @@ #include #endif -#include "quakedef.h" +#include "darkplaces.h" + +#ifdef WIN32 +#include "utf8lib.h" +#endif // LadyHavoc: some portable directory listing code I wrote for lmp2pcx, now used in darkplaces to load id1/*.pak and such... @@ -164,20 +168,31 @@ 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) { - char pattern[4096]; - WIN32_FIND_DATA n_file; + #define BUFSIZE 4096 + char pattern[BUFSIZE] = {0}; + wchar patternw[BUFSIZE] = {0}; + char filename[BUFSIZE] = {0}; + wchar *filenamew; + int lenw = 0; + WIN32_FIND_DATAW n_file; HANDLE hFile; - strlcpy (pattern, basepath, sizeof(pattern)); - strlcat (pattern, path, sizeof (pattern)); - strlcat (pattern, "*", sizeof (pattern)); + dp_strlcpy(pattern, basepath, sizeof(pattern)); + dp_strlcat(pattern, path, sizeof (pattern)); + dp_strlcat(pattern, "*", sizeof (pattern)); + fromwtf8(pattern, strlen(pattern), patternw, BUFSIZE); // ask for the directory listing handle - hFile = FindFirstFile(pattern, &n_file); + hFile = FindFirstFileW(patternw, &n_file); if(hFile == INVALID_HANDLE_VALUE) return; do { - adddirentry(list, path, n_file.cFileName); - } while (FindNextFile(hFile, &n_file) != 0); + filenamew = n_file.cFileName; + lenw = 0; + while(filenamew[lenw] != 0) ++lenw; + towtf8(filenamew, lenw, filename, BUFSIZE); + adddirentry(list, path, filename); + } while (FindNextFileW(hFile, &n_file) != 0); FindClose(hFile); + #undef BUFSIZE } #else void listdirectory(stringlist_t *list, const char *basepath, const char *path)