From cd9d09d1f306e4f2ec1da2db71fc00202eefd954 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Tue, 29 Nov 2016 02:04:13 -0500 Subject: [PATCH] use unicode versions of windows functions --- file_path_special.c | 6 ++++- gfx/common/win32_common.cpp | 27 ++++++++++++++----- gfx/common/win32_common.h | 6 ++++- gfx/drivers/d3d.cpp | 4 +++ gfx/drivers_font/d3d_w32_font.cpp | 2 +- libretro-common/file/retro_dirent.c | 11 ++++++-- libretro-common/file/retro_stat.c | 11 +++++++- libretro-common/include/retro_dirent.h | 2 ++ libretro-common/include/retro_miscellaneous.h | 3 +++ libretro-common/streams/file_stream.c | 3 +++ 10 files changed, 63 insertions(+), 12 deletions(-) diff --git a/file_path_special.c b/file_path_special.c index 83ba105f52..540bf7073a 100644 --- a/file_path_special.c +++ b/file_path_special.c @@ -208,6 +208,8 @@ void fill_pathname_application_path(char *s, size_t len) #endif #ifdef _WIN32 DWORD ret; + wchar_t ws[len]; + size_t ws_size = 0; #endif #ifdef __HAIKU__ image_info info; @@ -219,7 +221,9 @@ void fill_pathname_application_path(char *s, size_t len) return; #ifdef _WIN32 - ret = GetModuleFileName(GetModuleHandle(NULL), s, len - 1); + mbstowcs_s(&ws_size, ws, len, s, len - 1); + + ret = GetModuleFileName(GetModuleHandle(NULL), ws, len - 1); s[ret] = '\0'; #elif defined(__APPLE__) if (bundle) diff --git a/gfx/common/win32_common.cpp b/gfx/common/win32_common.cpp index 61cafb7717..81e4c98444 100644 --- a/gfx/common/win32_common.cpp +++ b/gfx/common/win32_common.cpp @@ -260,6 +260,7 @@ void win32_monitor_info(void *data, void *hm_data, unsigned *mon_id) static int win32_drag_query_file(HWND hwnd, WPARAM wparam) { char szFilename[1024] = {0}; + wchar_t wszFilename[1024] = {0}; if (DragQueryFile((HDROP)wparam, 0xFFFFFFFF, NULL, 0)) { @@ -268,8 +269,11 @@ static int win32_drag_query_file(HWND hwnd, WPARAM wparam) content_ctx_info_t content_info = {0}; core_info_list_t *core_info_list = NULL; const core_info_t *core_info = NULL; + size_t file_len = 0; - DragQueryFile((HDROP)wparam, 0, szFilename, 1024); + DragQueryFile((HDROP)wparam, 0, wszFilename, 1024); + + wcstombs_s(&file_len, szFilename, sizeof(szFilename), wszFilename, sizeof(szFilename) - 1); core_info_get_list(&core_info_list); @@ -510,7 +514,7 @@ bool win32_window_create(void *data, unsigned style, unsigned height, bool fullscreen) { #ifndef _XBOX - main_window.hwnd = CreateWindowEx(0, "RetroArch", "RetroArch", + main_window.hwnd = CreateWindowEx(0, L"RetroArch", L"RetroArch", style, fullscreen ? mon_rect->left : g_pos_x, fullscreen ? mon_rect->top : g_pos_y, @@ -578,6 +582,9 @@ static bool win32_monitor_set_fullscreen(unsigned width, unsigned height, { #ifndef _XBOX DEVMODE devmode; + wchar_t dev_name_wide[1024]; + size_t dev_name_size = strlen(dev_name) + 1; + size_t dev_name_wide_size = 0; memset(&devmode, 0, sizeof(devmode)); devmode.dmSize = sizeof(DEVMODE); @@ -588,7 +595,10 @@ static bool win32_monitor_set_fullscreen(unsigned width, unsigned height, RARCH_LOG("Setting fullscreen to %ux%u @ %uHz on device %s.\n", width, height, refresh, dev_name); - return ChangeDisplaySettingsEx(dev_name, &devmode, + + mbstowcs_s(&dev_name_wide_size, dev_name_wide, dev_name_size, dev_name, dev_name_size - 1); + + return ChangeDisplaySettingsEx(dev_name_wide, &devmode, NULL, CDS_FULLSCREEN, NULL) == DISP_CHANGE_SUCCESSFUL; #endif } @@ -679,7 +689,8 @@ bool win32_suppress_screensaver(void *data, bool enable) #endif } -void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use, +/* FIXME: It should not be necessary to add the W after MONITORINFOEX, but linking fails without it. */ +void win32_set_style(MONITORINFOEXW *current_mon, HMONITOR *hm_to_use, unsigned *width, unsigned *height, bool fullscreen, bool windowed_full, RECT *rect, RECT *mon_rect, DWORD *style) { @@ -704,10 +715,14 @@ void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use, } else { + char dev_name[CCHDEVICENAME] = {0}; + size_t name_len = 0; *style = WS_POPUP | WS_VISIBLE; + wcstombs_s(&name_len, dev_name, sizeof(dev_name), current_mon->szDevice, sizeof(dev_name) - 1); + if (!win32_monitor_set_fullscreen(*width, *height, - refresh, current_mon->szDevice)) + refresh, dev_name)) {} /* Display settings might have changed, get new coordinates. */ @@ -853,7 +868,7 @@ void win32_window_reset(void) void win32_destroy_window(void) { #ifndef _XBOX - UnregisterClass("RetroArch", GetModuleHandle(NULL)); + UnregisterClass(L"RetroArch", GetModuleHandle(NULL)); #endif main_window.hwnd = NULL; } diff --git a/gfx/common/win32_common.h b/gfx/common/win32_common.h index 552be27fd1..a53015c41c 100644 --- a/gfx/common/win32_common.h +++ b/gfx/common/win32_common.h @@ -21,6 +21,9 @@ #ifndef _XBOX #define WIN32_LEAN_AND_MEAN +#define UNICODE +#include +#include #include #endif @@ -94,7 +97,8 @@ void win32_check_window(bool *quit, void win32_set_window(unsigned *width, unsigned *height, bool fullscreen, bool windowed_full, void *rect_data); -void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use, +/* FIXME: It should not be necessary to add the W after MONITORINFOEX, but linking fails without it. */ +void win32_set_style(MONITORINFOEXW *current_mon, HMONITOR *hm_to_use, unsigned *width, unsigned *height, bool fullscreen, bool windowed_full, RECT *rect, RECT *mon_rect, DWORD *style); diff --git a/gfx/drivers/d3d.cpp b/gfx/drivers/d3d.cpp index 8715dddffd..95bfc96f8b 100644 --- a/gfx/drivers/d3d.cpp +++ b/gfx/drivers/d3d.cpp @@ -18,6 +18,10 @@ #ifdef _XBOX #include #include +#else +#define UNICODE +#include +#include #endif #include diff --git a/gfx/drivers_font/d3d_w32_font.cpp b/gfx/drivers_font/d3d_w32_font.cpp index eb6f4027bd..35d6e26f43 100644 --- a/gfx/drivers_font/d3d_w32_font.cpp +++ b/gfx/drivers_font/d3d_w32_font.cpp @@ -45,7 +45,7 @@ static void *d3dfonts_w32_init_font(void *video_data, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_PITCH, - "Verdana" /* Hardcode FTL */ + L"Verdana" /* Hardcode FTL */ }; d3dfonts = (d3dfonts_t*)calloc(1, sizeof(*d3dfonts)); diff --git a/libretro-common/file/retro_dirent.c b/libretro-common/file/retro_dirent.c index 54c77b6a24..3eceb9285c 100644 --- a/libretro-common/file/retro_dirent.c +++ b/libretro-common/file/retro_dirent.c @@ -28,11 +28,15 @@ #include #include #include +#include struct RDIR *retro_opendir(const char *name) { #if defined(_WIN32) char path_buf[1024]; + wchar_t pathW[1024]; + size_t path_size = 0; + size_t out_size = 0; #endif struct RDIR *rdir = (struct RDIR*)calloc(1, sizeof(*rdir)); @@ -41,7 +45,9 @@ struct RDIR *retro_opendir(const char *name) #if defined(_WIN32) snprintf(path_buf, sizeof(path_buf), "%s\\*", name); - rdir->directory = FindFirstFile(path_buf, &rdir->entry); + path_size = strlen(path_buf) + 1; + mbstowcs_s(&out_size, pathW, path_size, path_buf, path_size - 1); + rdir->directory = FindFirstFile(pathW, &rdir->entry); #elif defined(VITA) || defined(PSP) rdir->directory = sceIoDopen(name); #elif defined(_3DS) @@ -93,7 +99,8 @@ int retro_readdir(struct RDIR *rdir) const char *retro_dirent_get_name(struct RDIR *rdir) { #if defined(_WIN32) - return rdir->entry.cFileName; + utf16_to_char_string(rdir->entry.cFileName, rdir->path, sizeof(rdir->path)); + return rdir->path; #elif defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__) return rdir->entry.d_name; #else diff --git a/libretro-common/file/retro_stat.c b/libretro-common/file/retro_stat.c index 077a1b7e60..e0ed739ee3 100644 --- a/libretro-common/file/retro_stat.c +++ b/libretro-common/file/retro_stat.c @@ -33,6 +33,9 @@ #include #define INVALID_FILE_ATTRIBUTES -1 #else +#define UNICODE +#include +#include #include #include #include @@ -102,7 +105,13 @@ static bool path_stat(const char *path, enum stat_mode mode, int32_t *size) #elif defined(_WIN32) WIN32_FILE_ATTRIBUTE_DATA file_info; GET_FILEEX_INFO_LEVELS fInfoLevelId = GetFileExInfoStandard; - DWORD ret = GetFileAttributesEx(path, fInfoLevelId, &file_info); + size_t path_len = strlen(path); + wchar_t path_wide[path_len + 1]; + size_t path_wide_size = 0; + + mbstowcs_s(&path_wide_size, path_wide, path_len + 1, path, path_len); + + DWORD ret = GetFileAttributesEx(path_wide, fInfoLevelId, &file_info); if (ret == 0) return false; #else diff --git a/libretro-common/include/retro_dirent.h b/libretro-common/include/retro_dirent.h index 4a44934e46..6270287a00 100644 --- a/libretro-common/include/retro_dirent.h +++ b/libretro-common/include/retro_dirent.h @@ -24,6 +24,7 @@ #define __RETRO_DIRENT_H #include +#include #include @@ -65,6 +66,7 @@ struct RDIR WIN32_FIND_DATA entry; HANDLE directory; bool next; + char path[PATH_MAX_LENGTH]; #elif defined(VITA) || defined(PSP) SceUID directory; SceIoDirent entry; diff --git a/libretro-common/include/retro_miscellaneous.h b/libretro-common/include/retro_miscellaneous.h index 83d004b8a0..2ab71c52dc 100644 --- a/libretro-common/include/retro_miscellaneous.h +++ b/libretro-common/include/retro_miscellaneous.h @@ -47,6 +47,9 @@ #if defined(_WIN32) && !defined(_XBOX) #define WIN32_LEAN_AND_MEAN +#define UNICODE +#include +#include #include #elif defined(_WIN32) && defined(_XBOX) #include diff --git a/libretro-common/streams/file_stream.c b/libretro-common/streams/file_stream.c index 6d74a9a106..db9d23b565 100644 --- a/libretro-common/streams/file_stream.c +++ b/libretro-common/streams/file_stream.c @@ -26,6 +26,9 @@ #include #if defined(_WIN32) +# define UNICODE +# include +# include # ifdef _MSC_VER # define setmode _setmode # endif