Adding a function (checkAndCreateDirectoryP) tp create directories recursively

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5616 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
xapantu 2010-07-02 09:35:55 +00:00
parent e99d7592fb
commit f4f78803b3
2 changed files with 49 additions and 16 deletions

View File

@ -376,6 +376,38 @@ bool FileManager::checkAndCreateDirectory(const std::string &path)
return !error;
} // checkAndCreateDirectory
bool FileManager::checkAndCreateDirectoryP(const std::string &path)
{
std::cout << "creating...:" << path << std::endl;
// irrlicht apparently returns true for files and directory
// (using access/_access internally):
if(m_file_system->existFile(io::path(path.c_str())))
return true;
for(int i = 0; i <= path.size(); i++)
{
if(path.c_str()[i] == '/')
{
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))
{
fprintf(stderr, "Can't create dir '%s'",
current_path.c_str());
break;
}
}
}
}
bool error = checkAndCreateDirectory(path);
return error;
} // checkAndCreateDirectory
//-----------------------------------------------------------------------------
/** Checks if the config directory exists, and it not, tries to create it. */
void FileManager::checkAndCreateConfigDir()

View File

@ -78,6 +78,7 @@ public:
XMLNode *createXMLTree(const std::string &filename);
std::string getConfigDir () const;
bool checkAndCreateDirectoryP(const std::string &path);
#ifdef ADDONS_MANAGER
std::string getAddonsDir () const;
void checkAndCreateDirForAddons(std::string addons_name, std::string addons_type);