WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
authorDavid Ludwig <dludwig@pobox.com>
Mon, 01 Apr 2013 21:33:06 -0400
changeset 8453499aa167ea79
parent 8452 a16533caf2b4
child 8454 ac6a37f54dc2
WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
include/SDL_system.h
src/core/windowsrt/SDL_winrtpaths.cpp
     1.1 --- a/include/SDL_system.h	Sun Mar 31 11:44:50 2013 -0400
     1.2 +++ b/include/SDL_system.h	Mon Apr 01 21:33:06 2013 -0400
     1.3 @@ -135,7 +135,25 @@
     1.4   *      SDL_WinRT_Path for more information on which path types are
     1.5   *      supported where.
     1.6   */
     1.7 -extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType);
     1.8 +extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
     1.9 +
    1.10 +/**
    1.11 + *  \brief Retrieves a Windows RT defined path on the local file system
    1.12 + *
    1.13 + *  \note Documentation on most app-specific path types on Windows RT
    1.14 + *      can be found on MSDN, at the URL:
    1.15 + *      http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
    1.16 + *
    1.17 + *  \param pathType The type of path to retrieve.
    1.18 + *  \ret A UTF-8 string (8-bit, multi-byte) containing the path, or NULL
    1.19 + *      if the path is not available for any reason.  Not all paths are
    1.20 + *      available on all versions of Windows.  This is especially true on
    1.21 + *      Windows Phone.  Check the documentation for the given
    1.22 + *      SDL_WinRT_Path for more information on which path types are
    1.23 + *      supported where.
    1.24 + */
    1.25 +extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
    1.26 +
    1.27  
    1.28  #endif /* __WINRT__ */
    1.29  
     2.1 --- a/src/core/windowsrt/SDL_winrtpaths.cpp	Sun Mar 31 11:44:50 2013 -0400
     2.2 +++ b/src/core/windowsrt/SDL_winrtpaths.cpp	Mon Apr 01 21:33:06 2013 -0400
     2.3 @@ -14,12 +14,13 @@
     2.4  }
     2.5  
     2.6  #include <string>
     2.7 +#include <unordered_map>
     2.8  
     2.9  using namespace std;
    2.10  using namespace Windows::Storage;
    2.11  
    2.12  extern "C" const wchar_t *
    2.13 -SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType)
    2.14 +SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
    2.15  {
    2.16      switch (pathType) {
    2.17          case SDL_WINRT_PATH_INSTALLED_LOCATION:
    2.18 @@ -68,4 +69,26 @@
    2.19      return NULL;
    2.20  }
    2.21  
    2.22 +extern "C" const char *
    2.23 +SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
    2.24 +{
    2.25 +    typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
    2.26 +    static UTF8PathMap utf8Paths;
    2.27 +
    2.28 +    UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
    2.29 +    if (searchResult != utf8Paths.end()) {
    2.30 +        return searchResult->second.c_str();
    2.31 +    }
    2.32 +
    2.33 +    const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
    2.34 +    if (!ucs2Path) {
    2.35 +        return NULL;
    2.36 +    }
    2.37 +
    2.38 +    char * utf8Path = WIN_StringToUTF8(ucs2Path);
    2.39 +    utf8Paths[pathType] = utf8Path;
    2.40 +    SDL_free(utf8Path);
    2.41 +    return utf8Paths[pathType].c_str();
    2.42 +}
    2.43 +
    2.44  #endif /* __WINRT__ */