mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-31 07:53:36 +00:00
COMMON: Implement FSNode::createDirectoryRecursive()
This commit is contained in:
parent
04c57babbc
commit
aca627bec7
@ -63,7 +63,7 @@ DefaultSaveFileManager::DefaultSaveFileManager(const Common::String &defaultSave
|
||||
void DefaultSaveFileManager::checkPath(const Common::FSNode &dir) {
|
||||
clearError();
|
||||
if (!dir.exists()) {
|
||||
if (!dir.createDirectory()) {
|
||||
if (!dir.createDirectoryRecursive()) {
|
||||
setError(Common::kPathDoesNotExist, "Failed to create directory '"+dir.getPath()+"'");
|
||||
}
|
||||
} else if (!dir.isDirectory()) {
|
||||
|
@ -155,24 +155,10 @@ bool DumpFile::open(const String &filename, bool createPath) {
|
||||
assert(!filename.empty());
|
||||
assert(!_handle);
|
||||
|
||||
if (createPath) {
|
||||
for (uint32 i = 0; i < filename.size(); ++i) {
|
||||
if (filename[i] == '/' || filename[i] == '\\') {
|
||||
Common::String subpath = filename;
|
||||
subpath.erase(i);
|
||||
if (subpath.empty()) continue;
|
||||
AbstractFSNode *node = g_system->getFilesystemFactory()->makeFileNodePath(subpath);
|
||||
if (node->exists()) {
|
||||
delete node;
|
||||
continue;
|
||||
}
|
||||
if (!node->createDirectory()) warning("DumpFile: unable to create directories from path prefix");
|
||||
delete node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FSNode node(filename);
|
||||
if (createPath)
|
||||
node.getParent().createDirectoryRecursive();
|
||||
|
||||
return open(node);
|
||||
}
|
||||
|
||||
|
@ -168,6 +168,27 @@ bool FSNode::createDirectory() const {
|
||||
return _realNode->createDirectory();
|
||||
}
|
||||
|
||||
bool FSNode::createDirectoryRecursive() const {
|
||||
if (_realNode == nullptr)
|
||||
return false;
|
||||
|
||||
if (_realNode->exists()) {
|
||||
if (!_realNode->isDirectory()) {
|
||||
warning("FSNode::createDirectoryRecursive: '%s' is a file", _realNode->getName().c_str());
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
FSNode parent = getParent();
|
||||
assert(parent.getPath() != _realNode->getPath());
|
||||
if (!parent.createDirectoryRecursive())
|
||||
return false;
|
||||
|
||||
return _realNode->createDirectory();
|
||||
}
|
||||
|
||||
FSDirectory::FSDirectory(const FSNode &node, int depth, bool flat)
|
||||
: _node(node), _cached(false), _depth(depth), _flat(flat) {
|
||||
}
|
||||
|
@ -239,6 +239,14 @@ public:
|
||||
* @return true if the directory was created, false otherwise.
|
||||
*/
|
||||
bool createDirectory() const;
|
||||
|
||||
/**
|
||||
* Creates a directory referred by this node. The parent directory
|
||||
* will also be created if it doesn't exist.
|
||||
*
|
||||
* @return true if the directory was created, false otherwise.
|
||||
*/
|
||||
bool createDirectoryRecursive() const;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user