From ddaa5e13c867fcc9e897bd39673ef6ed701fe766 Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Sun, 12 Jan 2020 12:37:22 +0100 Subject: [PATCH] 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. --- desktop_version/src/FileSystemUtils.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index 01dcda0a..11590620 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -13,7 +13,12 @@ #if defined(_WIN32) #include #include -#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) #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) #include @@ -158,7 +163,9 @@ void PLATFORM_getOSDirectory(char* output) { #ifdef _WIN32 /* 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\\"); #else strcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV"));