author  Sam Lantinga <slouken@libsdl.org> 
Thu, 13 Mar 2014 21:21:26 0700  
changeset 8616  ec011c16e2fd 
parent 8600  092802455aed 
child 9228  9ecf7c9f49e5 
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 

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

23 
/* TODO, WinRT: include copyright info in SDL_winrtpaths.cpp 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

24 
TODO, WinRT: remove the need to compile this with C++/CX (/ZW) extensions, and if possible, without C++ at all 
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 

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

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

28 

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

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

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

31 
#include "SDL_error.h" 
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 

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

65 
#if WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP 
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 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

148 
/* A 'Roaming' folder is not available in Windows Phone 8, however a 'Local' folder is. */ 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

149 
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

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

151 
/* A 'Roaming' folder is available on Windows 8 and 8.1. Use that. */ 
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_ROAMING_FOLDER); 
c3e9a2b93517
Fixed line endings on WinRT source code
Sam Lantinga <slouken@libsdl.org>
parents:
8539
diff
changeset

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

154 

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

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

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

157 

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

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

159 
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

160 
return 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 

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

163 
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

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

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

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

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

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

169 

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

170 
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

171 
return destPath; 
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 
#endif /* __WINRT__ */ 