SDL_winrtpaths.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp
  2. TODO, WinRT: add note to SDL_winrtpaths.cpp mentioning that /ZW must be used when compiling the file
  3. */
  4. #include "SDL_config.h"
  5. #ifdef __WINRT__
  6. extern "C" {
  7. #include "SDL_error.h"
  8. #include "SDL_stdinc.h"
  9. #include "SDL_system.h"
  10. #include "../windows/SDL_windows.h"
  11. }
  12. #include <string>
  13. #include <unordered_map>
  14. using namespace std;
  15. using namespace Windows::Storage;
  16. extern "C" const wchar_t *
  17. SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
  18. {
  19. switch (pathType) {
  20. case SDL_WINRT_PATH_INSTALLED_LOCATION:
  21. {
  22. static wstring path;
  23. if (path.empty()) {
  24. path = Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data();
  25. }
  26. return path.c_str();
  27. }
  28. case SDL_WINRT_PATH_LOCAL_FOLDER:
  29. {
  30. static wstring path;
  31. if (path.empty()) {
  32. path = ApplicationData::Current->LocalFolder->Path->Data();
  33. }
  34. return path.c_str();
  35. }
  36. #if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
  37. case SDL_WINRT_PATH_ROAMING_FOLDER:
  38. {
  39. static wstring path;
  40. if (path.empty()) {
  41. path = ApplicationData::Current->RoamingFolder->Path->Data();
  42. }
  43. return path.c_str();
  44. }
  45. case SDL_WINRT_PATH_TEMP_FOLDER:
  46. {
  47. static wstring path;
  48. if (path.empty()) {
  49. path = ApplicationData::Current->TemporaryFolder->Path->Data();
  50. }
  51. return path.c_str();
  52. }
  53. #endif
  54. default:
  55. break;
  56. }
  57. SDL_Unsupported();
  58. return NULL;
  59. }
  60. extern "C" const char *
  61. SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
  62. {
  63. typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
  64. static UTF8PathMap utf8Paths;
  65. UTF8PathMap::iterator searchResult = utf8Paths.find(pathType);
  66. if (searchResult != utf8Paths.end()) {
  67. return searchResult->second.c_str();
  68. }
  69. const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType);
  70. if (!ucs2Path) {
  71. return NULL;
  72. }
  73. char * utf8Path = WIN_StringToUTF8(ucs2Path);
  74. utf8Paths[pathType] = utf8Path;
  75. SDL_free(utf8Path);
  76. return utf8Paths[pathType].c_str();
  77. }
  78. #endif /* __WINRT__ */