aboutsummaryrefslogtreecommitdiff
path: root/common/file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/file.cpp')
-rw-r--r--common/file.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/common/file.cpp b/common/file.cpp
index 4d9c630076..52b66bd2f4 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,11 +151,23 @@ DumpFile::~DumpFile() {
close();
}
-bool DumpFile::open(const String &filename) {
+bool DumpFile::open(const String &filename, bool createPath) {
assert(!filename.empty());
assert(!_handle);
- FSNode node(filename);
+ if (createPath) {
+ for (uint32 i = 0; i < filename.size(); ++i) {
+ if (filename[i] == '/' || filename[i] == '\\') {
+ Common::String subpath = filename;
+ subpath.erase(i);
+ 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);
}