From 893f11d5431a8916ad6a71bf80801fd15b45f661 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Sat, 9 Feb 2013 22:48:19 -0500 Subject: [PATCH] WinRT: consolidated all WinRT path-retrieval functions into one function --- include/SDL_system.h | 66 +++++++++--------- src/core/windowsrt/SDL_winrtpaths.cpp | 80 +++++++++++----------- src/render/direct3d11/SDL_render_d3d11.cpp | 4 +- 3 files changed, 76 insertions(+), 74 deletions(-) diff --git a/include/SDL_system.h b/include/SDL_system.h index b7de4ab8a..eb7e81138 100644 --- a/include/SDL_system.h +++ b/include/SDL_system.h @@ -96,44 +96,46 @@ extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(); /* Platform specific functions for Windows RT */ #if defined(__WINRT__) && __WINRT__ -/* Gets the path to the installed app's root directory. +/** + * \brief Windows RT / Windows Phone path types + */ +typedef enum +{ + /** \brief The installed app's root directory. + Files here are likely to be read-only. */ + SDL_WINRT_PATH_INSTALLED_LOCATION, - This function may be used safely on Windows Phone 8. -*/ -extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetInstalledLocationPath(); + /** \brief The app's local data store. Files may be written here */ + SDL_WINRT_PATH_LOCAL_FOLDER, -/* Gets the path to the local app data store. - Files and directories that should be limited to the local device can be - created in this path. + /** \brief The app's roaming data store. Unsupported on Windows Phone. + Files written here may be copied to other machines via a network + connection. + */ + SDL_WINRT_PATH_ROAMING_FOLDER, - This function may be used safely on Windows Phone 8, as opposed to - SDL_WinRTGetRoamingFolderPath() and SDL_WinRTGetTemporaryFolderPath(), - which do not work on Windows Phone 8 (and will return NULL if called - from this platform). - */ -extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetLocalFolderPath(); + /** \brief The app's temporary data store. Unsupported on Windows Phone. + Files written here may be deleted at any time. */ + SDL_WINRT_PATH_TEMP_FOLDER +} SDL_WinRT_Path; -/* Gets the path to the roaming app data store. - Files and directories that should roam to different devices can be - created in this path. Be sure to read Microsoft's documentation on - roaming files for more information on how this works, as restrictions - do apply. - Please note that on Windows Phone 8, this function will return NULL, - as Windows Phone 8 apps do not have an accessible roaming app data - store. +/** + * \brief Retrieves a Windows RT defined path on the local file system + * + * \note Documentation on most app-specific path types on Windows RT + * can be found on MSDN, at the URL: + * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx + * + * \param pathType The type of path to retrieve. + * \ret A UCS-2 string (16-bit, wide-char) containing the path, or NULL + * if the path is not available for any reason. Not all paths are + * available on all versions of Windows. This is especially true on + * Windows Phone. Check the documentation for the given + * SDL_WinRT_Path for more information on which path types are + * supported where. */ -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 - by Windows at a future date. - - Please note that on Windows Phone 8, this function will return NULL, - as Windows Phone 8 apps do not have an accessible temporary app data - store. -*/ -extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetTemporaryFolderPath(); +extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType); #endif /* __WINRT__ */ diff --git a/src/core/windowsrt/SDL_winrtpaths.cpp b/src/core/windowsrt/SDL_winrtpaths.cpp index 1c5fb312b..eecfd9652 100644 --- a/src/core/windowsrt/SDL_winrtpaths.cpp +++ b/src/core/windowsrt/SDL_winrtpaths.cpp @@ -19,53 +19,53 @@ using namespace std; using namespace Windows::Storage; extern "C" const wchar_t * -SDL_WinRTGetInstalledLocationPath() +SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType) { - static wstring path; - if (path.empty()) { - path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data(); - } - return path.c_str(); -} + switch (pathType) { + case SDL_WINRT_PATH_INSTALLED_LOCATION: + { + static wstring path; + if (path.empty()) { + path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data(); + } + return path.c_str(); + } -extern "C" const wchar_t * -SDL_WinRTGetLocalFolderPath() -{ - static wstring path; - if (path.empty()) { - path = ApplicationData::Current->LocalFolder->Path->Data(); - } - return path.c_str(); -} + case SDL_WINRT_PATH_LOCAL_FOLDER: + { + static wstring path; + if (path.empty()) { + path = ApplicationData::Current->LocalFolder->Path->Data(); + } + return path.c_str(); + } -extern "C" const wchar_t * -SDL_WinRTGetRoamingFolderPath() -{ -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - SDL_Unsupported(); - return NULL; -#else - static wstring path; - if (path.empty()) { - path = ApplicationData::Current->RoamingFolder->Path->Data(); - } - return path.c_str(); +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP + case SDL_WINRT_PATH_ROAMING_FOLDER: + { + static wstring path; + if (path.empty()) { + path = ApplicationData::Current->RoamingFolder->Path->Data(); + } + return path.c_str(); + } + + case SDL_WINRT_PATH_TEMP_FOLDER: + { + static wstring path; + if (path.empty()) { + path = ApplicationData::Current->TemporaryFolder->Path->Data(); + } + return path.c_str(); + } #endif -} -extern "C" const wchar_t * -SDL_WinRTGetTemporaryFolderPath() -{ -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP + default: + break; + } + SDL_Unsupported(); return NULL; -#else - static wstring path; - if (path.empty()) { - path = ApplicationData::Current->TemporaryFolder->Path->Data(); - } - return path.c_str(); -#endif } #endif /* __WINRT__ */ diff --git a/src/render/direct3d11/SDL_render_d3d11.cpp b/src/render/direct3d11/SDL_render_d3d11.cpp index 3038b3d25..82f798383 100644 --- a/src/render/direct3d11/SDL_render_d3d11.cpp +++ b/src/render/direct3d11/SDL_render_d3d11.cpp @@ -202,10 +202,10 @@ D3D11_ReadShaderContents(const wstring & shaderName, vector & out) wstring fileName; #if WINAPI_FAMILY == WINAPI_FAMILY_APP - fileName = SDL_WinRTGetInstalledLocationPath(); + fileName = SDL_WinRTGetFileSystemPath(SDL_WINRT_PATH_INSTALLED_LOCATION); fileName += L"\\SDL_VS2012_WinRT\\"; #elif WINAPI_FAMILY == WINAPI_PHONE_APP - fileName = SDL_WinRTGetInstalledLocationPath(); + fileName = SDL_WinRTGetFileSystemPath(SDL_WINRT_PATH_INSTALLED_LOCATION); fileName += L"\\"; #endif // WinRT, TODO: test Direct3D 11.1 shader loading on Win32