diff options
author | Max Horn | 2006-04-30 23:08:37 +0000 |
---|---|---|
committer | Max Horn | 2006-04-30 23:08:37 +0000 |
commit | 13e4fc74e0bcaaa2df75ca60f284a57cbf7ccca8 (patch) | |
tree | 81e6441997dc23c86c52e48069cbc70ddaff5088 /common | |
parent | fd9e73d1f098a075fc5b1b4938c6336c2821dbf9 (diff) | |
download | scummvm-rg350-13e4fc74e0bcaaa2df75ca60f284a57cbf7ccca8.tar.gz scummvm-rg350-13e4fc74e0bcaaa2df75ca60f284a57cbf7ccca8.tar.bz2 scummvm-rg350-13e4fc74e0bcaaa2df75ca60f284a57cbf7ccca8.zip |
Add a File::open variant that takes a FilesystemNode as parameter
svn-id: r22251
Diffstat (limited to 'common')
-rw-r--r-- | common/file.cpp | 36 | ||||
-rw-r--r-- | common/file.h | 3 |
2 files changed, 39 insertions, 0 deletions
diff --git a/common/file.cpp b/common/file.cpp index d3f6c94a81..0fa6993148 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -195,6 +195,7 @@ bool File::open(const String &filename, AccessMode mode) { error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str()); } + _name.clear(); clearIOFailed(); String fname(filename); @@ -261,6 +262,40 @@ bool File::open(const String &filename, AccessMode mode) { return true; } +bool File::open(const FilesystemNode &node, AccessMode mode) { + assert(mode == kFileReadMode || mode == kFileWriteMode); + String filename(node.displayName()); + + if (_handle) { + error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str()); + } + + clearIOFailed(); + _name.clear(); + + const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb"; + + + _handle = fopen(node.path().c_str(), modeStr); + + + if (_handle == NULL) { + if (mode == kFileReadMode) + debug(2, "File %s not found", filename.c_str()); + else + debug(2, "File %s not opened", filename.c_str()); + return false; + } + + _name = filename; + +#ifdef DEBUG_FILE_REFCOUNT + warning("File::open on file '%s'", _name.c_str()); +#endif + + return true; +} + bool File::exists(const String &filename) { // First try to find the file it via a FilesystemNode (in case an absolute // path was passed). But we only use this to filter out directories. @@ -296,6 +331,7 @@ void File::close() { if (_handle) fclose(_handle); _handle = NULL; + _name.clear(); } bool File::isOpen() const { diff --git a/common/file.h b/common/file.h index eafb7adba9..76bee32024 100644 --- a/common/file.h +++ b/common/file.h @@ -28,6 +28,8 @@ #include "common/str.h" #include "common/stream.h" +class FilesystemNode; + namespace Common { class File : public SeekableReadStream, public WriteStream { @@ -61,6 +63,7 @@ public: void decRef(); virtual bool open(const String &filename, AccessMode mode = kFileReadMode); + virtual bool open(const FilesystemNode &node, AccessMode mode = kFileReadMode); static bool exists(const String &filename); virtual void close(); |