src/core/windowsrt/SDL_winrtpaths.cpp
author David Ludwig <dludwig@pobox.com>
Sun, 03 Feb 2013 12:49:12 -0500
changeset 8405 fe893b2d6f4d
parent 8404 47cfa104ad27
child 8406 a3244b2eefcd
permissions -rw-r--r--
WinRT: added a function to retrieve the root path to the installed app
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
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
     2
   TODO, WinRT: add note to SDL_winrtpaths.cpp mentioning that /ZW must be used when compiling the file
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" {
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    10
#include "SDL_error.h"
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    11
#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
    12
#include "SDL_system.h"
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    13
#include "../windows/SDL_windows.h"
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    14
}
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
using namespace Windows::Storage;
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    17
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    18
static const wchar_t *
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    19
WINRT_CopySystemPath(Windows::Storage::StorageFolder ^ folder)
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    20
{
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    21
    const wchar_t * srcPath = folder->Path->Data();
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    22
    const size_t srcPathLen = SDL_wcslen(srcPath);
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    23
    wchar_t * destPath = (wchar_t *) SDL_calloc(srcPathLen + 1, sizeof(wchar_t));
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    24
    if (!destPath) {
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    25
        SDL_OutOfMemory();
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    26
        return NULL;
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    27
    }
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    28
    SDL_wcslcpy(destPath, srcPath, srcPathLen + 1);
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    29
    return destPath;
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    30
}
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    31
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    32
extern "C" const wchar_t *
8405
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    33
SDL_WinRTGetInstalledLocationPath()
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    34
{
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    35
    static const wchar_t * path = nullptr;
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    36
    if (!path) {
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    37
        path = WINRT_CopySystemPath(Windows::ApplicationModel::Package::Current->InstalledLocation);
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    38
    }
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    39
    return path;
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    40
}
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    41
fe893b2d6f4d WinRT: added a function to retrieve the root path to the installed app
David Ludwig <dludwig@pobox.com>
parents: 8404
diff changeset
    42
extern "C" const wchar_t *
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    43
SDL_WinRTGetLocalFolderPath()
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    44
{
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    45
    static const wchar_t * path = nullptr;
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    46
    if (!path) {
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    47
        path = WINRT_CopySystemPath(ApplicationData::Current->LocalFolder);
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    48
    }
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    49
    return path;
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    50
}
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    51
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    52
extern "C" const wchar_t *
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    53
SDL_WinRTGetRoamingFolderPath()
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    54
{
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
    55
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
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
    56
    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
    57
    return NULL;
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
    58
#else
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    59
    static const wchar_t * path = nullptr;
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    60
    if (!path) {
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    61
        path = WINRT_CopySystemPath(ApplicationData::Current->RoamingFolder);
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    62
    }
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    63
    return path;
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
    64
#endif
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    65
}
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    66
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    67
extern "C" const wchar_t *
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    68
SDL_WinRTGetTemporaryFolderPath()
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    69
{
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
    70
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
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
    71
    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
    72
    return NULL;
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
    73
#else
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    74
    static const wchar_t * path = nullptr;
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    75
    if (!path) {
8403
fbf6bb26c8ce WinRT: made path retrieval functions return wide-char strings
David Ludwig <dludwig@pobox.com>
parents: 8388
diff changeset
    76
        path = WINRT_CopySystemPath(ApplicationData::Current->TemporaryFolder);
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    77
    }
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    78
    return path;
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
    79
#endif
8388
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    80
}
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    81
1e6ddf458e65 WinRT: added platform-specific APIs to access common, writable folder paths
David Ludwig <dludwig@pobox.com>
parents:
diff changeset
    82
#endif /* __WINRT__ */