Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

WinRT: made path retrieval functions return wide-char strings

  • Loading branch information
DavidLudwig committed Feb 3, 2013
1 parent e18fd19 commit a20af4e27083ffa1d25f4ac6d1da5eeb0878d8b3
Showing with 31 additions and 12 deletions.
  1. +3 −3 include/SDL_system.h
  2. +28 −9 src/core/windowsrt/SDL_winrtpaths.cpp
@@ -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;
}

0 comments on commit a20af4e

Please sign in to comment.