MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / GetSize

Method GetSize

src/server/angelscript/add_on/scriptfile/scriptfilesystem.cpp:351–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351asINT64 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

Callers 2

GetFilesMethod · 0.45
GetDirsMethod · 0.45

Calls 3

statClass · 0.85
c_strMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected