From 0c309e202c4312da244ce132004b9cc3e14c5130 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Mon, 1 Apr 2013 21:33:06 -0400 Subject: [PATCH] WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors --- include/SDL_system.h | 20 +++++++++++++++++++- src/core/windowsrt/SDL_winrtpaths.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/include/SDL_system.h b/include/SDL_system.h index 99bd19982..99ca46383 100644 --- a/include/SDL_system.h +++ b/include/SDL_system.h @@ -135,7 +135,25 @@ typedef enum * SDL_WinRT_Path for more information on which path types are * supported where. */ -extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType); +extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType); + +/** + * \brief Retrieves a Windows RT defined path on the local file system + * + * \note Documentation on most app-specific path types on Windows RT + * can be found on MSDN, at the URL: + * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx + * + * \param pathType The type of path to retrieve. + * \ret A UTF-8 string (8-bit, multi-byte) containing the path, or NULL + * if the path is not available for any reason. Not all paths are + * available on all versions of Windows. This is especially true on + * Windows Phone. Check the documentation for the given + * SDL_WinRT_Path for more information on which path types are + * supported where. + */ +extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType); + #endif /* __WINRT__ */ diff --git a/src/core/windowsrt/SDL_winrtpaths.cpp b/src/core/windowsrt/SDL_winrtpaths.cpp index eecfd9652..4c10b78b7 100644 --- a/src/core/windowsrt/SDL_winrtpaths.cpp +++ b/src/core/windowsrt/SDL_winrtpaths.cpp @@ -14,12 +14,13 @@ extern "C" { } #include +#include using namespace std; using namespace Windows::Storage; extern "C" const wchar_t * -SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType) +SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType) { switch (pathType) { case SDL_WINRT_PATH_INSTALLED_LOCATION: @@ -68,4 +69,26 @@ SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType) return NULL; } +extern "C" const char * +SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType) +{ + typedef unordered_map UTF8PathMap; + static UTF8PathMap utf8Paths; + + UTF8PathMap::iterator searchResult = utf8Paths.find(pathType); + if (searchResult != utf8Paths.end()) { + return searchResult->second.c_str(); + } + + const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType); + if (!ucs2Path) { + return NULL; + } + + char * utf8Path = WIN_StringToUTF8(ucs2Path); + utf8Paths[pathType] = utf8Path; + SDL_free(utf8Path); + return utf8Paths[pathType].c_str(); +} + #endif /* __WINRT__ */