improve the checkandcreatedirectory recursive function file_manager using the stringutils split function

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5619 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
xapantu 2010-07-02 17:14:09 +00:00
parent 079a25cbd8
commit 2a3854db6b

View File

@ -384,23 +384,21 @@ bool FileManager::checkAndCreateDirectoryP(const std::string &path)
if(m_file_system->existFile(io::path(path.c_str())))
return true;
for(int i = 0; i <= path.size(); i++)
std::vector<std::string> split = StringUtils::split(path,'/');
std::string current_path ="";
for(unsigned int i=0; i<split.size(); i++)
{
if(path.c_str()[i] == '/')
current_path += split[i] + "/";
std::cout << "Checking for: " << current_path << std::endl;
if(m_file_system->existFile(io::path(current_path.c_str())))
std::cout << "The directory exist." << std::endl;
else
{
std::string current_path = path.substr(0, i + 1);
std::cout << "Checking for: " << current_path << std::endl;
if(m_file_system->existFile(io::path(current_path.c_str())))
std::cout << "The directory exist." << std::endl;
else
if(!checkAndCreateDirectory(current_path))
{
if(!checkAndCreateDirectory(current_path))
{
fprintf(stderr, "Can't create dir '%s'",
current_path.c_str());
break;
}
fprintf(stderr, "Can't create dir '%s'",
current_path.c_str());
break;
}
}
}