aboutsummaryrefslogtreecommitdiff
path: root/common/file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/file.cpp')
-rw-r--r--common/file.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/common/file.cpp b/common/file.cpp
index 4d9c630076..9797bcaa69 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -25,6 +25,8 @@
#include "common/file.h"
#include "common/fs.h"
#include "common/textconsole.h"
+#include "common/system.h"
+#include "backends/fs/fs-factory.h"
namespace Common {
@@ -149,10 +151,23 @@ DumpFile::~DumpFile() {
close();
}
-bool DumpFile::open(const String &filename) {
+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()) continue;
+ if (!node->create(true)) warning("DumpFile: unable to create directories from path prefix");
+ }
+ }
+ }
+
FSNode node(filename);
return open(node);
}