1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Use wide-char Windows API functions on Windows

There's now a thin layer of UTF-16 around the WinAPI functions to get
the path to the Documents folder and to create a new directory, so that
account usernames with non-ASCII characters do not result in no VVVVVV
folder being created or used.
This commit is contained in:
Dav999-v 2020-01-12 12:37:22 +01:00 committed by Ethan Lee
parent 64fd50be6f
commit ddaa5e13c8

View file

@ -13,7 +13,12 @@
#if defined(_WIN32) #if defined(_WIN32)
#include <windows.h> #include <windows.h>
#include <shlobj.h> #include <shlobj.h>
#define mkdir(a, b) CreateDirectory(a, NULL) int mkdir(char* path, int mode)
{
WCHAR utf16_path[MAX_PATH];
MultiByteToWideChar(CP_UTF8, 0, path, -1, utf16_path, MAX_PATH);
return CreateDirectoryW(utf16_path, NULL);
}
#define VNEEDS_MIGRATION (mkdirResult != 0) #define VNEEDS_MIGRATION (mkdirResult != 0)
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <sys/stat.h> #include <sys/stat.h>
@ -158,7 +163,9 @@ void PLATFORM_getOSDirectory(char* output)
{ {
#ifdef _WIN32 #ifdef _WIN32
/* This block is here for compatibility, do not touch it! */ /* This block is here for compatibility, do not touch it! */
SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, output); WCHAR utf16_path[MAX_PATH];
SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, utf16_path);
WideCharToMultiByte(CP_UTF8, 0, utf16_path, -1, output, MAX_PATH, NULL, NULL);
strcat(output, "\\VVVVVV\\"); strcat(output, "\\VVVVVV\\");
#else #else
strcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV")); strcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV"));