WinRT: fixed an odd path retrieval bug
authorDavid Ludwig <dludwig@pobox.com>
Sun, 03 Feb 2013 13:18:31 -0500
changeset 8406a3244b2eefcd
parent 8405 fe893b2d6f4d
child 8407 2dc7432abaf9
WinRT: fixed an odd path retrieval bug
src/core/windowsrt/SDL_winrtpaths.cpp
     1.1 --- a/src/core/windowsrt/SDL_winrtpaths.cpp	Sun Feb 03 12:49:12 2013 -0500
     1.2 +++ b/src/core/windowsrt/SDL_winrtpaths.cpp	Sun Feb 03 13:18:31 2013 -0500
     1.3 @@ -13,40 +13,29 @@
     1.4  #include "../windows/SDL_windows.h"
     1.5  }
     1.6  
     1.7 +#include <string>
     1.8 +
     1.9 +using namespace std;
    1.10  using namespace Windows::Storage;
    1.11  
    1.12 -static const wchar_t *
    1.13 -WINRT_CopySystemPath(Windows::Storage::StorageFolder ^ folder)
    1.14 -{
    1.15 -    const wchar_t * srcPath = folder->Path->Data();
    1.16 -    const size_t srcPathLen = SDL_wcslen(srcPath);
    1.17 -    wchar_t * destPath = (wchar_t *) SDL_calloc(srcPathLen + 1, sizeof(wchar_t));
    1.18 -    if (!destPath) {
    1.19 -        SDL_OutOfMemory();
    1.20 -        return NULL;
    1.21 -    }
    1.22 -    SDL_wcslcpy(destPath, srcPath, srcPathLen + 1);
    1.23 -    return destPath;
    1.24 -}
    1.25 -
    1.26  extern "C" const wchar_t *
    1.27  SDL_WinRTGetInstalledLocationPath()
    1.28  {
    1.29 -    static const wchar_t * path = nullptr;
    1.30 -    if (!path) {
    1.31 -        path = WINRT_CopySystemPath(Windows::ApplicationModel::Package::Current->InstalledLocation);
    1.32 +    static wstring path;
    1.33 +    if (path.empty()) {
    1.34 +        path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
    1.35      }
    1.36 -    return path;
    1.37 +    return path.c_str();
    1.38  }
    1.39  
    1.40  extern "C" const wchar_t *
    1.41  SDL_WinRTGetLocalFolderPath()
    1.42  {
    1.43 -    static const wchar_t * path = nullptr;
    1.44 -    if (!path) {
    1.45 -        path = WINRT_CopySystemPath(ApplicationData::Current->LocalFolder);
    1.46 +    static wstring path;
    1.47 +    if (path.empty()) {
    1.48 +        path = ApplicationData::Current->LocalFolder->Path->Data();
    1.49      }
    1.50 -    return path;
    1.51 +    return path.c_str();
    1.52  }
    1.53  
    1.54  extern "C" const wchar_t *
    1.55 @@ -56,11 +45,11 @@
    1.56      SDL_Unsupported();
    1.57      return NULL;
    1.58  #else
    1.59 -    static const wchar_t * path = nullptr;
    1.60 -    if (!path) {
    1.61 -        path = WINRT_CopySystemPath(ApplicationData::Current->RoamingFolder);
    1.62 +    static wstring path;
    1.63 +    if (path.empty()) {
    1.64 +        path = ApplicationData::Current->RoamingFolder->Path->Data();
    1.65      }
    1.66 -    return path;
    1.67 +    return path.c_str();
    1.68  #endif
    1.69  }
    1.70  
    1.71 @@ -71,11 +60,11 @@
    1.72      SDL_Unsupported();
    1.73      return NULL;
    1.74  #else
    1.75 -    static const wchar_t * path = nullptr;
    1.76 -    if (!path) {
    1.77 -        path = WINRT_CopySystemPath(ApplicationData::Current->TemporaryFolder);
    1.78 +    static wstring path;
    1.79 +    if (path.empty()) {
    1.80 +        path = ApplicationData::Current->TemporaryFolder->Path->Data();
    1.81      }
    1.82 -    return path;
    1.83 +    return path.c_str();
    1.84  #endif
    1.85  }
    1.86