src/core/windowsrt/SDL_winrtpaths.cpp
changeset 8406 a3244b2eefcd
parent 8405 fe893b2d6f4d
child 8420 99dc85ad173c
equal deleted inserted replaced
8405:fe893b2d6f4d 8406:a3244b2eefcd
    11 #include "SDL_stdinc.h"
    11 #include "SDL_stdinc.h"
    12 #include "SDL_system.h"
    12 #include "SDL_system.h"
    13 #include "../windows/SDL_windows.h"
    13 #include "../windows/SDL_windows.h"
    14 }
    14 }
    15 
    15 
       
    16 #include <string>
       
    17 
       
    18 using namespace std;
    16 using namespace Windows::Storage;
    19 using namespace Windows::Storage;
    17 
       
    18 static const wchar_t *
       
    19 WINRT_CopySystemPath(Windows::Storage::StorageFolder ^ folder)
       
    20 {
       
    21     const wchar_t * srcPath = folder->Path->Data();
       
    22     const size_t srcPathLen = SDL_wcslen(srcPath);
       
    23     wchar_t * destPath = (wchar_t *) SDL_calloc(srcPathLen + 1, sizeof(wchar_t));
       
    24     if (!destPath) {
       
    25         SDL_OutOfMemory();
       
    26         return NULL;
       
    27     }
       
    28     SDL_wcslcpy(destPath, srcPath, srcPathLen + 1);
       
    29     return destPath;
       
    30 }
       
    31 
    20 
    32 extern "C" const wchar_t *
    21 extern "C" const wchar_t *
    33 SDL_WinRTGetInstalledLocationPath()
    22 SDL_WinRTGetInstalledLocationPath()
    34 {
    23 {
    35     static const wchar_t * path = nullptr;
    24     static wstring path;
    36     if (!path) {
    25     if (path.empty()) {
    37         path = WINRT_CopySystemPath(Windows::ApplicationModel::Package::Current->InstalledLocation);
    26         path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
    38     }
    27     }
    39     return path;
    28     return path.c_str();
    40 }
    29 }
    41 
    30 
    42 extern "C" const wchar_t *
    31 extern "C" const wchar_t *
    43 SDL_WinRTGetLocalFolderPath()
    32 SDL_WinRTGetLocalFolderPath()
    44 {
    33 {
    45     static const wchar_t * path = nullptr;
    34     static wstring path;
    46     if (!path) {
    35     if (path.empty()) {
    47         path = WINRT_CopySystemPath(ApplicationData::Current->LocalFolder);
    36         path = ApplicationData::Current->LocalFolder->Path->Data();
    48     }
    37     }
    49     return path;
    38     return path.c_str();
    50 }
    39 }
    51 
    40 
    52 extern "C" const wchar_t *
    41 extern "C" const wchar_t *
    53 SDL_WinRTGetRoamingFolderPath()
    42 SDL_WinRTGetRoamingFolderPath()
    54 {
    43 {
    55 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    44 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    56     SDL_Unsupported();
    45     SDL_Unsupported();
    57     return NULL;
    46     return NULL;
    58 #else
    47 #else
    59     static const wchar_t * path = nullptr;
    48     static wstring path;
    60     if (!path) {
    49     if (path.empty()) {
    61         path = WINRT_CopySystemPath(ApplicationData::Current->RoamingFolder);
    50         path = ApplicationData::Current->RoamingFolder->Path->Data();
    62     }
    51     }
    63     return path;
    52     return path.c_str();
    64 #endif
    53 #endif
    65 }
    54 }
    66 
    55 
    67 extern "C" const wchar_t *
    56 extern "C" const wchar_t *
    68 SDL_WinRTGetTemporaryFolderPath()
    57 SDL_WinRTGetTemporaryFolderPath()
    69 {
    58 {
    70 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    59 #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    71     SDL_Unsupported();
    60     SDL_Unsupported();
    72     return NULL;
    61     return NULL;
    73 #else
    62 #else
    74     static const wchar_t * path = nullptr;
    63     static wstring path;
    75     if (!path) {
    64     if (path.empty()) {
    76         path = WINRT_CopySystemPath(ApplicationData::Current->TemporaryFolder);
    65         path = ApplicationData::Current->TemporaryFolder->Path->Data();
    77     }
    66     }
    78     return path;
    67     return path.c_str();
    79 #endif
    68 #endif
    80 }
    69 }
    81 
    70 
    82 #endif /* __WINRT__ */
    71 #endif /* __WINRT__ */