| 1175 | } |
| 1176 | |
| 1177 | string GetCurrentDir() |
| 1178 | { |
| 1179 | char buffer[1024]; |
| 1180 | #if defined(_MSC_VER) || defined(_WIN32) |
| 1181 | #ifdef _WIN32_WCE |
| 1182 | static TCHAR apppath[MAX_PATH] = TEXT(""); |
| 1183 | if (!apppath[0]) |
| 1184 | { |
| 1185 | GetModuleFileName(NULL, apppath, MAX_PATH); |
| 1186 | |
| 1187 | int appLen = _tcslen(apppath); |
| 1188 | |
| 1189 | // Look for the last backslash in the path, which would be the end |
| 1190 | // of the path itself and the start of the filename. We only want |
| 1191 | // the path part of the exe's full-path filename |
| 1192 | // Safety is that we make sure not to walk off the front of the |
| 1193 | // array (in case the path is nothing more than a filename) |
| 1194 | while (appLen > 1) |
| 1195 | { |
| 1196 | if (apppath[appLen-1] == TEXT('\\')) |
| 1197 | break; |
| 1198 | appLen--; |
| 1199 | } |
| 1200 | |
| 1201 | // Terminate the string after the trailing backslash |
| 1202 | apppath[appLen] = TEXT('\0'); |
| 1203 | } |
| 1204 | #ifdef _UNICODE |
| 1205 | wcstombs(buffer, apppath, min(1024, wcslen(apppath)*sizeof(wchar_t))); |
| 1206 | #else |
| 1207 | memcpy(buffer, apppath, min(1024, strlen(apppath))); |
| 1208 | #endif |
| 1209 | |
| 1210 | return buffer; |
| 1211 | #elif defined(__S3E__) |
| 1212 | // Marmalade uses its own portable C library |
| 1213 | return getcwd(buffer, (int)1024); |
| 1214 | #elif _XBOX_VER >= 200 |
| 1215 | // XBox 360 doesn't support the getcwd function, just use the root folder |
| 1216 | return "game:/"; |
| 1217 | #elif defined(_M_ARM) |
| 1218 | // TODO: How to determine current working dir on Windows Phone? |
| 1219 | return ""; |
| 1220 | #else |
| 1221 | return _getcwd(buffer, (int)1024); |
| 1222 | #endif // _MSC_VER |
| 1223 | #elif defined(__APPLE__) || defined(__linux__) |
| 1224 | return getcwd(buffer, 1024); |
| 1225 | #else |
| 1226 | return ""; |
| 1227 | #endif |
| 1228 | } |
| 1229 | |
| 1230 | END_AS_NAMESPACE |
| 1231 | |