Skip to content

Commit ac83d6f

Browse files
committed
修复无法正确获取鸿蒙平台沙箱里文件大小的问题
1 parent 1b7bbb6 commit ac83d6f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

native/cocos/platform/openharmony/FileUtils-OpenHarmony.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ long FileUtilsOpenHarmony::getFileSize(const std::string &filepath) {
183183
return 0;
184184
}
185185

186+
if (fullPath[0] == '/') {
187+
struct stat info;
188+
int result = stat(fullPath.c_str(), &info);
189+
if (result != 0) {
190+
return -1;
191+
}
192+
return static_cast<long>(info.st_size);
193+
}
194+
186195
long filesize = 0;
187196
RawFile64 *rawFile = OH_ResourceManager_OpenRawFile64(_nativeResourceManager, fullPath.c_str());
188197
if (rawFile) {
@@ -201,11 +210,11 @@ bool FileUtilsOpenHarmony::isFileExistInternal(const std::string &strFilePath) c
201210
return false;
202211
}
203212

204-
if (strFilePath[0] != '/') {
213+
if (strFilePath[0] != '/') {
205214
const char *s = strFilePath.c_str();
206215
// Found "@assets/" at the beginning of the path and we don't want it
207216
if (strFilePath.find(ASSETS_FOLDER_NAME) == 0) s += strlen(ASSETS_FOLDER_NAME);
208-
217+
209218
if (nullptr == _nativeResourceManager) {
210219
CC_LOG_ERROR("nativeResourceManager is nullptr");
211220
return false;
@@ -217,7 +226,7 @@ bool FileUtilsOpenHarmony::isFileExistInternal(const std::string &strFilePath) c
217226
return true;
218227
}
219228
return false;
220-
}
229+
}
221230
FILE *fp = fopen(strFilePath.c_str(), "r");
222231
if (fp) {
223232
fclose(fp);

0 commit comments

Comments
 (0)