diff options
Diffstat (limited to 'common/file.h')
-rw-r--r-- | common/file.h | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/common/file.h b/common/file.h index a2739f795f..0634aecdd3 100644 --- a/common/file.h +++ b/common/file.h @@ -27,13 +27,14 @@ #define COMMON_FILE_H #include "common/scummsys.h" +#include "common/archive.h" #include "common/noncopyable.h" #include "common/str.h" #include "common/stream.h" namespace Common { -class FilesystemNode; +class FSNode; /** * TODO: vital to document this core class properly!!! For both users and implementors @@ -43,7 +44,7 @@ protected: /** File handle to the actual file; 0 if no file is open. */ SeekableReadStream *_handle; - /** The name of this file, for debugging. */ + /** The name of this file, kept for debugging purposes. */ String _name; public: @@ -51,11 +52,12 @@ public: static void addDefaultDirectory(const String &directory); static void addDefaultDirectoryRecursive(const String &directory, int level = 4); - static void addDefaultDirectory(const FilesystemNode &directory); - static void addDefaultDirectoryRecursive(const FilesystemNode &directory, int level = 4); + static void addDefaultDirectory(const FSNode &directory); + static void addDefaultDirectoryRecursive(const FSNode &directory, int level = 4); static void resetDefaultDirectories(); + File(); virtual ~File(); @@ -64,14 +66,56 @@ public: * (those were/are added by addDefaultDirectory and/or * addDefaultDirectoryRecursive). * - * @param filename: the file to check for - * @return: true if the file exists, else false + * @param filename the file to check for + * @return true if the file exists, false otherwise */ static bool exists(const String &filename); + /** + * Try to open the file with the given filename, by searching SearchMan. + * @note Must not be called if this file already is open (i.e. if isOpen returns true). + * + * @param filename the name of the file to open + * @return true if file was opened successfully, false otherwise + */ virtual bool open(const String &filename); - virtual bool open(const FilesystemNode &node); + /** + * Try to open the file with the given filename from within the given archive. + * @note Must not be called if this file already is open (i.e. if isOpen returns true). + * + * @param filename the name of the file to open + * @param archive the archive in which to search for the file + * @return true if file was opened successfully, false otherwise + */ + virtual bool open(const String &filename, Archive &archive); + + /** + * Try to open the file corresponding to the give node. Will check whether the + * node actually refers to an existing file (and not a directory), and handle + * those cases gracefully. + * @note Must not be called if this file already is open (i.e. if isOpen returns true). + * + * @param filename the name of the file to open + * @param archive the archive in which to search for the file + * @return true if file was opened successfully, false otherwise + */ + virtual bool open(const FSNode &node); + + /** + * Try to 'open' the given stream. That is, we just wrap around it, and if stream + * is a NULL pointer, we gracefully treat this as if opening failed. + * @note Must not be called if this file already is open (i.e. if isOpen returns true). + * + * @param stream a pointer to a SeekableReadStream, or 0 + * @param name a string describing the 'file' corresponding to stream + * @return true if stream was 0, false otherwise + */ + virtual bool open(SeekableReadStream *stream, const Common::String &name); + + /** + * Close the file, if open. + */ virtual void close(); /** @@ -82,11 +126,11 @@ public: bool isOpen() const; /** - * Returns the filename of the opened file. + * Returns the filename of the opened file for debugging purposes. * * @return: the filename */ - const char *name() const { return _name.c_str(); } + const char *getName() const { return _name.c_str(); } bool ioFailed() const; void clearIOFailed(); @@ -117,7 +161,7 @@ public: virtual ~DumpFile(); virtual bool open(const String &filename); - virtual bool open(const FilesystemNode &node); + virtual bool open(const FSNode &node); virtual void close(); |