Use FileStream instead of fopen to check if file can be opened in read mode

This commit is contained in:
rh101 2021-04-26 01:44:50 +10:00
parent d76cb66e8e
commit bceabe87c1
1 changed files with 4 additions and 5 deletions

View File

@ -345,11 +345,10 @@ public:
std::string lowerCasePath = fontPath;
std::transform(lowerCasePath.begin(), lowerCasePath.end(), lowerCasePath.begin(), ::tolower);
if ( lowerCasePath.find(".ttf") != std::string::npos ) {
fontPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fontPath.c_str());
FILE *f = fopen(fontPath.c_str(), "r");
if ( f ) {
fclose(f);
fontPath = cocos2d::FileUtils::getInstance()->fullPathForFilename(fontPath);
auto* fileStream = cocos2d::FileUtils::getInstance()->openFileStream(fontPath, FileStream::Mode::READ);
if ( fileStream ) {
delete fileStream;
fontCache.insert(std::pair<std::string, std::string>(family_name, fontPath));
return fontPath;
}