From 2912c039ee7ba1a9c177bf4f99829fa86d3a9475 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 3 Dec 2017 20:27:08 +1030 Subject: [PATCH 07/13] win32: support unicode directory names in GDir/GDirEntry --- goo/gfile.cc | 20 +++++++++++++++----- goo/gfile.h | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/goo/gfile.cc b/goo/gfile.cc index fe05de67..3eb78ced 100644 --- a/goo/gfile.cc +++ b/goo/gfile.cc @@ -57,6 +57,8 @@ #include #include #include "GooString.h" +#include "UTF.h" +#include "gmem.h" #include "gfile.h" // Some systems don't define this, so just make it something reasonably @@ -698,7 +700,9 @@ GDirEntry::GDirEntry(char *dirPath, char *nameA, GBool doStat) { #elif defined(ACORN) #else #ifdef _WIN32 - fa = GetFileAttributesA(fullPath->getCString()); + wchar_t *tmp_w = (wchar_t *)utf8ToUtf16(fullPath->getCString()); + fa = GetFileAttributesW(tmp_w); + gfree(tmp_w); dir = (fa != 0xFFFFFFFF && (fa & FILE_ATTRIBUTE_DIRECTORY)); #else if (stat(fullPath->getCString(), &st) == 0) @@ -721,7 +725,9 @@ GDir::GDir(char *name, GBool doStatA) { tmp = path->copy(); tmp->append("/*.*"); - hnd = FindFirstFileA(tmp->getCString(), &ffd); + wchar_t *tmp_w = (wchar_t *)utf8ToUtf16(tmp->getCString()); + hnd = FindFirstFileW(tmp_w, &ffd); + gfree(tmp_w); delete tmp; #elif defined(ACORN) #elif defined(MACOS) @@ -753,8 +759,10 @@ GDirEntry *GDir::getNextEntry() { #if defined(_WIN32) if (hnd != INVALID_HANDLE_VALUE) { - e = new GDirEntry(path->getCString(), ffd.cFileName, doStat); - if (!FindNextFileA(hnd, &ffd)) { + char *name = utf16ToUtf8((uint16_t *)ffd.cFileName); + e = new GDirEntry(path->getCString(), name, doStat); + gfree(name); + if (!FindNextFileW(hnd, &ffd)) { FindClose(hnd); hnd = INVALID_HANDLE_VALUE; } @@ -798,7 +806,9 @@ void GDir::rewind() { FindClose(hnd); tmp = path->copy(); tmp->append("/*.*"); - hnd = FindFirstFileA(tmp->getCString(), &ffd); + wchar_t *tmp_w = (wchar_t *)utf8ToUtf16(tmp->getCString()); + hnd = FindFirstFileW(tmp_w, &ffd); + gfree(tmp_w); delete tmp; #elif defined(ACORN) #elif defined(MACOS) diff --git a/goo/gfile.h b/goo/gfile.h index 805e5232..8854b6c6 100644 --- a/goo/gfile.h +++ b/goo/gfile.h @@ -195,7 +195,7 @@ private: GooString *path; // directory path GBool doStat; // call stat() for each entry? #if defined(_WIN32) - WIN32_FIND_DATAA ffd; + WIN32_FIND_DATAW ffd; HANDLE hnd; #elif defined(ACORN) #elif defined(MACOS) -- 2.11.0