All: Proper handling of Unicode file paths

This commit is contained in:
Jeffrey Pfau 2015-06-29 21:45:32 -07:00
parent 99878b32ca
commit 5bae2087fe
4 changed files with 18 additions and 6 deletions

View File

@ -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:

View File

@ -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
}

View File

@ -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);
}

View File

@ -9,6 +9,8 @@
#include <sys/stat.h>
#ifndef _WIN32
#include <sys/mman.h>
#else
#include <windows.h>
#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);
}