Use plain ASCII for directories.

This commit is contained in:
Themaister 2012-01-05 17:22:03 +01:00
parent 4812b632c3
commit d8b6aebe9a

45
file.c
View File

@ -42,11 +42,7 @@
#endif #endif
#elif defined(_XBOX) #elif defined(_XBOX)
#include <xtl.h> #include <xtl.h>
#define FindFirstFileW FindFirstFile
#define FindNextFileW FindNextFile
#ifdef _MSC_VER
#define setmode _setmode #define setmode _setmode
#endif
#else #else
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -830,16 +826,10 @@ char **dir_list_new(const char *dir, const char *ext)
char **dir_list = NULL; char **dir_list = NULL;
#ifdef _WIN32 #ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX) WIN32_FIND_DATA ffd;
WIN32_FIND_DATAW ffd;
wchar_t wchar_buf[PATH_MAX];
#else
LPWIN32_FIND_DATA ffd;
LPWSTR wchar_buf;
#endif
HANDLE hFind = INVALID_HANDLE_VALUE; HANDLE hFind = INVALID_HANDLE_VALUE;
char utf8_buf[PATH_MAX]; char path_buf[PATH_MAX];
if (strlcpy(utf8_buf, dir, sizeof(utf8_buf)) >= sizeof(utf8_buf)) if (strlcpy(utf8_buf, dir, sizeof(utf8_buf)) >= sizeof(utf8_buf))
goto error; goto error;
@ -852,14 +842,7 @@ char **dir_list_new(const char *dir, const char *ext)
goto error; goto error;
} }
if (MultiByteToWideChar(CP_UTF8, 0, utf8_buf, -1, wchar_buf, PATH_MAX) == 0) hFind = FindFirstFile(path_buf, &ffd);
goto error;
#ifdef _XBOX
hFind = FindFirstFile((LPCSTR)wchar_buf, ffd);
#else
hFind = FindFirstFileW(wchar_buf, &ffd);
#endif
if (hFind == INVALID_HANDLE_VALUE) if (hFind == INVALID_HANDLE_VALUE)
goto error; goto error;
#else #else
@ -883,19 +866,9 @@ char **dir_list_new(const char *dir, const char *ext)
{ {
// Not a perfect search of course, but hopefully good enough in practice. // Not a perfect search of course, but hopefully good enough in practice.
#ifdef _WIN32 #ifdef _WIN32
#ifdef _XBOX if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
if (ffd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
#else
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
#endif
continue; continue;
#ifdef _XBOX if (ext && !strstr(ffd.cFileName, ext))
if (WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)ffd->cFileName, -1, utf8_buf, PATH_MAX, NULL, NULL) == 0)
#else
if (WideCharToMultiByte(CP_UTF8, 0, ffd.cFileName, -1, utf8_buf, PATH_MAX, NULL, NULL) == 0)
#endif
continue;
if (ext && !strstr(utf8_buf, ext))
continue; continue;
#else #else
if (ext && !strstr(entry->d_name, ext)) if (ext && !strstr(entry->d_name, ext))
@ -909,7 +882,7 @@ char **dir_list_new(const char *dir, const char *ext)
strlcpy(dir_list[cur_ptr], dir, PATH_MAX); strlcpy(dir_list[cur_ptr], dir, PATH_MAX);
strlcat(dir_list[cur_ptr], "/", PATH_MAX); strlcat(dir_list[cur_ptr], "/", PATH_MAX);
#ifdef _WIN32 #ifdef _WIN32
strlcat(dir_list[cur_ptr], utf8_buf, PATH_MAX); strlcat(dir_list[cur_ptr], ffd.cFileName, PATH_MAX);
#else #else
strlcat(dir_list[cur_ptr], entry->d_name, PATH_MAX); strlcat(dir_list[cur_ptr], entry->d_name, PATH_MAX);
#endif #endif
@ -926,10 +899,8 @@ char **dir_list_new(const char *dir, const char *ext)
memset(dir_list + cur_ptr, 0, (cur_size - cur_ptr) * sizeof(char*)); memset(dir_list + cur_ptr, 0, (cur_size - cur_ptr) * sizeof(char*));
} }
} }
#if defined(_WIN32) && !defined(_XBOX) #if defined(_WIN32)
while (FindNextFileW(hFind, &ffd) != 0); while (FindNextFile(hFind, &ffd) != 0);
#else
while (FindNextFile(hFind, ffd) != 0);
#endif #endif
#ifdef _WIN32 #ifdef _WIN32