Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
WinRT: made path retrieval functions return wide-char strings
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLudwig committed Feb 3, 2013
1 parent e18fd19 commit a20af4e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
6 changes: 3 additions & 3 deletions include/SDL_system.h
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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__ */

Expand Down
37 changes: 28 additions & 9 deletions src/core/windowsrt/SDL_winrtpaths.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit a20af4e

Please sign in to comment.