diff --git a/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp b/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp index ac331a40d45..2387b12a88c 100644 --- a/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp +++ b/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp @@ -178,11 +178,25 @@ long FileUtilsOpenHarmony::getFileSize(const std::string &filepath) { if (fullPath.empty()) { return 0; } + + if(fullPath[0] == '/') { + return FileUtils::getFileSize(fullPath); + } + if (nullptr == _nativeResourceManager) { CC_LOG_ERROR("nativeResourceManager is nullptr"); return 0; } + if (fullPath[0] == '/') { + struct stat info; + int result = stat(fullPath.c_str(), &info); + if (result != 0) { + return -1; + } + return static_cast(info.st_size); + } + long filesize = 0; RawFile64 *rawFile = OH_ResourceManager_OpenRawFile64(_nativeResourceManager, fullPath.c_str()); if (rawFile) { @@ -201,11 +215,11 @@ bool FileUtilsOpenHarmony::isFileExistInternal(const std::string &strFilePath) c return false; } - if (strFilePath[0] != '/') { + if (strFilePath[0] != '/') { const char *s = strFilePath.c_str(); // Found "@assets/" at the beginning of the path and we don't want it if (strFilePath.find(ASSETS_FOLDER_NAME) == 0) s += strlen(ASSETS_FOLDER_NAME); - + if (nullptr == _nativeResourceManager) { CC_LOG_ERROR("nativeResourceManager is nullptr"); return false; @@ -217,7 +231,7 @@ bool FileUtilsOpenHarmony::isFileExistInternal(const std::string &strFilePath) c return true; } return false; - } + } FILE *fp = fopen(strFilePath.c_str(), "r"); if (fp) { fclose(fp);