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