From ac83d6fffb17224d93eb506f967711397c56642e Mon Sep 17 00:00:00 2001 From: konglianjie <857386415@qq.com> Date: Wed, 10 Dec 2025 14:03:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96=E9=B8=BF=E8=92=99=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=B2=99=E7=AE=B1=E9=87=8C=E6=96=87=E4=BB=B6=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../openharmony/FileUtils-OpenHarmony.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp b/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp index ac331a40d45..4356fd72450 100644 --- a/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp +++ b/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp @@ -183,6 +183,15 @@ long FileUtilsOpenHarmony::getFileSize(const std::string &filepath) { 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 +210,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 +226,7 @@ bool FileUtilsOpenHarmony::isFileExistInternal(const std::string &strFilePath) c return true; } return false; - } + } FILE *fp = fopen(strFilePath.c_str(), "r"); if (fp) { fclose(fp); From 7804e3adf3d6f00fe7b3c812a17f3a6d28b79850 Mon Sep 17 00:00:00 2001 From: konglianjie <857386415@qq.com> Date: Wed, 10 Dec 2025 14:39:21 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96=E9=B8=BF=E8=92=99=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=B2=99=E7=AE=B1=E9=87=8C=E6=96=87=E4=BB=B6=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/openharmony/FileUtils-OpenHarmony.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp b/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp index ac331a40d45..c0e538bb6f4 100644 --- a/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp +++ b/native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp @@ -178,6 +178,11 @@ 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; @@ -201,11 +206,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 +222,7 @@ bool FileUtilsOpenHarmony::isFileExistInternal(const std::string &strFilePath) c return true; } return false; - } + } FILE *fp = fopen(strFilePath.c_str(), "r"); if (fp) { fclose(fp);