author  David Ludwig <dludwig@pobox.com> 
Thu, 27 Nov 2014 09:55:34 0500  
changeset 9242  f4d353bd5d16 
parent 9241  4900e838abbc 
child 9247  eddb899239fe 
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" 
9242
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

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

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

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

34 
#include "../../core/windows/SDL_windows.h" 
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 

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

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

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

39 

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

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

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

42 

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

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

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

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

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

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

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

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

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

51 
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

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

53 
return path.c_str(); 
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 

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

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

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

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

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

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

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

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

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

64 

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

65 
#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

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

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

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

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

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

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

72 
return path.c_str(); 
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 

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

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

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

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

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

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

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

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

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

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

84 

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

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

86 
break; 
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 

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

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

90 
return NULL; 
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 

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

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

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

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

96 
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

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

98 

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

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

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

101 
return searchResult>second.c_str(); 
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 

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

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

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

106 
return NULL; 
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 

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

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

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

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

112 
return utf8Paths[pathType].c_str(); 
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 

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

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

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

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

118 
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

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

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

121 

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

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

123 
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

124 
return NULL; 
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 

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

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

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

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

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

131 
return NULL; 
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 

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

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

135 
return destPath; 
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 

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

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

139 
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

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

141 
/* 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

142 
* 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

143 
* 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

144 
* without violating Microsoft's appstore requirements. 
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 

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

147 
#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

148 
/* 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

149 
* '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

150 
* 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

151 
* 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

152 
*/ 
9242
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

153 
SDL_WinRT_Path pathType = SDL_WINRT_PATH_LOCAL_FOLDER; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

154 
#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

155 
/* 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

156 
*/ 
9242
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

157 
SDL_WinRT_Path pathType = SDL_WINRT_PATH_ROAMING_FOLDER; 
8582
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

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

159 

9242
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

160 
const char * hint = SDL_GetHint(SDL_HINT_WINRT_PREF_PATH_ROOT); 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

161 
if (hint) { 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

162 
if (SDL_strcasecmp(hint, "local") == 0) { 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

163 
pathType = SDL_WINRT_PATH_LOCAL_FOLDER; 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

164 
} 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

165 
#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP)  (NTDDI_VERSION > NTDDI_WIN8) 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

166 
else if (SDL_strcasecmp(hint, "roaming") == 0) { 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

167 
pathType = SDL_WINRT_PATH_ROAMING_FOLDER; 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

168 
} 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

169 
#endif 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

170 
} 
f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

171 

f4d353bd5d16
WinRT: added SDL_HINT_WINRT_PREF_PATH_ROOT
David Ludwig <dludwig@pobox.com>
parents:
9241
diff
changeset

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

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

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

175 

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

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

177 
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

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

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

180 

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

181 
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

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

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

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

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

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

187 

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

188 
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

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

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

191 

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

192 
#endif /* __WINRT__ */ 