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:
parent
e99d7592fb
commit
f4f78803b3
@ -177,7 +177,7 @@ void FileManager::dropFileSystem()
|
|||||||
void FileManager::setDevice(IrrlichtDevice *device)
|
void FileManager::setDevice(IrrlichtDevice *device)
|
||||||
{
|
{
|
||||||
m_device = device;
|
m_device = device;
|
||||||
|
|
||||||
//std::cout << "^^^^^^^^ GRABBING m_device (FileManager) ^^^^^^^^\n";
|
//std::cout << "^^^^^^^^ GRABBING m_device (FileManager) ^^^^^^^^\n";
|
||||||
m_device->grab(); // To make sure that the device still exists while
|
m_device->grab(); // To make sure that the device still exists while
|
||||||
// file_manager has a pointer to the file system.
|
// file_manager has a pointer to the file system.
|
||||||
@ -242,7 +242,7 @@ void FileManager::pushModelSearchPath(const std::string& path)
|
|||||||
{
|
{
|
||||||
m_model_search_path.push_back(path);
|
m_model_search_path.push_back(path);
|
||||||
m_file_system->addFileArchive(createAbsoluteFilename(path),
|
m_file_system->addFileArchive(createAbsoluteFilename(path),
|
||||||
/*ignoreCase*/false,
|
/*ignoreCase*/false,
|
||||||
/*ignorePaths*/false,
|
/*ignorePaths*/false,
|
||||||
io::EFAT_FOLDER);
|
io::EFAT_FOLDER);
|
||||||
} // pushModelSearchPath
|
} // pushModelSearchPath
|
||||||
@ -252,7 +252,7 @@ void FileManager::pushTextureSearchPath(const std::string& path)
|
|||||||
{
|
{
|
||||||
m_texture_search_path.push_back(path);
|
m_texture_search_path.push_back(path);
|
||||||
m_file_system->addFileArchive(createAbsoluteFilename(path),
|
m_file_system->addFileArchive(createAbsoluteFilename(path),
|
||||||
/*ignoreCase*/false,
|
/*ignoreCase*/false,
|
||||||
/*ignorePaths*/false,
|
/*ignorePaths*/false,
|
||||||
io::EFAT_FOLDER);
|
io::EFAT_FOLDER);
|
||||||
} // pushTextureSearchPath
|
} // pushTextureSearchPath
|
||||||
@ -376,6 +376,38 @@ bool FileManager::checkAndCreateDirectory(const std::string &path)
|
|||||||
return !error;
|
return !error;
|
||||||
} // checkAndCreateDirectory
|
} // 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. */
|
/** Checks if the config directory exists, and it not, tries to create it. */
|
||||||
void FileManager::checkAndCreateConfigDir()
|
void FileManager::checkAndCreateConfigDir()
|
||||||
@ -393,10 +425,10 @@ void FileManager::checkAndCreateConfigDir()
|
|||||||
m_config_dir = ".";
|
m_config_dir = ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_config_dir = ".";
|
m_config_dir = ".";
|
||||||
const std::string CONFIGDIR("supertuxkart");
|
const std::string CONFIGDIR("supertuxkart");
|
||||||
|
|
||||||
m_config_dir += "/";
|
m_config_dir += "/";
|
||||||
m_config_dir += CONFIGDIR;
|
m_config_dir += CONFIGDIR;
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
@ -438,7 +470,7 @@ void FileManager::checkAndCreateConfigDir()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const std::string CONFIGDIR("supertuxkart");
|
const std::string CONFIGDIR("supertuxkart");
|
||||||
|
|
||||||
m_config_dir += "/";
|
m_config_dir += "/";
|
||||||
m_config_dir += CONFIGDIR;
|
m_config_dir += CONFIGDIR;
|
||||||
#endif
|
#endif
|
||||||
@ -484,9 +516,9 @@ void FileManager::checkAndCreateAddonsDir()
|
|||||||
m_addons_dir += ".";
|
m_addons_dir += ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string CONFIGDIR("supertuxkart");
|
const std::string CONFIGDIR("supertuxkart");
|
||||||
|
|
||||||
m_addons_dir += "/";
|
m_addons_dir += "/";
|
||||||
m_addons_dir += CONFIGDIR;
|
m_addons_dir += CONFIGDIR;
|
||||||
#endif
|
#endif
|
||||||
@ -604,6 +636,6 @@ void FileManager::checkAndCreateDirForAddons(std::string addons_name, std::strin
|
|||||||
if(!success)
|
if(!success)
|
||||||
std::cout << "There is a problem with the addons dir." << std::endl;
|
std::cout << "There is a problem with the addons dir." << std::endl;
|
||||||
checkAndCreateDirectory(getAddonsDir() + "/data/" + addons_type + addons_name);
|
checkAndCreateDirectory(getAddonsDir() + "/data/" + addons_type + addons_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,12 +37,12 @@ using namespace irr;
|
|||||||
* \brief class handling files and paths
|
* \brief class handling files and paths
|
||||||
* \ingroup io
|
* \ingroup io
|
||||||
*/
|
*/
|
||||||
class FileManager
|
class FileManager
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/** Handle to irrlicht's file systems. */
|
/** Handle to irrlicht's file systems. */
|
||||||
io::IFileSystem *m_file_system;
|
io::IFileSystem *m_file_system;
|
||||||
/** Pointer to the irrlicht device. This is necessary before reInit is
|
/** Pointer to the irrlicht device. This is necessary before reInit is
|
||||||
* called to store the NULL device initially created. See Constructor
|
* called to store the NULL device initially created. See Constructor
|
||||||
* for details. */
|
* for details. */
|
||||||
IrrlichtDevice *m_device;
|
IrrlichtDevice *m_device;
|
||||||
@ -58,8 +58,8 @@ private:
|
|||||||
m_model_search_path,
|
m_model_search_path,
|
||||||
m_music_search_path;
|
m_music_search_path;
|
||||||
bool findFile (std::string& full_path,
|
bool findFile (std::string& full_path,
|
||||||
const std::string& fname,
|
const std::string& fname,
|
||||||
const std::vector<std::string>& search_path)
|
const std::vector<std::string>& search_path)
|
||||||
const;
|
const;
|
||||||
void makePath (std::string& path, const std::string& dir,
|
void makePath (std::string& path, const std::string& dir,
|
||||||
const std::string& fname) const;
|
const std::string& fname) const;
|
||||||
@ -78,6 +78,7 @@ public:
|
|||||||
XMLNode *createXMLTree(const std::string &filename);
|
XMLNode *createXMLTree(const std::string &filename);
|
||||||
|
|
||||||
std::string getConfigDir () const;
|
std::string getConfigDir () const;
|
||||||
|
bool checkAndCreateDirectoryP(const std::string &path);
|
||||||
#ifdef ADDONS_MANAGER
|
#ifdef ADDONS_MANAGER
|
||||||
std::string getAddonsDir () const;
|
std::string getAddonsDir () const;
|
||||||
void checkAndCreateDirForAddons(std::string addons_name, std::string addons_type);
|
void checkAndCreateDirForAddons(std::string addons_name, std::string addons_type);
|
||||||
@ -99,13 +100,13 @@ public:
|
|||||||
std::string getSFXFile (const std::string& fname) const;
|
std::string getSFXFile (const std::string& fname) const;
|
||||||
std::string getFontFile (const std::string& fname) const;
|
std::string getFontFile (const std::string& fname) const;
|
||||||
std::string getModelFile (const std::string& fname) const;
|
std::string getModelFile (const std::string& fname) const;
|
||||||
void listFiles (std::set<std::string>& result,
|
void listFiles (std::set<std::string>& result,
|
||||||
const std::string& dir,
|
const std::string& dir,
|
||||||
bool is_full_path=false,
|
bool is_full_path=false,
|
||||||
bool make_full_path=false) const;
|
bool make_full_path=false) const;
|
||||||
|
|
||||||
bool fileExists (const std::string& path) { return m_file_system->existFile(path.c_str()); }
|
bool fileExists (const std::string& path) { return m_file_system->existFile(path.c_str()); }
|
||||||
|
|
||||||
void pushTextureSearchPath(const std::string& path);
|
void pushTextureSearchPath(const std::string& path);
|
||||||
void pushModelSearchPath (const std::string& path);
|
void pushModelSearchPath (const std::string& path);
|
||||||
void pushMusicSearchPath (const std::string& path)
|
void pushMusicSearchPath (const std::string& path)
|
||||||
|
Loading…
Reference in New Issue
Block a user