昨天升级到了2.1.1版本,结果iOS版本出了点问题,发现getPathForFilename()返回的结果多出了些斜杠,如传入sfx/sfx.xml,返回的是: 绝对目录//sfx//sfx.xml,因此作了点小修改,如下:
std::string CCFileUtils::getPathForFilename(const std::string& filename, const std::string& resourceDirectory, const std::string& searchPath)
{
std::string file = filename;
std::string file_path = "";
size_t pos = filename.find_last_of("/");
if (pos != std::string::npos)
{
file_path = filename.substr(0, pos); // pos+1改为pos,即不附加'/'
file = filename.substr(pos+1);
}
// searchPath + file_path + resourceDirectory
std::string path = searchPath;
if (!path.empty() && path != '/') // 添加字符串为空的判断,即搜索目录是主目录时,不附加'/'
{
path += "/";
}
path += file_path;
path += resourceDirectory;