From 195dc704e3121614f5c7c27d767fda992b081013 Mon Sep 17 00:00:00 2001 From: minggo Date: Wed, 10 Apr 2019 00:09:30 -0700 Subject: [PATCH] [Android] fix FileUtils::listFiles with path 'assets/' --- cocos/platform/android/CCFileUtils-android.cpp | 2 +- .../Classes/FileUtilsTest/FileUtilsTest.cpp | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cocos/platform/android/CCFileUtils-android.cpp b/cocos/platform/android/CCFileUtils-android.cpp index 0d2c5e1606..3faa14a7f7 100644 --- a/cocos/platform/android/CCFileUtils-android.cpp +++ b/cocos/platform/android/CCFileUtils-android.cpp @@ -300,7 +300,7 @@ long FileUtilsAndroid::getFileSize(const std::string& filepath) const std::vector FileUtilsAndroid::listFiles(const std::string& dirPath) const { - if(isAbsolutePath(dirPath)) return FileUtils::listFiles(dirPath); + if(!dirPath.empty() && dirPath[0] == '/') return FileUtils::listFiles(dirPath); std::vector fileList; string fullPath = fullPathForDirectory(dirPath); diff --git a/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp b/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp index b999079a75..f76a53df2f 100644 --- a/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp +++ b/tests/cpp-tests/Classes/FileUtilsTest/FileUtilsTest.cpp @@ -1409,10 +1409,23 @@ void TestListFiles::onEnter() this->addChild(cntLabel); cntLabel->setPosition(winSize.width / 2, winSize.height / 3); // writeTest - auto list = FileUtils::getInstance()->listFiles("fonts"); + std::vector listFonts = FileUtils::getInstance()->listFiles("fonts"); + auto defaultPath = FileUtils::getInstance()->getDefaultResourceRootPath(); + std::vector list = FileUtils::getInstance()->listFiles (defaultPath); char cntBuffer[200] = { 0 }; - snprintf(cntBuffer, 200, "%lu", static_cast(list.size())); + snprintf(cntBuffer, 200, "'fonts/' %d, $defaultResourceRootPath %d",listFonts.size(), list.size()); + + for(int i=0;isetString(cntBuffer); }