mirror of
https://github.com/yawut/SDL.git
synced 2026-08-28 03:34:44 -05:00
WinRT: made path retrieval functions return wide-char strings
This commit is contained in:
@@ -105,7 +105,7 @@ extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath();
|
||||
which do not work on Windows Phone 8 (and will return NULL if called
|
||||
from this platform).
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_WinRTGetLocalFolderPath();
|
||||
extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetLocalFolderPath();
|
||||
|
||||
/* Gets the path to the roaming app data store.
|
||||
Files and directories that should roam to different devices can be
|
||||
@@ -117,7 +117,7 @@ extern DECLSPEC const char * SDLCALL SDL_WinRTGetLocalFolderPath();
|
||||
as Windows Phone 8 apps do not have an accessible roaming app data
|
||||
store.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_WinRTGetRoamingFolderPath();
|
||||
extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetRoamingFolderPath();
|
||||
|
||||
/* Gets the path to the temporary app data store.
|
||||
Files and directories may be written here, however they may be deleted
|
||||
@@ -127,7 +127,7 @@ extern DECLSPEC const char * SDLCALL SDL_WinRTGetRoamingFolderPath();
|
||||
as Windows Phone 8 apps do not have an accessible temporary app data
|
||||
store.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_WinRTGetTemporaryFolderPath();
|
||||
extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetTemporaryFolderPath();
|
||||
|
||||
#endif /* __WINRT__ */
|
||||
|
||||
|
||||
@@ -7,37 +7,56 @@
|
||||
#ifdef __WINRT__
|
||||
|
||||
extern "C" {
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_system.h"
|
||||
#include "../windows/SDL_windows.h"
|
||||
}
|
||||
|
||||
using namespace Windows::Storage;
|
||||
|
||||
extern "C" const char * SDL_WinRTGetLocalFolderPath()
|
||||
static const wchar_t *
|
||||
WINRT_CopySystemPath(Windows::Storage::StorageFolder ^ folder)
|
||||
{
|
||||
static const char * path = nullptr;
|
||||
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;
|
||||
}
|
||||
|
||||
extern "C" const wchar_t *
|
||||
SDL_WinRTGetLocalFolderPath()
|
||||
{
|
||||
static const wchar_t * path = nullptr;
|
||||
if (!path) {
|
||||
path = WIN_StringToUTF8(ApplicationData::Current->LocalFolder->Path->Data());
|
||||
path = WINRT_CopySystemPath(ApplicationData::Current->LocalFolder);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
extern "C" const char * SDL_WinRTGetRoamingFolderPath()
|
||||
extern "C" const wchar_t *
|
||||
SDL_WinRTGetRoamingFolderPath()
|
||||
{
|
||||
// TODO, WinRT: make SDL_WinRTGetRoamingFolderPath return NULL on Windows Phone 8
|
||||
static const char * path = nullptr;
|
||||
static const wchar_t * path = nullptr;
|
||||
if (!path) {
|
||||
path = WIN_StringToUTF8(ApplicationData::Current->RoamingFolder->Path->Data());
|
||||
path = WINRT_CopySystemPath(ApplicationData::Current->RoamingFolder);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
extern "C" const char * SDL_WinRTGetTemporaryFolderPath()
|
||||
extern "C" const wchar_t *
|
||||
SDL_WinRTGetTemporaryFolderPath()
|
||||
{
|
||||
// TODO, WinRT: make SDL_WinRTGetTemporaryFolderPath return NULL on Windows Phone 8
|
||||
static const char * path = nullptr;
|
||||
static const wchar_t * path = nullptr;
|
||||
if (!path) {
|
||||
path = WIN_StringToUTF8(ApplicationData::Current->TemporaryFolder->Path->Data());
|
||||
path = WINRT_CopySystemPath(ApplicationData::Current->TemporaryFolder);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user