WinRT: consolidated all WinRT path-retrieval functions into one function
authorDavid Ludwig <dludwig@pobox.com>
Sat, 09 Feb 2013 22:48:19 -0500
changeset 842099dc85ad173c
parent 8419 480504efcbc3
child 8421 8df0242bbeae
WinRT: consolidated all WinRT path-retrieval functions into one function
include/SDL_system.h
src/core/windowsrt/SDL_winrtpaths.cpp
src/render/direct3d11/SDL_render_d3d11.cpp
     1.1 --- a/include/SDL_system.h	Sat Feb 09 20:30:53 2013 -0500
     1.2 +++ b/include/SDL_system.h	Sat Feb 09 22:48:19 2013 -0500
     1.3 @@ -96,44 +96,46 @@
     1.4  /* Platform specific functions for Windows RT */
     1.5  #if defined(__WINRT__) && __WINRT__
     1.6  
     1.7 -/* Gets the path to the installed app's root directory.
     1.8 -
     1.9 -   This function may be used safely on Windows Phone 8.
    1.10 -*/
    1.11 -extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetInstalledLocationPath();
    1.12 +/**
    1.13 + *  \brief Windows RT / Windows Phone path types
    1.14 + */
    1.15 +typedef enum
    1.16 +{
    1.17 +    /** \brief The installed app's root directory.
    1.18 +        Files here are likely to be read-only. */
    1.19 +    SDL_WINRT_PATH_INSTALLED_LOCATION,
    1.20  
    1.21 -/* Gets the path to the local app data store.
    1.22 -   Files and directories that should be limited to the local device can be
    1.23 -   created in this path.
    1.24 +    /** \brief The app's local data store.  Files may be written here */
    1.25 +    SDL_WINRT_PATH_LOCAL_FOLDER,
    1.26  
    1.27 -   This function may be used safely on Windows Phone 8, as opposed to
    1.28 -   SDL_WinRTGetRoamingFolderPath() and SDL_WinRTGetTemporaryFolderPath(),
    1.29 -   which do not work on Windows Phone 8 (and will return NULL if called
    1.30 -   from this platform).
    1.31 - */
    1.32 -extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetLocalFolderPath();
    1.33 +    /** \brief The app's roaming data store.  Unsupported on Windows Phone.
    1.34 +        Files written here may be copied to other machines via a network
    1.35 +        connection.
    1.36 +    */
    1.37 +    SDL_WINRT_PATH_ROAMING_FOLDER,
    1.38  
    1.39 -/* Gets the path to the roaming app data store.
    1.40 -   Files and directories that should roam to different devices can be
    1.41 -   created in this path.  Be sure to read Microsoft's documentation on
    1.42 -   roaming files for more information on how this works, as restrictions
    1.43 -   do apply.
    1.44 +    /** \brief The app's temporary data store.  Unsupported on Windows Phone.
    1.45 +        Files written here may be deleted at any time. */
    1.46 +    SDL_WINRT_PATH_TEMP_FOLDER
    1.47 +} SDL_WinRT_Path;
    1.48 +
    1.49  
    1.50 -   Please note that on Windows Phone 8, this function will return NULL,
    1.51 -   as Windows Phone 8 apps do not have an accessible roaming app data
    1.52 -   store.
    1.53 +/**
    1.54 + *  \brief Retrieves a Windows RT defined path on the local file system
    1.55 + *
    1.56 + *  \note Documentation on most app-specific path types on Windows RT
    1.57 + *      can be found on MSDN, at the URL:
    1.58 + *      http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
    1.59 + *
    1.60 + *  \param pathType The type of path to retrieve.
    1.61 + *  \ret A UCS-2 string (16-bit, wide-char) containing the path, or NULL
    1.62 + *      if the path is not available for any reason.  Not all paths are
    1.63 + *      available on all versions of Windows.  This is especially true on
    1.64 + *      Windows Phone.  Check the documentation for the given
    1.65 + *      SDL_WinRT_Path for more information on which path types are
    1.66 + *      supported where.
    1.67   */
    1.68 -extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetRoamingFolderPath();
    1.69 -
    1.70 -/* Gets the path to the temporary app data store.
    1.71 -   Files and directories may be written here, however they may be deleted
    1.72 -   by Windows at a future date.
    1.73 -
    1.74 -   Please note that on Windows Phone 8, this function will return NULL,
    1.75 -   as Windows Phone 8 apps do not have an accessible temporary app data
    1.76 -   store.
    1.77 -*/
    1.78 -extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetTemporaryFolderPath();
    1.79 +extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType);
    1.80  
    1.81  #endif /* __WINRT__ */
    1.82  
     2.1 --- a/src/core/windowsrt/SDL_winrtpaths.cpp	Sat Feb 09 20:30:53 2013 -0500
     2.2 +++ b/src/core/windowsrt/SDL_winrtpaths.cpp	Sat Feb 09 22:48:19 2013 -0500
     2.3 @@ -19,53 +19,53 @@
     2.4  using namespace Windows::Storage;
     2.5  
     2.6  extern "C" const wchar_t *
     2.7 -SDL_WinRTGetInstalledLocationPath()
     2.8 -{
     2.9 -    static wstring path;
    2.10 -    if (path.empty()) {
    2.11 -        path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
    2.12 -    }
    2.13 -    return path.c_str();
    2.14 -}
    2.15 -
    2.16 -extern "C" const wchar_t *
    2.17 -SDL_WinRTGetLocalFolderPath()
    2.18 +SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType)
    2.19  {
    2.20 -    static wstring path;
    2.21 -    if (path.empty()) {
    2.22 -        path = ApplicationData::Current->LocalFolder->Path->Data();
    2.23 +    switch (pathType) {
    2.24 +        case SDL_WINRT_PATH_INSTALLED_LOCATION:
    2.25 +        {
    2.26 +            static wstring path;
    2.27 +            if (path.empty()) {
    2.28 +                path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
    2.29 +            }
    2.30 +            return path.c_str();
    2.31 +        }
    2.32 +
    2.33 +        case SDL_WINRT_PATH_LOCAL_FOLDER:
    2.34 +        {
    2.35 +            static wstring path;
    2.36 +            if (path.empty()) {
    2.37 +                path = ApplicationData::Current->LocalFolder->Path->Data();
    2.38 +            }
    2.39 +            return path.c_str();
    2.40 +        }
    2.41 +
    2.42 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    2.43 +        case SDL_WINRT_PATH_ROAMING_FOLDER:
    2.44 +        {
    2.45 +            static wstring path;
    2.46 +            if (path.empty()) {
    2.47 +                path = ApplicationData::Current->RoamingFolder->Path->Data();
    2.48 +            }
    2.49 +            return path.c_str();
    2.50 +        }
    2.51 +
    2.52 +        case SDL_WINRT_PATH_TEMP_FOLDER:
    2.53 +        {
    2.54 +            static wstring path;
    2.55 +            if (path.empty()) {
    2.56 +                path = ApplicationData::Current->TemporaryFolder->Path->Data();
    2.57 +            }
    2.58 +            return path.c_str();
    2.59 +        }
    2.60 +#endif
    2.61 +
    2.62 +        default:
    2.63 +            break;
    2.64      }
    2.65 -    return path.c_str();
    2.66 -}
    2.67  
    2.68 -extern "C" const wchar_t *
    2.69 -SDL_WinRTGetRoamingFolderPath()
    2.70 -{
    2.71 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    2.72      SDL_Unsupported();
    2.73      return NULL;
    2.74 -#else
    2.75 -    static wstring path;
    2.76 -    if (path.empty()) {
    2.77 -        path = ApplicationData::Current->RoamingFolder->Path->Data();
    2.78 -    }
    2.79 -    return path.c_str();
    2.80 -#endif
    2.81 -}
    2.82 -
    2.83 -extern "C" const wchar_t *
    2.84 -SDL_WinRTGetTemporaryFolderPath()
    2.85 -{
    2.86 -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
    2.87 -    SDL_Unsupported();
    2.88 -    return NULL;
    2.89 -#else
    2.90 -    static wstring path;
    2.91 -    if (path.empty()) {
    2.92 -        path = ApplicationData::Current->TemporaryFolder->Path->Data();
    2.93 -    }
    2.94 -    return path.c_str();
    2.95 -#endif
    2.96  }
    2.97  
    2.98  #endif /* __WINRT__ */
     3.1 --- a/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 09 20:30:53 2013 -0500
     3.2 +++ b/src/render/direct3d11/SDL_render_d3d11.cpp	Sat Feb 09 22:48:19 2013 -0500
     3.3 @@ -202,10 +202,10 @@
     3.4      wstring fileName;
     3.5  
     3.6  #if WINAPI_FAMILY == WINAPI_FAMILY_APP
     3.7 -    fileName = SDL_WinRTGetInstalledLocationPath();
     3.8 +    fileName = SDL_WinRTGetFileSystemPath(SDL_WINRT_PATH_INSTALLED_LOCATION);
     3.9      fileName += L"\\SDL_VS2012_WinRT\\";
    3.10  #elif WINAPI_FAMILY == WINAPI_PHONE_APP
    3.11 -    fileName = SDL_WinRTGetInstalledLocationPath();
    3.12 +    fileName = SDL_WinRTGetFileSystemPath(SDL_WINRT_PATH_INSTALLED_LOCATION);
    3.13      fileName += L"\\";
    3.14  #endif
    3.15      // WinRT, TODO: test Direct3D 11.1 shader loading on Win32