| 349 | } |
| 350 | |
| 351 | asINT64 CScriptFileSystem::GetSize(const string &path) const |
| 352 | { |
| 353 | string search; |
| 354 | if (path.find(":") != string::npos || path.find("/") == 0 || path.find("\\") == 0) |
| 355 | search = path; |
| 356 | else |
| 357 | search = currentPath + "/" + path; |
| 358 | |
| 359 | #if defined(_WIN32) |
| 360 | // Windows uses UTF16 so it is necessary to convert the string |
| 361 | wchar_t bufUTF16[10000]; |
| 362 | MultiByteToWideChar(CP_UTF8, 0, search.c_str(), -1, bufUTF16, 10000); |
| 363 | |
| 364 | // Get the size of the file |
| 365 | LARGE_INTEGER largeInt; |
| 366 | HANDLE file = CreateFileW(bufUTF16, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
| 367 | BOOL success = GetFileSizeEx(file, &largeInt); |
| 368 | CloseHandle(file); |
| 369 | if( !success ) |
| 370 | return -1; |
| 371 | return asINT64(largeInt.QuadPart); |
| 372 | #else |
| 373 | // Get the size of the file |
| 374 | struct stat st; |
| 375 | if (stat(search.c_str(), &st) == -1) |
| 376 | return -1; |
| 377 | return asINT64(st.st_size); |
| 378 | #endif |
| 379 | } |
| 380 | |
| 381 | // TODO: Should be able to return different codes for |
| 382 | // - directory exists |