all repos — mgba @ c364a6527a83d22bdd79e77286d0b53b0b624746

mGBA Game Boy Advance Emulator

Windows: Fix passing Unicode filenames (fixes #1359)
Vicki Pfau vi@endrift.com
Sat, 16 Mar 2019 19:37:42 -0700
commit

c364a6527a83d22bdd79e77286d0b53b0b624746

parent

1844c26388885986ecd7cb7cdbd02453a342a0f8

4 files changed, 43 insertions(+), 1 deletions(-)

jump to
M CMakeLists.txtCMakeLists.txt

@@ -226,6 +226,8 @@ # Platform support

if(WIN32) set(WIN32_VERSION "${LIB_VERSION_MAJOR},${LIB_VERSION_MINOR},${LIB_VERSION_PATCH}") add_definitions(-D_WIN32_WINNT=0x0600) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -municode") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode") list(APPEND OS_LIB ws2_32 shlwapi) list(APPEND CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/vfs-w32.c) file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/*.c)
M include/mgba-util/common.hinclude/mgba-util/common.h

@@ -34,12 +34,16 @@ #ifdef _WIN32

// WinSock2 gets very angry if it's included too late #include <winsock2.h> #endif + +#if defined(_MSC_VER) || defined(__cplusplus) +#define restrict __restrict +#endif + #ifdef _MSC_VER #include <Windows.h> #include <sys/types.h> typedef intptr_t ssize_t; #define PATH_MAX MAX_PATH -#define restrict __restrict #define strcasecmp _stricmp #define strncasecmp _strnicmp #define ftruncate _chsize
M src/platform/qt/main.cppsrc/platform/qt/main.cpp

@@ -104,3 +104,21 @@ w->show();

return application.exec(); } + +#ifdef _WIN32 +#include <mgba-util/string.h> +#include <vector> + +extern "C" +int wmain(int argc, wchar_t* argv[]) { + std::vector<char*> argv8; + for (int i = 0; i < argc; ++i) { + argv8.push_back(utf16to8(reinterpret_cast<uint16_t*>(argv[i]), wcslen(argv[i]) * 2)); + } + int ret = main(argc, argv8.data()); + for (char* ptr : argv8) { + free(ptr); + } + return ret; +} +#endif
M src/platform/sdl/main.csrc/platform/sdl/main.c

@@ -179,6 +179,24 @@

return ret; } +#ifdef _WIN32 +#include <mgba-util/string.h> + +int wmain(int argc, wchar_t** argv) { + char** argv8 = malloc(sizeof(char*) * argc); + int i; + for (i = 0; i < argc; ++i) { + argv8[i] = utf16to8((uint16_t*) argv[i], wcslen(argv[i]) * 2); + } + int ret = main(argc, argv8); + for (i = 0; i < argc; ++i) { + free(argv8[i]); + } + free(argv8); + return ret; +} +#endif + int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) { struct mCoreThread thread = { .core = renderer->core