This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_winrtpaths.cpp
82 lines (72 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
/* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp
TODO, WinRT: add note to SDL_winrtpaths.cpp mentioning that /ZW must be used when compiling the file
*/
#include "SDL_config.h"
#ifdef __WINRT__
extern "C" {
10
11
#include "SDL_error.h"
#include "SDL_stdinc.h"
12
13
14
15
16
17
#include "SDL_system.h"
#include "../windows/SDL_windows.h"
}
using namespace Windows::Storage;
18
19
static const wchar_t *
WINRT_CopySystemPath(Windows::Storage::StorageFolder ^ folder)
20
{
21
22
23
24
25
26
27
28
29
30
31
const wchar_t * srcPath = folder->Path->Data();
const size_t srcPathLen = SDL_wcslen(srcPath);
wchar_t * destPath = (wchar_t *) SDL_calloc(srcPathLen + 1, sizeof(wchar_t));
if (!destPath) {
SDL_OutOfMemory();
return NULL;
}
SDL_wcslcpy(destPath, srcPath, srcPathLen + 1);
return destPath;
}
32
33
34
35
36
37
38
39
40
41
extern "C" const wchar_t *
SDL_WinRTGetInstalledLocationPath()
{
static const wchar_t * path = nullptr;
if (!path) {
path = WINRT_CopySystemPath(Windows::ApplicationModel::Package::Current->InstalledLocation);
}
return path;
}
42
43
44
45
extern "C" const wchar_t *
SDL_WinRTGetLocalFolderPath()
{
static const wchar_t * path = nullptr;
46
if (!path) {
47
path = WINRT_CopySystemPath(ApplicationData::Current->LocalFolder);
48
49
50
51
}
return path;
}
52
53
extern "C" const wchar_t *
SDL_WinRTGetRoamingFolderPath()
54
{
55
56
57
58
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
SDL_Unsupported();
return NULL;
#else
59
static const wchar_t * path = nullptr;
60
if (!path) {
61
path = WINRT_CopySystemPath(ApplicationData::Current->RoamingFolder);
62
63
}
return path;
64
#endif
65
66
}
67
68
extern "C" const wchar_t *
SDL_WinRTGetTemporaryFolderPath()
69
{
70
71
72
73
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
SDL_Unsupported();
return NULL;
#else
74
static const wchar_t * path = nullptr;
75
if (!path) {
76
path = WINRT_CopySystemPath(ApplicationData::Current->TemporaryFolder);
77
78
}
return path;
79
#endif
80
81
82
}
#endif /* __WINRT__ */