diff options
Diffstat (limited to 'engines/sci/engine/file.h')
-rw-r--r-- | engines/sci/engine/file.h | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/engines/sci/engine/file.h b/engines/sci/engine/file.h index 1657dd3c7c..28a3c5801b 100644 --- a/engines/sci/engine/file.h +++ b/engines/sci/engine/file.h @@ -23,20 +23,21 @@ #ifndef SCI_ENGINE_FILE_H #define SCI_ENGINE_FILE_H +#include "common/memstream.h" #include "common/str-array.h" #include "common/stream.h" namespace Sci { enum kFileOpenMode { - _K_FILE_MODE_OPEN_OR_CREATE = 0, - _K_FILE_MODE_OPEN_OR_FAIL = 1, - _K_FILE_MODE_CREATE = 2 + kFileOpenModeOpenOrCreate = 0, + kFileOpenModeOpenOrFail = 1, + kFileOpenModeCreate = 2 }; enum { - SCI_MAX_SAVENAME_LENGTH = 36, ///< Maximum length of a savegame name (including optional terminator character). - MAX_SAVEGAME_NR = 20 ///< Maximum number of savegames + kMaxSaveNameLength = 36, ///< Maximum length of a savegame name (including optional terminator character). + kMaxNumSaveGames = 20 ///< Maximum number of savegames }; #ifdef ENABLE_SCI32 @@ -51,10 +52,12 @@ enum { }; #endif -#define VIRTUALFILE_HANDLE_START 32000 -#define VIRTUALFILE_HANDLE_SCI32SAVE 32100 -#define VIRTUALFILE_HANDLE_SCIAUDIO 32300 -#define VIRTUALFILE_HANDLE_END 32300 +enum { + kVirtualFileHandleStart = 32000, + kVirtualFileHandleSci32Save = 32100, + kVirtualFileHandleSciAudio = 32300, + kVirtualFileHandleEnd = 32300 +}; struct SavegameDesc { int16 id; @@ -62,7 +65,7 @@ struct SavegameDesc { int date; int time; int version; - char name[SCI_MAX_SAVENAME_LENGTH]; + char name[kMaxSaveNameLength]; Common::String gameVersion; uint32 script0Size; uint32 gameObjectOffset; @@ -112,7 +115,58 @@ private: void addAsVirtualFiles(Common::String title, Common::String fileMask); }; +#ifdef ENABLE_SCI32 +/** + * A MemoryWriteStreamDynamic with additional read functionality. + * The read and write functions share a single stream position. + */ +class MemoryDynamicRWStream : public Common::MemoryWriteStreamDynamic, public Common::SeekableReadStream { +public: + MemoryDynamicRWStream(DisposeAfterUse::Flag disposeMemory = DisposeAfterUse::NO) : MemoryWriteStreamDynamic(disposeMemory), _eos(false) { } + + uint32 read(void *dataPtr, uint32 dataSize); + + bool eos() const { return _eos; } + int32 pos() const { return _pos; } + int32 size() const { return _size; } + void clearErr() { _eos = false; Common::MemoryWriteStreamDynamic::clearErr(); } + bool seek(int32 offs, int whence = SEEK_SET) { return Common::MemoryWriteStreamDynamic::seek(offs, whence); } + +protected: + bool _eos; +}; + +/** + * A MemoryDynamicRWStream intended to re-write a file. + * It reads the contents of `inFile` in the constructor, and writes back + * the changes to `fileName` in the destructor (and when calling commit() ). + */ +class SaveFileRewriteStream : public MemoryDynamicRWStream { +public: + SaveFileRewriteStream(const Common::String &fileName, + Common::SeekableReadStream *inFile, + kFileOpenMode mode, bool compress); + virtual ~SaveFileRewriteStream(); + + virtual uint32 write(const void *dataPtr, uint32 dataSize) { _changed = true; return MemoryDynamicRWStream::write(dataPtr, dataSize); } + + void commit(); //< Save back to disk + +protected: + Common::String _fileName; + bool _compress; + bool _changed; +}; + +#endif + uint findFreeFileHandle(EngineState *s); +reg_t file_open(EngineState *s, const Common::String &filename, kFileOpenMode mode, bool unwrapFilename); +FileHandle *getFileFromHandle(EngineState *s, uint handle); +int fgets_wrapper(EngineState *s, char *dest, int maxsize, int handle); +void listSavegames(Common::Array<SavegameDesc> &saves); +int findSavegame(Common::Array<SavegameDesc> &saves, int16 savegameId); +bool fillSavegameDesc(const Common::String &filename, SavegameDesc &desc); } // End of namespace Sci |