WinRT: consolidated all WinRT path-retrieval functions into one function

This commit is contained in:
David Ludwig 2013-02-09 22:48:19 -05:00
parent af0c2dad3d
commit 2649db8b65
3 changed files with 80 additions and 78 deletions

View file

@ -96,44 +96,46 @@ extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath();
/* Platform specific functions for Windows RT */ /* Platform specific functions for Windows RT */
#if defined(__WINRT__) && __WINRT__ #if defined(__WINRT__) && __WINRT__
/* Gets the path to the installed app's root directory. /**
* \brief Windows RT / Windows Phone path types
This function may be used safely on Windows Phone 8.
*/ */
extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetInstalledLocationPath(); typedef enum
{
/** \brief The installed app's root directory.
Files here are likely to be read-only. */
SDL_WINRT_PATH_INSTALLED_LOCATION,
/* Gets the path to the local app data store. /** \brief The app's local data store. Files may be written here */
Files and directories that should be limited to the local device can be SDL_WINRT_PATH_LOCAL_FOLDER,
created in this path.
This function may be used safely on Windows Phone 8, as opposed to /** \brief The app's roaming data store. Unsupported on Windows Phone.
SDL_WinRTGetRoamingFolderPath() and SDL_WinRTGetTemporaryFolderPath(), Files written here may be copied to other machines via a network
which do not work on Windows Phone 8 (and will return NULL if called connection.
from this platform).
*/ */
extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetLocalFolderPath(); SDL_WINRT_PATH_ROAMING_FOLDER,
/* Gets the path to the roaming app data store. /** \brief The app's temporary data store. Unsupported on Windows Phone.
Files and directories that should roam to different devices can be Files written here may be deleted at any time. */
created in this path. Be sure to read Microsoft's documentation on SDL_WINRT_PATH_TEMP_FOLDER
roaming files for more information on how this works, as restrictions } SDL_WinRT_Path;
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(); extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType);
/* 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();
#endif /* __WINRT__ */ #endif /* __WINRT__ */

View file

@ -19,7 +19,10 @@ using namespace std;
using namespace Windows::Storage; using namespace Windows::Storage;
extern "C" const wchar_t * extern "C" const wchar_t *
SDL_WinRTGetInstalledLocationPath() SDL_WinRTGetFileSystemPath(SDL_WinRT_Path pathType)
{
switch (pathType) {
case SDL_WINRT_PATH_INSTALLED_LOCATION:
{ {
static wstring path; static wstring path;
if (path.empty()) { if (path.empty()) {
@ -28,8 +31,7 @@ SDL_WinRTGetInstalledLocationPath()
return path.c_str(); return path.c_str();
} }
extern "C" const wchar_t * case SDL_WINRT_PATH_LOCAL_FOLDER:
SDL_WinRTGetLocalFolderPath()
{ {
static wstring path; static wstring path;
if (path.empty()) { if (path.empty()) {
@ -38,34 +40,32 @@ SDL_WinRTGetLocalFolderPath()
return path.c_str(); return path.c_str();
} }
extern "C" const wchar_t * #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
SDL_WinRTGetRoamingFolderPath() case SDL_WINRT_PATH_ROAMING_FOLDER:
{ {
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
SDL_Unsupported();
return NULL;
#else
static wstring path; static wstring path;
if (path.empty()) { if (path.empty()) {
path = ApplicationData::Current->RoamingFolder->Path->Data(); path = ApplicationData::Current->RoamingFolder->Path->Data();
} }
return path.c_str(); return path.c_str();
#endif
} }
extern "C" const wchar_t * case SDL_WINRT_PATH_TEMP_FOLDER:
SDL_WinRTGetTemporaryFolderPath()
{ {
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
SDL_Unsupported();
return NULL;
#else
static wstring path; static wstring path;
if (path.empty()) { if (path.empty()) {
path = ApplicationData::Current->TemporaryFolder->Path->Data(); path = ApplicationData::Current->TemporaryFolder->Path->Data();
} }
return path.c_str(); return path.c_str();
}
#endif #endif
default:
break;
}
SDL_Unsupported();
return NULL;
} }
#endif /* __WINRT__ */ #endif /* __WINRT__ */

View file

@ -202,10 +202,10 @@ D3D11_ReadShaderContents(const wstring & shaderName, vector<char> & out)
wstring fileName; wstring fileName;
#if WINAPI_FAMILY == WINAPI_FAMILY_APP #if WINAPI_FAMILY == WINAPI_FAMILY_APP
fileName = SDL_WinRTGetInstalledLocationPath(); fileName = SDL_WinRTGetFileSystemPath(SDL_WINRT_PATH_INSTALLED_LOCATION);
fileName += L"\\SDL_VS2012_WinRT\\"; fileName += L"\\SDL_VS2012_WinRT\\";
#elif WINAPI_FAMILY == WINAPI_PHONE_APP #elif WINAPI_FAMILY == WINAPI_PHONE_APP
fileName = SDL_WinRTGetInstalledLocationPath(); fileName = SDL_WinRTGetFileSystemPath(SDL_WINRT_PATH_INSTALLED_LOCATION);
fileName += L"\\"; fileName += L"\\";
#endif #endif
// WinRT, TODO: test Direct3D 11.1 shader loading on Win32 // WinRT, TODO: test Direct3D 11.1 shader loading on Win32