WinRT: made path retrieval functions return wide-char strings
authorDavid Ludwig <dludwig@pobox.com>
Sun, 03 Feb 2013 12:34:34 -0500
changeset 8403fbf6bb26c8ce
parent 8402 d9464231555b
child 8404 47cfa104ad27
WinRT: made path retrieval functions return wide-char strings
include/SDL_system.h
src/core/windowsrt/SDL_winrtpaths.cpp
     1.1 --- a/include/SDL_system.h	Sun Feb 03 12:33:15 2013 -0500
     1.2 +++ b/include/SDL_system.h	Sun Feb 03 12:34:34 2013 -0500
     1.3 @@ -105,7 +105,7 @@
     1.4     which do not work on Windows Phone 8 (and will return NULL if called
     1.5     from this platform).
     1.6   */
     1.7 -extern DECLSPEC const char * SDLCALL SDL_WinRTGetLocalFolderPath();
     1.8 +extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetLocalFolderPath();
     1.9  
    1.10  /* Gets the path to the roaming app data store.
    1.11     Files and directories that should roam to different devices can be
    1.12 @@ -117,7 +117,7 @@
    1.13     as Windows Phone 8 apps do not have an accessible roaming app data
    1.14     store.
    1.15   */
    1.16 -extern DECLSPEC const char * SDLCALL SDL_WinRTGetRoamingFolderPath();
    1.17 +extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetRoamingFolderPath();
    1.18  
    1.19  /* Gets the path to the temporary app data store.
    1.20     Files and directories may be written here, however they may be deleted
    1.21 @@ -127,7 +127,7 @@
    1.22     as Windows Phone 8 apps do not have an accessible temporary app data
    1.23     store.
    1.24  */
    1.25 -extern DECLSPEC const char * SDLCALL SDL_WinRTGetTemporaryFolderPath();
    1.26 +extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetTemporaryFolderPath();
    1.27  
    1.28  #endif /* __WINRT__ */
    1.29  
     2.1 --- a/src/core/windowsrt/SDL_winrtpaths.cpp	Sun Feb 03 12:33:15 2013 -0500
     2.2 +++ b/src/core/windowsrt/SDL_winrtpaths.cpp	Sun Feb 03 12:34:34 2013 -0500
     2.3 @@ -7,37 +7,56 @@
     2.4  #ifdef __WINRT__
     2.5  
     2.6  extern "C" {
     2.7 +#include "SDL_error.h"
     2.8 +#include "SDL_stdinc.h"
     2.9  #include "SDL_system.h"
    2.10  #include "../windows/SDL_windows.h"
    2.11  }
    2.12  
    2.13  using namespace Windows::Storage;
    2.14  
    2.15 -extern "C" const char * SDL_WinRTGetLocalFolderPath()
    2.16 +static const wchar_t *
    2.17 +WINRT_CopySystemPath(Windows::Storage::StorageFolder ^ folder)
    2.18  {
    2.19 -    static const char * path = nullptr;
    2.20 +    const wchar_t * srcPath = folder->Path->Data();
    2.21 +    const size_t srcPathLen = SDL_wcslen(srcPath);
    2.22 +    wchar_t * destPath = (wchar_t *) SDL_calloc(srcPathLen + 1, sizeof(wchar_t));
    2.23 +    if (!destPath) {
    2.24 +        SDL_OutOfMemory();
    2.25 +        return NULL;
    2.26 +    }
    2.27 +    SDL_wcslcpy(destPath, srcPath, srcPathLen + 1);
    2.28 +    return destPath;
    2.29 +}
    2.30 +
    2.31 +extern "C" const wchar_t *
    2.32 +SDL_WinRTGetLocalFolderPath()
    2.33 +{
    2.34 +    static const wchar_t * path = nullptr;
    2.35      if (!path) {
    2.36 -        path = WIN_StringToUTF8(ApplicationData::Current->LocalFolder->Path->Data());
    2.37 +        path = WINRT_CopySystemPath(ApplicationData::Current->LocalFolder);
    2.38      }
    2.39      return path;
    2.40  }
    2.41  
    2.42 -extern "C" const char * SDL_WinRTGetRoamingFolderPath()
    2.43 +extern "C" const wchar_t *
    2.44 +SDL_WinRTGetRoamingFolderPath()
    2.45  {
    2.46      // TODO, WinRT: make SDL_WinRTGetRoamingFolderPath return NULL on Windows Phone 8
    2.47 -    static const char * path = nullptr;
    2.48 +    static const wchar_t * path = nullptr;
    2.49      if (!path) {
    2.50 -        path = WIN_StringToUTF8(ApplicationData::Current->RoamingFolder->Path->Data());
    2.51 +        path = WINRT_CopySystemPath(ApplicationData::Current->RoamingFolder);
    2.52      }
    2.53      return path;
    2.54  }
    2.55  
    2.56 -extern "C" const char * SDL_WinRTGetTemporaryFolderPath()
    2.57 +extern "C" const wchar_t *
    2.58 +SDL_WinRTGetTemporaryFolderPath()
    2.59  {
    2.60      // TODO, WinRT: make SDL_WinRTGetTemporaryFolderPath return NULL on Windows Phone 8
    2.61 -    static const char * path = nullptr;
    2.62 +    static const wchar_t * path = nullptr;
    2.63      if (!path) {
    2.64 -        path = WIN_StringToUTF8(ApplicationData::Current->TemporaryFolder->Path->Data());
    2.65 +        path = WINRT_CopySystemPath(ApplicationData::Current->TemporaryFolder);
    2.66      }
    2.67      return path;
    2.68  }