std::string FileUtils::getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) { // get directory+filename, safely adding '/' as necessary std::string ret = directory; if (directory.size() && directory[directory.size()-1] != '/') { ret += '/'; } ret += filename; // if the file doesn't exist, return an empty string if (!isFileExistInternal(ret)) { ret = ""; } return ret; }
bool FileUtils::isFileExist(const std::string& filename) const { if (isAbsolutePath(filename)) { return isFileExistInternal(filename); } else { std::string fullpath = searchFullPathForFilename(filename); if (fullpath.empty()) return false; else return true; } }
bool FileUtils::isFileExist(const std::string& filename) const { // If filename is absolute path, we don't need to consider 'search paths' and 'resolution orders'. if (isAbsolutePath(filename)) { return isFileExistInternal(filename); } // Already Cached ? auto cacheIter = _fullPathCache.find(filename); if( cacheIter != _fullPathCache.end() ) { return true; } // Get the new file name. const std::string newFilename( getNewFilename(filename) ); std::string fullpath; for (auto searchIt = _searchPathArray.cbegin(); searchIt != _searchPathArray.cend(); ++searchIt) { for (auto resolutionIt = _searchResolutionsOrderArray.cbegin(); resolutionIt != _searchResolutionsOrderArray.cend(); ++resolutionIt) { fullpath = const_cast<FileUtils*>(this)->getPathForFilename(newFilename, *resolutionIt, *searchIt); if (!fullpath.empty()) { // Using the filename passed in as key. const_cast<FileUtils*>(this)->_fullPathCache.insert(std::make_pair(filename, fullpath)); return true; } } } return false; }