From 5bae2087feddeef3345d19b53f7a1e6fcd7b4f62 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 29 Jun 2015 21:45:32 -0700 Subject: [PATCH] All: Proper handling of Unicode file paths --- CHANGES | 1 + src/gba/supervisor/config.c | 13 +++++++++---- src/platform/qt/VFileDevice.cpp | 2 +- src/util/vfs/vfs-fd.c | 8 +++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 490b28b42..a64dfa6cc 100644 --- a/CHANGES +++ b/CHANGES @@ -91,6 +91,7 @@ Misc: - SDL: Clean up GL context - GBA Audio: Implement audio reset for channels A/B - GBA Hardware: Backport generic RTC source into core + - All: Proper handling of Unicode file paths 0.2.1: (2015-05-13) Bugfixes: diff --git a/src/gba/supervisor/config.c b/src/gba/supervisor/config.c index 4c50653f8..e812b30e0 100644 --- a/src/gba/supervisor/config.c +++ b/src/gba/supervisor/config.c @@ -133,10 +133,15 @@ void GBAConfigDirectory(char* out, size_t outLength) { snprintf(out, outLength, "%s/.config/%s", home, binaryName); mkdir(out, 0755); #else - char home[MAX_PATH]; - SHGetFolderPath(0, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, home); - snprintf(out, outLength, "%s\\%s", home, projectName); - CreateDirectoryA(out, NULL); + wchar_t* home; + wchar_t wpath[MAX_PATH]; + wchar_t wprojectName[MAX_PATH]; + SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &home); + MultiByteToWideChar(CP_UTF8, 0, projectName, -1, wprojectName, MAX_PATH); + StringCchPrintfW(wpath, MAX_PATH, L"%ws\\%ws", home, wprojectName); + CoTaskMemFree(home); + CreateDirectoryW(wpath, NULL); + WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0); #endif } diff --git a/src/platform/qt/VFileDevice.cpp b/src/platform/qt/VFileDevice.cpp index 1e44af382..7e6a006fe 100644 --- a/src/platform/qt/VFileDevice.cpp +++ b/src/platform/qt/VFileDevice.cpp @@ -27,5 +27,5 @@ qint64 VFileDevice::size() const { } VFile* VFileDevice::open(QString path, int mode) { - return VFileOpen(path.toLocal8Bit().constData(), mode); + return VFileOpen(path.toUtf8().constData(), mode); } diff --git a/src/util/vfs/vfs-fd.c b/src/util/vfs/vfs-fd.c index 8e7196028..383d6bbff 100644 --- a/src/util/vfs/vfs-fd.c +++ b/src/util/vfs/vfs-fd.c @@ -9,6 +9,8 @@ #include #ifndef _WIN32 #include +#else +#include #endif struct VFileFD { @@ -35,8 +37,12 @@ struct VFile* VFileOpenFD(const char* path, int flags) { } #ifdef _WIN32 flags |= O_BINARY; -#endif + wchar_t wpath[PATH_MAX]; + MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, sizeof(wpath) / sizeof(*wpath)); + int fd = _wopen(wpath, flags, 0666); +#else int fd = open(path, flags, 0666); +#endif return VFileFromFD(fd); }