aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-25 16:32:22 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitae8e7f39f5b3e4f647a29d39d19cce7626528bb1 (patch)
treebf1031fbf6bedd96056b8a427f2bf647499b44e6 /common
parentd014b5bf3826d78de269891ccf6722e58d7a5bcd (diff)
downloadscummvm-rg350-ae8e7f39f5b3e4f647a29d39d19cce7626528bb1.tar.gz
scummvm-rg350-ae8e7f39f5b3e4f647a29d39d19cce7626528bb1.tar.bz2
scummvm-rg350-ae8e7f39f5b3e4f647a29d39d19cce7626528bb1.zip
CLOUD: Make download() create necessary directories
DumpFile::open() with createPath=true create would create the missing directories from the path before opening a file. Thus, one can easily create a file and avoid "can't open a file" error.
Diffstat (limited to 'common')
-rw-r--r--common/file.cpp18
-rw-r--r--common/file.h2
2 files changed, 17 insertions, 3 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);
}
diff --git a/common/file.h b/common/file.h
index 3d174834e9..8ad6249d6d 100644
--- a/common/file.h
+++ b/common/file.h
@@ -143,7 +143,7 @@ public:
DumpFile();
virtual ~DumpFile();
- virtual bool open(const String &filename);
+ virtual bool open(const String &filename, bool createPath = false);
virtual bool open(const FSNode &node);
virtual void close();