src/filesystem/winrt/SDL_sysfilesystem.cpp
author David Ludwig <dludwig@pobox.com>
Mon, 28 Oct 2013 15:41:22 -0400
changeset 8538 d9279c169943
parent 8483 src/core/winrt/SDL_winrtpaths.cpp@d403ded25942
child 8539 41885a5f550d
permissions -rw-r--r--
WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     1
/* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp
8538
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
     2
   TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     3
*/
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     4
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     5
#include "SDL_config.h"
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     6
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     7
#ifdef __WINRT__
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     8
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     9
extern "C" {
8538
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
    10
#include "SDL_filesystem.h"
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    11
#include "SDL_error.h"
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    12
#include "SDL_stdinc.h"
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    13
#include "SDL_system.h"
8538
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
    14
#include "../../core/windows/SDL_windows.h"
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    15
}
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    16
8406
a3244b2eefcd WinRT: fixed an odd path retrieval bug
David Ludwig <dludwig@pobox.com>
parents: 8405
diff changeset
    17
#include <string>
8453
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    18
#include <unordered_map>
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    19
8406
a3244b2eefcd WinRT: fixed an odd path retrieval bug
David Ludwig <dludwig@pobox.com>
parents: 8405
diff changeset
    20
using namespace std;
a3244b2eefcd WinRT: fixed an odd path retrieval bug
David Ludwig <dludwig@pobox.com>
parents: 8405
diff changeset
    21
using namespace Windows::Storage;
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    22
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    23
extern "C" const wchar_t *
8453
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    24
SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    25
{
8420
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    26
    switch (pathType) {
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    27
        case SDL_WINRT_PATH_INSTALLED_LOCATION:
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    28
        {
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    29
            static wstring path;
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    30
            if (path.empty()) {
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    31
                path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    32
            }
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    33
            return path.c_str();
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    34
        }
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    35
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    36
        case SDL_WINRT_PATH_LOCAL_FOLDER:
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    37
        {
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    38
            static wstring path;
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    39
            if (path.empty()) {
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    40
                path = ApplicationData::Current->LocalFolder->Path->Data();
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    41
            }
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    42
            return path.c_str();
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    43
        }
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    44
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    45
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    46
        case SDL_WINRT_PATH_ROAMING_FOLDER:
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    47
        {
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    48
            static wstring path;
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    49
            if (path.empty()) {
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    50
                path = ApplicationData::Current->RoamingFolder->Path->Data();
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    51
            }
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    52
            return path.c_str();
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    53
        }
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    54
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    55
        case SDL_WINRT_PATH_TEMP_FOLDER:
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    56
        {
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    57
            static wstring path;
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    58
            if (path.empty()) {
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    59
                path = ApplicationData::Current->TemporaryFolder->Path->Data();
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    60
            }
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    61
            return path.c_str();
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    62
        }
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    63
#endif
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    64
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    65
        default:
99dc85ad173c WinRT: consolidated all WinRT path-retrieval functions into one function
David Ludwig <dludwig@pobox.com>
parents: 8406
diff changeset
    66
            break;
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    67
    }
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    68
8404
47cfa104ad27 WinRT: made path retrieval functions return NULL on Windows Phone whenever said data isn't available
David Ludwig <dludwig@pobox.com>
parents: 8403
diff changeset
    69
    SDL_Unsupported();
47cfa104ad27 WinRT: made path retrieval functions return NULL on Windows Phone whenever said data isn't available
David Ludwig <dludwig@pobox.com>
parents: 8403
diff changeset
    70
    return NULL;
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    71
}
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    72
8453
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    73
extern "C" const char *
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    74
SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    75
{
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    76
    typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    77
    static UTF8PathMap utf8Paths;
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    78
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    79
    UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    80
    if (searchResult != utf8Paths.end()) {
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    81
        return searchResult->second.c_str();
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    82
    }
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    83
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    84
    const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    85
    if (!ucs2Path) {
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    86
        return NULL;
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    87
    }
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    88
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    89
    char * utf8Path = WIN_StringToUTF8(ucs2Path);
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    90
    utf8Paths[pathType] = utf8Path;
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    91
    SDL_free(utf8Path);
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    92
    return utf8Paths[pathType].c_str();
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    93
}
499aa167ea79 WinRT: made WinRT path retrieval be available in both UCS-2 and UTF-8 flavors
David Ludwig <dludwig@pobox.com>
parents: 8420
diff changeset
    94
8538
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
    95
extern "C" char *
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
    96
SDL_GetBasePath(void)
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
    97
{
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
    98
    const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
    99
    size_t destPathLen;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   100
    char * destPath = NULL;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   101
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   102
    if (!srcPath) {
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   103
        SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   104
        return NULL;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   105
    }
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   106
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   107
    destPathLen = SDL_strlen(srcPath) + 2;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   108
    destPath = (char *) SDL_malloc(destPathLen);
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   109
    if (!destPath) {
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   110
        SDL_OutOfMemory();
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   111
        return NULL;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   112
    }
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   113
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   114
    SDL_snprintf(destPath, destPathLen, "%s\\", srcPath);
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   115
    return destPath;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   116
}
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   117
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   118
extern "C" char *
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   119
SDL_GetPrefPath(const char *org, const char *app)
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   120
{
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   121
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   122
    /* A 'Roaming' folder is not available in Windows Phone 8, however a 'Local' folder is. */
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   123
    const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_LOCAL_FOLDER);
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   124
#else
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   125
    /* A 'Roaming' folder is available on Windows 8 and 8.1.  Use that. */
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   126
    const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_ROAMING_FOLDER);
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   127
#endif
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   128
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   129
    size_t destPathLen;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   130
    char * destPath = NULL;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   131
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   132
    if (!srcPath) {
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   133
        SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   134
        return NULL;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   135
    }
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   136
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   137
    destPathLen = SDL_strlen(srcPath) + SDL_strlen(org) + SDL_strlen(app) + 4;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   138
    destPath = (char *) SDL_malloc(destPathLen);
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   139
    if (!destPath) {
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   140
        SDL_OutOfMemory();
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   141
        return NULL;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   142
    }
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   143
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   144
    SDL_snprintf(destPath, destPathLen, "%s\\%s\\%s\\", srcPath, org, app);
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   145
    return destPath;
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   146
}
d9279c169943 WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
David Ludwig <dludwig@pobox.com>
parents: 8483
diff changeset
   147
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
   148
#endif /* __WINRT__ */