Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8…
Browse files Browse the repository at this point in the history
… flavors
  • Loading branch information
DavidLudwig committed Apr 2, 2013
1 parent dc87662 commit 0c309e2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
20 changes: 19 additions & 1 deletion include/SDL_system.h
Expand Up @@ -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__ */

Expand Down
25 changes: 24 additions & 1 deletion src/core/windowsrt/SDL_winrtpaths.cpp
Expand Up @@ -14,12 +14,13 @@ extern "C" {
}

#include <string>
#include <unordered_map>

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:
Expand Down Expand Up @@ -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<SDL_WinRT_Path, string> 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__ */

0 comments on commit 0c309e2

Please sign in to comment.