3939#include < SDL.h>
4040#include < string>
4141
42- #ifdef HX_WINDOWS
4342#include < locale>
4443#include < codecvt>
45- #endif
44+
45+ using wstring_convert = std::wstring_convert<std::codecvt_utf8<wchar_t >>;
4646
4747
4848namespace lime {
@@ -111,27 +111,31 @@ namespace lime {
111111 case APPLICATION: {
112112
113113 char * path = SDL_GetBasePath ();
114- #ifdef HX_WINDOWS
115- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
116- result = new std::wstring (converter.from_bytes (path));
117- #else
118- result = new std::wstring (path, path + strlen (path));
119- #endif
120- SDL_free (path);
114+
115+ if (path != nullptr ) {
116+
117+ wstring_convert converter;
118+ result = new std::wstring (converter.from_bytes (path));
119+ SDL_free (path);
120+
121+ }
122+
121123 break ;
122124
123125 }
124126
125127 case APPLICATION_STORAGE: {
126128
127129 char * path = SDL_GetPrefPath (company, title);
128- #ifdef HX_WINDOWS
129- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
130- result = new std::wstring (converter.from_bytes (path));
131- #else
132- result = new std::wstring (path, path + strlen (path));
133- #endif
134- SDL_free (path);
130+
131+ if (path != nullptr ) {
132+
133+ wstring_convert converter;
134+ result = new std::wstring (converter.from_bytes (path));
135+ SDL_free (path);
136+
137+ }
138+
135139 break ;
136140
137141 }
@@ -145,11 +149,9 @@ namespace lime {
145149
146150 #elif defined (HX_WINDOWS)
147151
148- char folderPath[MAX_PATH] = " " ;
149- SHGetFolderPath (NULL , CSIDL_DESKTOPDIRECTORY, NULL , SHGFP_TYPE_CURRENT, folderPath);
150- // WIN_StringToUTF8 (folderPath);
151- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
152- result = new std::wstring (converter.from_bytes (folderPath));
152+ WCHAR folderPath[MAX_PATH] = L" " ;
153+ SHGetFolderPathW (NULL , CSIDL_DESKTOPDIRECTORY, NULL , SHGFP_TYPE_CURRENT, folderPath);
154+ result = new std::wstring (folderPath);
153155
154156 #elif defined (IPHONE)
155157
@@ -159,15 +161,14 @@ namespace lime {
159161
160162 char const * home = getenv (" HOME" );
161163
162- if (home = = NULL ) {
164+ if (home ! = NULL ) {
163165
164- return 0 ;
166+ std::string path = std::string (home) + std::string (" /Desktop" );
167+ wstring_convert converter;
168+ result = new std::wstring (converter.from_bytes (path));
165169
166170 }
167171
168- std::string path = std::string (home) + std::string (" /Desktop" );
169- result = new std::wstring (path.begin (), path.end ());
170-
171172 #endif
172173 break ;
173174
@@ -182,11 +183,9 @@ namespace lime {
182183
183184 #elif defined (HX_WINDOWS)
184185
185- char folderPath[MAX_PATH] = " " ;
186- SHGetFolderPath (NULL , CSIDL_MYDOCUMENTS, NULL , SHGFP_TYPE_CURRENT, folderPath);
187- // WIN_StringToUTF8 (folderPath);
188- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
189- result = new std::wstring (converter.from_bytes (folderPath));
186+ WCHAR folderPath[MAX_PATH] = L" " ;
187+ SHGetFolderPathW (NULL , CSIDL_MYDOCUMENTS, NULL , SHGFP_TYPE_CURRENT, folderPath);
188+ result = new std::wstring (folderPath);
190189
191190 #elif defined (IPHONE)
192191
@@ -203,7 +202,8 @@ namespace lime {
203202 if (home != NULL ) {
204203
205204 std::string path = std::string (home) + std::string (" /Documents" );
206- result = new std::wstring (path.begin (), path.end ());
205+ wstring_convert converter;
206+ result = new std::wstring (converter.from_bytes (path));
207207
208208 }
209209
@@ -220,11 +220,9 @@ namespace lime {
220220
221221 #elif defined (HX_WINDOWS)
222222
223- char folderPath[MAX_PATH] = " " ;
224- SHGetFolderPath (NULL , CSIDL_FONTS, NULL , SHGFP_TYPE_CURRENT, folderPath);
225- // WIN_StringToUTF8 (folderPath);
226- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
227- result = new std::wstring (converter.from_bytes (folderPath));
223+ WCHAR folderPath[MAX_PATH] = L" " ;
224+ SHGetFolderPathW (NULL , CSIDL_FONTS, NULL , SHGFP_TYPE_CURRENT, folderPath);
225+ result = new std::wstring (folderPath);
228226
229227 #elif defined (HX_MACOS)
230228
@@ -260,11 +258,9 @@ namespace lime {
260258
261259 #elif defined (HX_WINDOWS)
262260
263- char folderPath[MAX_PATH] = " " ;
264- SHGetFolderPath (NULL , CSIDL_PROFILE, NULL , SHGFP_TYPE_CURRENT, folderPath);
265- // WIN_StringToUTF8 (folderPath);
266- std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
267- result = new std::wstring (converter.from_bytes (folderPath));
261+ WCHAR folderPath[MAX_PATH] = L" " ;
262+ SHGetFolderPathW (NULL , CSIDL_PROFILE, NULL , SHGFP_TYPE_CURRENT, folderPath);
263+ result = new std::wstring (folderPath);
268264
269265 #elif defined (IPHONE)
270266
@@ -281,7 +277,8 @@ namespace lime {
281277 if (home != NULL ) {
282278
283279 std::string path = std::string (home);
284- result = new std::wstring (path.begin (), path.end ());
280+ wstring_convert converter;
281+ result = new std::wstring (converter.from_bytes (path));
285282
286283 }
287284
@@ -909,4 +906,4 @@ namespace lime {
909906 }
910907
911908
912- }
909+ }
0 commit comments