From 3236fc3a9f823c28739cdd49a8144289451a737b Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Mon, 28 Oct 2013 15:41:22 -0400 Subject: [PATCH] WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath --- .../SDL/SDL-WinPhone_VS2012.vcxproj | 13 +++-- .../SDL/SDL-WinPhone_VS2012.vcxproj.filters | 9 ++- VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj | 17 +++--- .../SDL/SDL-WinRT_VS2012.vcxproj.filters | 9 ++- .../winrt/SDL_sysfilesystem.cpp} | 58 ++++++++++++++++++- 5 files changed, 84 insertions(+), 22 deletions(-) rename src/{core/winrt/SDL_winrtpaths.cpp => filesystem/winrt/SDL_sysfilesystem.cpp} (54%) diff --git a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj index 501c929c14504..882fe3b6c012d 100644 --- a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj +++ b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj @@ -156,6 +156,7 @@ + @@ -288,12 +289,6 @@ true true - - true - true - true - true - @@ -304,6 +299,12 @@ + + true + true + true + true + diff --git a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj.filters b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj.filters index 346e0735d0579..f99bb94885266 100644 --- a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj.filters +++ b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj.filters @@ -342,6 +342,9 @@ Source Files + + Header Files + @@ -584,9 +587,6 @@ Source Files - - Source Files - Source Files @@ -611,6 +611,9 @@ Source Files + + Source Files + diff --git a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj index 0be3fc4e0caa7..e50293e2468c4 100644 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj @@ -71,14 +71,6 @@ true true - - true - true - true - true - true - true - @@ -89,6 +81,14 @@ + + true + true + true + true + true + true + @@ -211,6 +211,7 @@ + diff --git a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters index ffeb7165ff53c..8a7f94d5363ce 100644 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters @@ -258,9 +258,6 @@ Source Files - - Source Files - Source Files @@ -279,6 +276,9 @@ Source Files + + Source Files + @@ -614,6 +614,9 @@ Source Files + + Header Files + diff --git a/src/core/winrt/SDL_winrtpaths.cpp b/src/filesystem/winrt/SDL_sysfilesystem.cpp similarity index 54% rename from src/core/winrt/SDL_winrtpaths.cpp rename to src/filesystem/winrt/SDL_sysfilesystem.cpp index 4c10b78b7e44c..c70113200a3ce 100644 --- a/src/core/winrt/SDL_winrtpaths.cpp +++ b/src/filesystem/winrt/SDL_sysfilesystem.cpp @@ -1,5 +1,5 @@ /* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp - TODO, WinRT: add note to SDL_winrtpaths.cpp mentioning that /ZW must be used when compiling the file + TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all */ #include "SDL_config.h" @@ -7,10 +7,11 @@ #ifdef __WINRT__ extern "C" { +#include "SDL_filesystem.h" #include "SDL_error.h" #include "SDL_stdinc.h" #include "SDL_system.h" -#include "../windows/SDL_windows.h" +#include "../../core/windows/SDL_windows.h" } #include @@ -91,4 +92,57 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType) return utf8Paths[pathType].c_str(); } +extern "C" char * +SDL_GetBasePath(void) +{ + const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION); + size_t destPathLen; + char * destPath = NULL; + + if (!srcPath) { + SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError()); + return NULL; + } + + destPathLen = SDL_strlen(srcPath) + 2; + destPath = (char *) SDL_malloc(destPathLen); + if (!destPath) { + SDL_OutOfMemory(); + return NULL; + } + + SDL_snprintf(destPath, destPathLen, "%s\\", srcPath); + return destPath; +} + +extern "C" char * +SDL_GetPrefPath(const char *org, const char *app) +{ +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP + /* A 'Roaming' folder is not available in Windows Phone 8, however a 'Local' folder is. */ + const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_LOCAL_FOLDER); +#else + /* A 'Roaming' folder is available on Windows 8 and 8.1. Use that. */ + const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_ROAMING_FOLDER); +#endif + + size_t destPathLen; + char * destPath = NULL; + + if (!srcPath) { + SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError()); + return NULL; + } + + destPathLen = SDL_strlen(srcPath) + SDL_strlen(org) + SDL_strlen(app) + 4; + destPath = (char *) SDL_malloc(destPathLen); + if (!destPath) { + SDL_OutOfMemory(); + return NULL; + } + + SDL_snprintf(destPath, destPathLen, "%s\\%s\\%s\\", srcPath, org, app); + return destPath; +} + #endif /* __WINRT__ */