author  David Ludwig <dludwig@pobox.com> 
Thu, 27 Nov 2014 08:50:11 0500  
changeset 9241  4900e838abbc 
parent 9229  c4ff10b9a23c 
child 9242  f4d353bd5d16 
permissions  rwrr 
8616
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

1 
/* 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

2 
Simple DirectMedia Layer 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

3 
Copyright (C) 19972014 Sam Lantinga <slouken@libsdl.org> 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

4 

ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

5 
This software is provided 'asis', without any express or implied 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

6 
warranty. In no event will the authors be held liable for any damages 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

7 
arising from the use of this software. 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

8 

ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

9 
Permission is granted to anyone to use this software for any purpose, 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

10 
including commercial applications, and to alter it and redistribute it 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

11 
freely, subject to the following restrictions: 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

12 

ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

13 
1. The origin of this software must not be misrepresented; you must not 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

14 
claim that you wrote the original software. If you use this software 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

15 
in a product, an acknowledgment in the product documentation would be 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

16 
appreciated but is not required. 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

17 
2. Altered source versions must be plainly marked as such, and must not be 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

18 
misrepresented as being the original software. 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

19 
3. This notice may not be removed or altered from any source distribution. 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

20 
*/ 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

21 
#include "../../SDL_internal.h" 
ec011c16e2fd
Added missing copyright notices
Sam Lantinga <slouken@libsdl.org>
parents:
8600
diff
changeset

22 

9241
4900e838abbc
WinRT: removed a completed TODO item from an inline comment
David Ludwig <dludwig@pobox.com>
parents:
9229
diff
changeset

23 
/* TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

24 
*/ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

25 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

26 
#ifdef __WINRT__ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

27 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

28 
extern "C" { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

29 
#include "SDL_filesystem.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

30 
#include "SDL_error.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

31 
#include "SDL_stdinc.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

32 
#include "SDL_system.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

33 
#include "../../core/windows/SDL_windows.h" 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

34 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

35 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

36 
#include <string> 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

37 
#include <unordered_map> 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

38 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

39 
using namespace std; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

40 
using namespace Windows::Storage; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

41 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

42 
extern "C" const wchar_t * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

43 
SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

44 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

45 
switch (pathType) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

46 
case SDL_WINRT_PATH_INSTALLED_LOCATION: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

47 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

48 
static wstring path; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

49 
if (path.empty()) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

50 
path = Windows::ApplicationModel::Package::Current>InstalledLocation>Path>Data(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

51 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

52 
return path.c_str(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

53 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

54 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

55 
case SDL_WINRT_PATH_LOCAL_FOLDER: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

56 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

57 
static wstring path; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

58 
if (path.empty()) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

59 
path = ApplicationData::Current>LocalFolder>Path>Data(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

60 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

61 
return path.c_str(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

62 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

63 

9228
9ecf7c9f49e5
WinRT: allowed 'roaming' and 'temp' folder paths to be retrieved on WinPhone 8.1
David Ludwig <dludwig@pobox.com>
parents:
8616
diff
changeset

64 
#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)  (NTDDI_VERSION > NTDDI_WIN8) 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

65 
case SDL_WINRT_PATH_ROAMING_FOLDER: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

66 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

67 
static wstring path; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

68 
if (path.empty()) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

69 
path = ApplicationData::Current>RoamingFolder>Path>Data(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

70 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

71 
return path.c_str(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

72 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

73 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

74 
case SDL_WINRT_PATH_TEMP_FOLDER: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

75 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

76 
static wstring path; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

77 
if (path.empty()) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

78 
path = ApplicationData::Current>TemporaryFolder>Path>Data(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

79 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

80 
return path.c_str(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

81 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

82 
#endif 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

83 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

84 
default: 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

85 
break; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

86 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

87 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

88 
SDL_Unsupported(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

89 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

90 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

91 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

92 
extern "C" const char * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

93 
SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

94 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

95 
typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

96 
static UTF8PathMap utf8Paths; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

97 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

98 
UTF8PathMap::iterator searchResult = utf8Paths.find(pathType); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

99 
if (searchResult != utf8Paths.end()) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

100 
return searchResult>second.c_str(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

101 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

102 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

103 
const wchar_t * ucs2Path = SDL_WinRTGetFSPathUNICODE(pathType); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

104 
if (!ucs2Path) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

105 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

106 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

107 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

108 
char * utf8Path = WIN_StringToUTF8(ucs2Path); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

109 
utf8Paths[pathType] = utf8Path; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

110 
SDL_free(utf8Path); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

111 
return utf8Paths[pathType].c_str(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

112 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

113 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

114 
extern "C" char * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

115 
SDL_GetBasePath(void) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

116 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

117 
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

118 
size_t destPathLen; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

119 
char * destPath = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

120 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

121 
if (!srcPath) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

122 
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError()); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

123 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

124 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

125 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

126 
destPathLen = SDL_strlen(srcPath) + 2; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

127 
destPath = (char *) SDL_malloc(destPathLen); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

128 
if (!destPath) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

129 
SDL_OutOfMemory(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

130 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

131 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

132 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

133 
SDL_snprintf(destPath, destPathLen, "%s\\", srcPath); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

134 
return destPath; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

135 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

136 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

137 
extern "C" char * 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

138 
SDL_GetPrefPath(const char *org, const char *app) 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

139 
{ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

140 
/* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

141 
* earlier is not available on WinRT or Windows Phone. WinRT provides 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

142 
* a similar API, but SHGetFolderPath can't be called, at least not 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

143 
* without violating Microsoft's appstore requirements. 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

144 
*/ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

145 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

146 
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP 
9228
9ecf7c9f49e5
WinRT: allowed 'roaming' and 'temp' folder paths to be retrieved on WinPhone 8.1
David Ludwig <dludwig@pobox.com>
parents:
8616
diff
changeset

147 
/* A 'Roaming' folder is not available in Windows Phone 8.0, however a 
9ecf7c9f49e5
WinRT: allowed 'roaming' and 'temp' folder paths to be retrieved on WinPhone 8.1
David Ludwig <dludwig@pobox.com>
parents:
8616
diff
changeset

148 
* 'Local' folder is. Use the 'Local' folder in order to preserve 
9ecf7c9f49e5
WinRT: allowed 'roaming' and 'temp' folder paths to be retrieved on WinPhone 8.1
David Ludwig <dludwig@pobox.com>
parents:
8616
diff
changeset

149 
* compatibility with Windows Phone 8.0, and with appinstalls that have 
9ecf7c9f49e5
WinRT: allowed 'roaming' and 'temp' folder paths to be retrieved on WinPhone 8.1
David Ludwig <dludwig@pobox.com>
parents:
8616
diff
changeset

150 
* been updated from 8.0based, to 8.1based apps. 
9ecf7c9f49e5
WinRT: allowed 'roaming' and 'temp' folder paths to be retrieved on WinPhone 8.1
David Ludwig <dludwig@pobox.com>
parents:
8616
diff
changeset

151 
*/ 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

152 
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_LOCAL_FOLDER); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

153 
#else 
9228
9ecf7c9f49e5
WinRT: allowed 'roaming' and 'temp' folder paths to be retrieved on WinPhone 8.1
David Ludwig <dludwig@pobox.com>
parents:
8616
diff
changeset

154 
/* A 'Roaming' folder is available on Windows 8 and 8.1. Use that. 
9ecf7c9f49e5
WinRT: allowed 'roaming' and 'temp' folder paths to be retrieved on WinPhone 8.1
David Ludwig <dludwig@pobox.com>
parents:
8616
diff
changeset

155 
*/ 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

156 
const char * srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_ROAMING_FOLDER); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

157 
#endif 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

158 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

159 
size_t destPathLen; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

160 
char * destPath = NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

161 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

162 
if (!srcPath) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

163 
SDL_SetError("Couldn't locate our basepath: %s", SDL_GetError()); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

164 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

165 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

166 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

167 
destPathLen = SDL_strlen(srcPath) + SDL_strlen(org) + SDL_strlen(app) + 4; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

168 
destPath = (char *) SDL_malloc(destPathLen); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

169 
if (!destPath) { 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

170 
SDL_OutOfMemory(); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

171 
return NULL; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

172 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

173 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

174 
SDL_snprintf(destPath, destPathLen, "%s\\%s\\%s\\", srcPath, org, app); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

175 
return destPath; 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

176 
} 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

177 

c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

178 
#endif /* __WINRT__ */ 