src/core/winrt/SDL_winrtpaths.cpp
author David Ludwig <dludwig@pobox.com>
Sun, 22 Sep 2013 23:17:25 -0400
changeset 8532 0f4be71aa156
parent 8483 d403ded25942
permissions -rw-r--r--
WinRT: added missing files
     1 /* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp
     2    TODO, WinRT: add note to SDL_winrtpaths.cpp mentioning that /ZW must be used when compiling the file
     3 */
     4 
     5 #include "SDL_config.h"
     6 
     7 #ifdef __WINRT__
     8 
     9 extern "C" {
    10 #include "SDL_error.h"
    11 #include "SDL_stdinc.h"
    12 #include "SDL_system.h"
    13 #include "../windows/SDL_windows.h"
    14 }
    15 
    16 #include <string>
    17 #include <unordered_map>
    18 
    19 using namespace std;
    20 using namespace Windows::Storage;
    21 
    22 extern "C" const wchar_t *
    23 SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
    24 {
    25     switch (pathType) {
    26         case SDL_WINRT_PATH_INSTALLED_LOCATION:
    27         {
    28             static wstring path;
    29             if (path.empty()) {
    30                 path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
    31             }
    32             return path.c_str();
    33         }
    34 
    35         case SDL_WINRT_PATH_LOCAL_FOLDER:
    36         {
    37             static wstring path;
    38             if (path.empty()) {
    39                 path = ApplicationData::Current->LocalFolder->Path->Data();
    40             }
    41             return path.c_str();
    42         }
    43 
    44 #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    45         case SDL_WINRT_PATH_ROAMING_FOLDER:
    46         {
    47             static wstring path;
    48             if (path.empty()) {
    49                 path = ApplicationData::Current->RoamingFolder->Path->Data();
    50             }
    51             return path.c_str();
    52         }
    53 
    54         case SDL_WINRT_PATH_TEMP_FOLDER:
    55         {
    56             static wstring path;
    57             if (path.empty()) {
    58                 path = ApplicationData::Current->TemporaryFolder->Path->Data();
    59             }
    60             return path.c_str();
    61         }
    62 #endif
    63 
    64         default:
    65             break;
    66     }
    67 
    68     SDL_Unsupported();
    69     return NULL;
    70 }
    71 
    72 extern "C" const char *
    73 SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
    74 {
    75     typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
    76     static UTF8PathMap utf8Paths;
    77 
    78     UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
    79     if (searchResult != utf8Paths.end()) {
    80         return searchResult->second.c_str();
    81     }
    82 
    83     const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
    84     if (!ucs2Path) {
    85         return NULL;
    86     }
    87 
    88     char * utf8Path = WIN_StringToUTF8(ucs2Path);
    89     utf8Paths[pathType] = utf8Path;
    90     SDL_free(utf8Path);
    91     return utf8Paths[pathType].c_str();
    92 }
    93 
    94 #endif /* __WINRT__ */