#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...
int matchpattern(const char *in, const char *pattern, int caseinsensitive)
#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));
+ 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)