WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
This commit is contained in:
parent
2e29d030b9
commit
df42edd5e1
2 changed files with 43 additions and 2 deletions
|
@ -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__ */
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
@ -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__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue