[Android] fix FileUtils::listFiles with path 'assets/'

This commit is contained in:
minggo 2019-04-10 00:09:30 -07:00 committed by GitHub
parent 408f6cf9da
commit 195dc704e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -300,7 +300,7 @@ long FileUtilsAndroid::getFileSize(const std::string& filepath) const
std::vector<std::string> 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<std::string> fileList;
string fullPath = fullPathForDirectory(dirPath);

View File

@ -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<std::string> listFonts = FileUtils::getInstance()->listFiles("fonts");
auto defaultPath = FileUtils::getInstance()->getDefaultResourceRootPath();
std::vector<std::string> list = FileUtils::getInstance()->listFiles (defaultPath);
char cntBuffer[200] = { 0 };
snprintf(cntBuffer, 200, "%lu", static_cast<unsigned long>(list.size()));
snprintf(cntBuffer, 200, "'fonts/' %d, $defaultResourceRootPath %d",listFonts.size(), list.size());
for(int i=0;i<listFonts.size();i++)
{
CCLOG("fonts/ %d: \t %s", i, listFonts[i].c_str());
}
for(int i=0;i<list.size();i++)
{
CCLOG("defResRootPath %d: \t %s", i, list[i].c_str());
}
cntLabel->setString(cntBuffer);
}