From 274ae9891505cf0323a1b2b3e4ed15600837b4a0 Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Mon, 12 Apr 2021 18:58:24 +0200 Subject: [PATCH] Re-fix handling filepaths with non-ASCII characters on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In #52 I fixed VVVVVV not being able to handle filepaths with non-ASCII characters on Windows. 2f0a0bce4c663b7df2ed229ef897dcf3fd878ec6 and aa5c2d9dc260386c1b99fb9867b2a8ef7c82252f reintroduce this problem, however, by reverting the definition of mkdir to how it was before the fix and using the non-Unicode version of CreateDirectory. And I can confirm that VVVVVV indeed doesn't make its folder anymore with a Windows username of "ั‚ะตัั‚". This commit fixes that issue. --- desktop_version/src/FileSystemUtils.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index bf7cbf72..79233e27 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -16,7 +16,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__) || defined(__HAIKU__) || defined(__DragonFly__) #include @@ -585,7 +590,7 @@ static void PLATFORM_getOSDirectory(char* output) SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, utf16_path); WideCharToMultiByte(CP_UTF8, 0, utf16_path, -1, output, MAX_PATH, NULL, NULL); SDL_strlcat(output, "\\VVVVVV\\", MAX_PATH); - CreateDirectory(output, NULL); + mkdir(output, 0); #else SDL_strlcpy(output, PHYSFS_getPrefDir("distractionware", "VVVVVV"), MAX_PATH); #endif