WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
authorDavid Ludwig <dludwig@pobox.com>
Mon, 28 Oct 2013 15:41:22 -0400
changeset 8538d9279c169943
parent 8537 ea81cf5b6252
child 8539 41885a5f550d
WinRT: implemented SDL_GetBasePath and SDL_GetPrefPath
VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj
VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj.filters
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj
VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters
src/core/winrt/SDL_winrtpaths.cpp
src/filesystem/winrt/SDL_sysfilesystem.cpp
     1.1 --- a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj	Sun Oct 27 23:19:35 2013 -0400
     1.2 +++ b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj	Mon Oct 28 15:41:22 2013 -0400
     1.3 @@ -156,6 +156,7 @@
     1.4      <ClInclude Include="..\..\include\SDL_endian.h" />
     1.5      <ClInclude Include="..\..\include\SDL_error.h" />
     1.6      <ClInclude Include="..\..\include\SDL_events.h" />
     1.7 +    <ClInclude Include="..\..\include\SDL_filesystem.h" />
     1.8      <ClInclude Include="..\..\include\SDL_haptic.h" />
     1.9      <ClInclude Include="..\..\include\SDL_hints.h" />
    1.10      <ClInclude Include="..\..\include\SDL_input.h" />
    1.11 @@ -288,12 +289,6 @@
    1.12        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.13        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.14      </ClCompile>
    1.15 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtpaths.cpp">
    1.16 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.17 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.18 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.19 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.20 -    </ClCompile>
    1.21      <ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
    1.22      <ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
    1.23      <ClCompile Include="..\..\src\events\SDL_dropevents.c" />
    1.24 @@ -304,6 +299,12 @@
    1.25      <ClCompile Include="..\..\src\events\SDL_quit.c" />
    1.26      <ClCompile Include="..\..\src\events\SDL_touch.c" />
    1.27      <ClCompile Include="..\..\src\events\SDL_windowevents.c" />
    1.28 +    <ClCompile Include="..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp">
    1.29 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    1.30 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    1.31 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    1.32 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    1.33 +    </ClCompile>
    1.34      <ClCompile Include="..\..\src\file\SDL_rwops.c" />
    1.35      <ClCompile Include="..\..\src\haptic\dummy\SDL_syshaptic.c" />
    1.36      <ClCompile Include="..\..\src\haptic\SDL_haptic.c" />
     2.1 --- a/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj.filters	Sun Oct 27 23:19:35 2013 -0400
     2.2 +++ b/VisualC-WinPhone/SDL/SDL-WinPhone_VS2012.vcxproj.filters	Mon Oct 28 15:41:22 2013 -0400
     2.3 @@ -342,6 +342,9 @@
     2.4      <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_common.h">
     2.5        <Filter>Source Files</Filter>
     2.6      </ClInclude>
     2.7 +    <ClInclude Include="..\..\include\SDL_filesystem.h">
     2.8 +      <Filter>Header Files</Filter>
     2.9 +    </ClInclude>
    2.10    </ItemGroup>
    2.11    <ItemGroup>
    2.12      <ClCompile Include="..\..\src\atomic\SDL_atomic.c">
    2.13 @@ -584,9 +587,6 @@
    2.14      <ClCompile Include="..\..\src\stdlib\SDL_malloc.c">
    2.15        <Filter>Source Files</Filter>
    2.16      </ClCompile>
    2.17 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtpaths.cpp">
    2.18 -      <Filter>Source Files</Filter>
    2.19 -    </ClCompile>
    2.20      <ClCompile Include="..\..\src\video\winrt\SDL_winrtevents.cpp">
    2.21        <Filter>Source Files</Filter>
    2.22      </ClCompile>
    2.23 @@ -611,6 +611,9 @@
    2.24      <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_common.cpp">
    2.25        <Filter>Source Files</Filter>
    2.26      </ClCompile>
    2.27 +    <ClCompile Include="..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp">
    2.28 +      <Filter>Source Files</Filter>
    2.29 +    </ClCompile>
    2.30    </ItemGroup>
    2.31    <ItemGroup>
    2.32      <FxCompile Include="..\..\src\render\direct3d11\SDL_D3D11_PixelShader_FixedColor.hlsl">
     3.1 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Sun Oct 27 23:19:35 2013 -0400
     3.2 +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj	Mon Oct 28 15:41:22 2013 -0400
     3.3 @@ -71,14 +71,6 @@
     3.4        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
     3.5        <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
     3.6      </ClCompile>
     3.7 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtpaths.cpp">
     3.8 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
     3.9 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    3.10 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    3.11 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    3.12 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    3.13 -      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    3.14 -    </ClCompile>
    3.15      <ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
    3.16      <ClCompile Include="..\..\src\events\SDL_clipboardevents.c" />
    3.17      <ClCompile Include="..\..\src\events\SDL_dropevents.c" />
    3.18 @@ -89,6 +81,14 @@
    3.19      <ClCompile Include="..\..\src\events\SDL_quit.c" />
    3.20      <ClCompile Include="..\..\src\events\SDL_touch.c" />
    3.21      <ClCompile Include="..\..\src\events\SDL_windowevents.c" />
    3.22 +    <ClCompile Include="..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp">
    3.23 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</CompileAsWinRT>
    3.24 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</CompileAsWinRT>
    3.25 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
    3.26 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</CompileAsWinRT>
    3.27 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</CompileAsWinRT>
    3.28 +      <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
    3.29 +    </ClCompile>
    3.30      <ClCompile Include="..\..\src\file\SDL_rwops.c" />
    3.31      <ClCompile Include="..\..\src\haptic\dummy\SDL_syshaptic.c" />
    3.32      <ClCompile Include="..\..\src\haptic\SDL_haptic.c" />
    3.33 @@ -211,6 +211,7 @@
    3.34      <ClInclude Include="..\..\include\SDL_endian.h" />
    3.35      <ClInclude Include="..\..\include\SDL_error.h" />
    3.36      <ClInclude Include="..\..\include\SDL_events.h" />
    3.37 +    <ClInclude Include="..\..\include\SDL_filesystem.h" />
    3.38      <ClInclude Include="..\..\include\SDL_haptic.h" />
    3.39      <ClInclude Include="..\..\include\SDL_hints.h" />
    3.40      <ClInclude Include="..\..\include\SDL_input.h" />
     4.1 --- a/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters	Sun Oct 27 23:19:35 2013 -0400
     4.2 +++ b/VisualC-WinRT/SDL/SDL-WinRT_VS2012.vcxproj.filters	Mon Oct 28 15:41:22 2013 -0400
     4.3 @@ -258,9 +258,6 @@
     4.4      <ClCompile Include="..\..\src\video\winrt\SDL_winrtvideo.cpp">
     4.5        <Filter>Source Files</Filter>
     4.6      </ClCompile>
     4.7 -    <ClCompile Include="..\..\src\core\winrt\SDL_winrtpaths.cpp">
     4.8 -      <Filter>Source Files</Filter>
     4.9 -    </ClCompile>
    4.10      <ClCompile Include="..\..\src\video\winrt\SDL_winrtkeyboard.cpp">
    4.11        <Filter>Source Files</Filter>
    4.12      </ClCompile>
    4.13 @@ -279,6 +276,9 @@
    4.14      <ClCompile Include="..\..\src\core\winrt\SDL_winrtapp_common.cpp">
    4.15        <Filter>Source Files</Filter>
    4.16      </ClCompile>
    4.17 +    <ClCompile Include="..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp">
    4.18 +      <Filter>Source Files</Filter>
    4.19 +    </ClCompile>
    4.20    </ItemGroup>
    4.21    <ItemGroup>
    4.22      <ClInclude Include="..\..\include\begin_code.h">
    4.23 @@ -614,6 +614,9 @@
    4.24      <ClInclude Include="..\..\src\core\winrt\SDL_winrtapp_common.h">
    4.25        <Filter>Source Files</Filter>
    4.26      </ClInclude>
    4.27 +    <ClInclude Include="..\..\include\SDL_filesystem.h">
    4.28 +      <Filter>Header Files</Filter>
    4.29 +    </ClInclude>
    4.30    </ItemGroup>
    4.31    <ItemGroup>
    4.32      <Filter Include="Header Files">
     5.1 --- a/src/core/winrt/SDL_winrtpaths.cpp	Sun Oct 27 23:19:35 2013 -0400
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,94 +0,0 @@
     5.4 -/* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp
     5.5 -   TODO, WinRT: add note to SDL_winrtpaths.cpp mentioning that /ZW must be used when compiling the file
     5.6 -*/
     5.7 -
     5.8 -#include "SDL_config.h"
     5.9 -
    5.10 -#ifdef __WINRT__
    5.11 -
    5.12 -extern "C" {
    5.13 -#include "SDL_error.h"
    5.14 -#include "SDL_stdinc.h"
    5.15 -#include "SDL_system.h"
    5.16 -#include "../windows/SDL_windows.h"
    5.17 -}
    5.18 -
    5.19 -#include <string>
    5.20 -#include <unordered_map>
    5.21 -
    5.22 -using namespace std;
    5.23 -using namespace Windows::Storage;
    5.24 -
    5.25 -extern "C" const wchar_t *
    5.26 -SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
    5.27 -{
    5.28 -    switch (pathType) {
    5.29 -        case SDL_WINRT_PATH_INSTALLED_LOCATION:
    5.30 -        {
    5.31 -            static wstring path;
    5.32 -            if (path.empty()) {
    5.33 -                path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
    5.34 -            }
    5.35 -            return path.c_str();
    5.36 -        }
    5.37 -
    5.38 -        case SDL_WINRT_PATH_LOCAL_FOLDER:
    5.39 -        {
    5.40 -            static wstring path;
    5.41 -            if (path.empty()) {
    5.42 -                path = ApplicationData::Current->LocalFolder->Path->Data();
    5.43 -            }
    5.44 -            return path.c_str();
    5.45 -        }
    5.46 -
    5.47 -#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    5.48 -        case SDL_WINRT_PATH_ROAMING_FOLDER:
    5.49 -        {
    5.50 -            static wstring path;
    5.51 -            if (path.empty()) {
    5.52 -                path = ApplicationData::Current->RoamingFolder->Path->Data();
    5.53 -            }
    5.54 -            return path.c_str();
    5.55 -        }
    5.56 -
    5.57 -        case SDL_WINRT_PATH_TEMP_FOLDER:
    5.58 -        {
    5.59 -            static wstring path;
    5.60 -            if (path.empty()) {
    5.61 -                path = ApplicationData::Current->TemporaryFolder->Path->Data();
    5.62 -            }
    5.63 -            return path.c_str();
    5.64 -        }
    5.65 -#endif
    5.66 -
    5.67 -        default:
    5.68 -            break;
    5.69 -    }
    5.70 -
    5.71 -    SDL_Unsupported();
    5.72 -    return NULL;
    5.73 -}
    5.74 -
    5.75 -extern "C" const char *
    5.76 -SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
    5.77 -{
    5.78 -    typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
    5.79 -    static UTF8PathMap utf8Paths;
    5.80 -
    5.81 -    UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
    5.82 -    if (searchResult != utf8Paths.end()) {
    5.83 -        return searchResult->second.c_str();
    5.84 -    }
    5.85 -
    5.86 -    const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
    5.87 -    if (!ucs2Path) {
    5.88 -        return NULL;
    5.89 -    }
    5.90 -
    5.91 -    char * utf8Path = WIN_StringToUTF8(ucs2Path);
    5.92 -    utf8Paths[pathType] = utf8Path;
    5.93 -    SDL_free(utf8Path);
    5.94 -    return utf8Paths[pathType].c_str();
    5.95 -}
    5.96 -
    5.97 -#endif /* __WINRT__ */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/filesystem/winrt/SDL_sysfilesystem.cpp	Mon Oct 28 15:41:22 2013 -0400
     6.3 @@ -0,0 +1,148 @@
     6.4 +/* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp
     6.5 +   TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all
     6.6 +*/
     6.7 +
     6.8 +#include "SDL_config.h"
     6.9 +
    6.10 +#ifdef __WINRT__
    6.11 +
    6.12 +extern "C" {
    6.13 +#include "SDL_filesystem.h"
    6.14 +#include "SDL_error.h"
    6.15 +#include "SDL_stdinc.h"
    6.16 +#include "SDL_system.h"
    6.17 +#include "../../core/windows/SDL_windows.h"
    6.18 +}
    6.19 +
    6.20 +#include <string>
    6.21 +#include <unordered_map>
    6.22 +
    6.23 +using namespace std;
    6.24 +using namespace Windows::Storage;
    6.25 +
    6.26 +extern "C" const wchar_t *
    6.27 +SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
    6.28 +{
    6.29 +    switch (pathType) {
    6.30 +        case SDL_WINRT_PATH_INSTALLED_LOCATION:
    6.31 +        {
    6.32 +            static wstring path;
    6.33 +            if (path.empty()) {
    6.34 +                path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
    6.35 +            }
    6.36 +            return path.c_str();
    6.37 +        }
    6.38 +
    6.39 +        case SDL_WINRT_PATH_LOCAL_FOLDER:
    6.40 +        {
    6.41 +            static wstring path;
    6.42 +            if (path.empty()) {
    6.43 +                path = ApplicationData::Current->LocalFolder->Path->Data();
    6.44 +            }
    6.45 +            return path.c_str();
    6.46 +        }
    6.47 +
    6.48 +#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
    6.49 +        case SDL_WINRT_PATH_ROAMING_FOLDER:
    6.50 +        {
    6.51 +            static wstring path;
    6.52 +            if (path.empty()) {
    6.53 +                path = ApplicationData::Current->RoamingFolder->Path->Data();
    6.54 +            }
    6.55 +            return path.c_str();
    6.56 +        }
    6.57 +
    6.58 +        case SDL_WINRT_PATH_TEMP_FOLDER:
    6.59 +        {
    6.60 +            static wstring path;
    6.61 +            if (path.empty()) {
    6.62 +                path = ApplicationData::Current->TemporaryFolder->Path->Data();
    6.63 +            }
    6.64 +            return path.c_str();
    6.65 +        }
    6.66 +#endif
    6.67 +
    6.68 +        default:
    6.69 +            break;
    6.70 +    }
    6.71 +
    6.72 +    SDL_Unsupported();
    6.73 +    return NULL;
    6.74 +}
    6.75 +
    6.76 +extern "C" const char *
    6.77 +SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
    6.78 +{
    6.79 +    typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
    6.80 +    static UTF8PathMap utf8Paths;
    6.81 +
    6.82 +    UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
    6.83 +    if (searchResult != utf8Paths.end()) {
    6.84 +        return searchResult->second.c_str();
    6.85 +    }
    6.86 +
    6.87 +    const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
    6.88 +    if (!ucs2Path) {
    6.89 +        return NULL;
    6.90 +    }
    6.91 +
    6.92 +    char * utf8Path = WIN_StringToUTF8(ucs2Path);
    6.93 +    utf8Paths[pathType] = utf8Path;
    6.94 +    SDL_free(utf8Path);
    6.95 +    return utf8Paths[pathType].c_str();
    6.96 +}
    6.97 +
    6.98 +extern "C" char *
    6.99 +SDL_GetBasePath(void)
   6.100 +{
   6.101 +    const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
   6.102 +    size_t destPathLen;
   6.103 +    char * destPath = NULL;
   6.104 +
   6.105 +    if (!srcPath) {
   6.106 +        SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
   6.107 +        return NULL;
   6.108 +    }
   6.109 +
   6.110 +    destPathLen = SDL_strlen(srcPath) + 2;
   6.111 +    destPath = (char *) SDL_malloc(destPathLen);
   6.112 +    if (!destPath) {
   6.113 +        SDL_OutOfMemory();
   6.114 +        return NULL;
   6.115 +    }
   6.116 +
   6.117 +    SDL_snprintf(destPath, destPathLen, "%s\\", srcPath);
   6.118 +    return destPath;
   6.119 +}
   6.120 +
   6.121 +extern "C" char *
   6.122 +SDL_GetPrefPath(const char *org, const char *app)
   6.123 +{
   6.124 +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   6.125 +    /* A 'Roaming' folder is not available in Windows Phone 8, however a 'Local' folder is. */
   6.126 +    const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_LOCAL_FOLDER);
   6.127 +#else
   6.128 +    /* A 'Roaming' folder is available on Windows 8 and 8.1.  Use that. */
   6.129 +    const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_ROAMING_FOLDER);
   6.130 +#endif
   6.131 +
   6.132 +    size_t destPathLen;
   6.133 +    char * destPath = NULL;
   6.134 +
   6.135 +    if (!srcPath) {
   6.136 +        SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError());
   6.137 +        return NULL;
   6.138 +    }
   6.139 +
   6.140 +    destPathLen = SDL_strlen(srcPath) + SDL_strlen(org) + SDL_strlen(app) + 4;
   6.141 +    destPath = (char *) SDL_malloc(destPathLen);
   6.142 +    if (!destPath) {
   6.143 +        SDL_OutOfMemory();
   6.144 +        return NULL;
   6.145 +    }
   6.146 +
   6.147 +    SDL_snprintf(destPath, destPathLen, "%s\\%s\\%s\\", srcPath, org, app);
   6.148 +    return destPath;
   6.149 +}
   6.150 +
   6.151 +#endif /* __WINRT__ */