MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / getAttr

Method getAttr

Source/Basic/Content.cpp:1394–1448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1392}
1393
1394std::optional<Content::FileAttr> Content::getAttr(String filename) {
1395 if (filename.empty()) {
1396 return std::nullopt;
1397 }
1398 auto fullPathAndPackage = Content::getFullPathAndPackage(filename);
1399 FileAttr attr;
1400 if (fullPathAndPackage.zipFile) {
1401 auto size = fullPathAndPackage.zipFile->getFileSize(fullPathAndPackage.zipRelativePath);
1402 if (!size) return std::nullopt;
1403 attr.size = s_cast<int64_t>(*size);
1404 size_t readTotal = 0;
1405 fullPathAndPackage.zipFile->getFileDataByChunks(fullPathAndPackage.zipRelativePath, [&](uint8_t* buffer, int size) {
1406 size_t readSize = std::min(s_cast<size_t>(size), s_cast<size_t>(DORA_BINARY_CHECK_SIZE) - readTotal);
1407 attr.isBinary = isBinaryData(buffer, readSize);
1408 readTotal += readSize;
1409 return attr.isBinary || readTotal >= DORA_BINARY_CHECK_SIZE;
1410 });
1411 return attr;
1412 }
1413 std::string fullPath = fullPathAndPackage.fullPath;
1414#if BX_PLATFORM_ANDROID
1415 if (isAndroidAsset(fullPath)) {
1416 std::string assetName = getAndroidAssetName(fullPath);
1417 auto size = _apkFile->getFileSize(assetName);
1418 if (!size) return std::nullopt;
1419 attr.size = s_cast<int64_t>(*size);
1420 size_t readTotal = 0;
1421 _apkFile->getFileDataByChunks(assetName, [&](uint8_t* buffer, int size) {
1422 size_t readSize = std::min(s_cast<size_t>(size), s_cast<size_t>(DORA_BINARY_CHECK_SIZE) - readTotal);
1423 attr.isBinary = isBinaryData(buffer, readSize);
1424 readTotal += readSize;
1425 return attr.isBinary || readTotal >= DORA_BINARY_CHECK_SIZE;
1426 });
1427 return attr;
1428 }
1429#endif // BX_PLATFORM_ANDROID
1430 std::error_code err;
1431 if (!fs::is_regular_file(fullPath, err) || err) {
1432 return std::nullopt;
1433 }
1434 auto fileSize = fs::file_size(fullPath, err);
1435 if (err) {
1436 return std::nullopt;
1437 }
1438 attr.size = s_cast<int64_t>(fileSize);
1439 SDL_RWops* io = SDL_RWFromFile(fullPath.c_str(), "rb");
1440 if (!io) {
1441 return std::nullopt;
1442 }
1443 DEFER(SDL_RWclose(io));
1444 uint8_t buffer[DORA_BINARY_CHECK_SIZE];
1445 size_t readSize = SDL_RWread(io, buffer, sizeof(uint8_t), DORA_BINARY_CHECK_SIZE);
1446 attr.isBinary = isBinaryData(buffer, readSize);
1447 return attr;
1448}
1449
1450std::list<std::string> Content::getDirEntries(String path, bool isFolder) {
1451 std::string searchName = path.empty() ? _assetPath : path.toString();

Callers 6

inspectReadableFileFunction · 0.45
syncProjectFileToWebIDEFunction · 0.45
fetchUrlFunction · 0.45
__Content_getAttrFunction · 0.45
Content_GetAttrFunction · 0.45

Calls 11

isBinaryDataFunction · 0.85
is_regular_fileFunction · 0.85
file_sizeFunction · 0.85
SDL_RWFromFileFunction · 0.85
SDL_RWcloseFunction · 0.85
SDL_RWreadFunction · 0.85
getFileSizeMethod · 0.80
getFileDataByChunksMethod · 0.80
minFunction · 0.50
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected