diff options
Diffstat (limited to 'engines/titanic')
-rw-r--r-- | engines/titanic/compressed_file.cpp | 43 | ||||
-rw-r--r-- | engines/titanic/compressed_file.h | 27 | ||||
-rw-r--r-- | engines/titanic/core/project_item.cpp | 9 | ||||
-rw-r--r-- | engines/titanic/simple_file.cpp | 20 | ||||
-rw-r--r-- | engines/titanic/simple_file.h | 9 |
5 files changed, 21 insertions, 87 deletions
diff --git a/engines/titanic/compressed_file.cpp b/engines/titanic/compressed_file.cpp index d0cd37671a..3db93522dc 100644 --- a/engines/titanic/compressed_file.cpp +++ b/engines/titanic/compressed_file.cpp @@ -24,51 +24,12 @@ namespace Titanic { -#define BUFFER_SIZE 1024 - -CompressedFile::CompressedFile() : SimpleFile() { - _readStream = nullptr; - _writeStream = nullptr; -} - -CompressedFile::~CompressedFile() { -} - -void CompressedFile::open(const Common::String &name) { - SimpleFile::open(name); - _readStream = Common::wrapCompressedReadStream(&_file); -} - void CompressedFile::open(Common::SeekableReadStream *stream) { - SimpleFile::open(stream); - _readStream = Common::wrapCompressedReadStream(&_file); + SimpleFile::open(Common::wrapCompressedReadStream(stream)); } void CompressedFile::open(Common::OutSaveFile *stream) { - SimpleFile::open(stream); - _writeStream = Common::wrapCompressedWriteStream(stream); -} - -void CompressedFile::close() { - delete _readStream; - delete _writeStream; - _readStream = nullptr; - _writeStream = nullptr; - - SimpleFile::close(); -} - -size_t CompressedFile::unsafeRead(void *dst, size_t count) { - assert(_readStream); - if (count == 0) - return 0; - - // Read data and decompress - return _readStream->read(dst, count); -} - -size_t CompressedFile::write(const void *src, size_t count) { - return _writeStream->write(src, count); + SimpleFile::open(Common::wrapCompressedWriteStream(stream)); } } // End of namespace Titanic diff --git a/engines/titanic/compressed_file.h b/engines/titanic/compressed_file.h index 4b1051be5c..3be852f3b4 100644 --- a/engines/titanic/compressed_file.h +++ b/engines/titanic/compressed_file.h @@ -36,17 +36,9 @@ namespace Titanic { * Derived file that handles compressed files */ class CompressedFile : public SimpleFile { -private: - Common::SeekableReadStream *_readStream; - Common::WriteStream *_writeStream; public: - CompressedFile(); - virtual ~CompressedFile(); - - /** - * Open a file for access - */ - virtual void open(const Common::String &name); + CompressedFile() : SimpleFile() {} + virtual ~CompressedFile() {} /** * Set up a stream for read access @@ -57,21 +49,6 @@ public: * Set up a stream for write access */ virtual void open(Common::OutSaveFile *stream); - - /** - * Close the file - */ - virtual void close(); - - /** - * Read from the file - */ - virtual size_t unsafeRead(void *dst, size_t count); - - /** - * Write out data - */ - virtual size_t write(const void *src, size_t count); }; } // End of namespace Titanic diff --git a/engines/titanic/core/project_item.cpp b/engines/titanic/core/project_item.cpp index e759b87e9f..2fa65f9e33 100644 --- a/engines/titanic/core/project_item.cpp +++ b/engines/titanic/core/project_item.cpp @@ -134,18 +134,20 @@ void CProjectItem::resetGameManager() { void CProjectItem::loadGame(int slotId) { CompressedFile file; - Common::InSaveFile *saveFile = nullptr; // Clear any existing project contents clear(); // Open either an existing savegame slot or the new game template if (slotId >= 0) { - saveFile = g_system->getSavefileManager()->openForLoading( + Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading( Common::String::format("slot%d.gam", slotId)); file.open(saveFile); } else { - file.open("newgame.st"); + Common::File *newFile = new Common::File(); + if (!newFile->open("newgame.st")) + error("Could not open newgame.st"); + file.open(newFile); } // Load the contents in @@ -165,6 +167,7 @@ void CProjectItem::loadGame(int slotId) { item->detach(); item->addUnder(this); } + // Loaded project instance is no longer needed newProject->destroyAll(); diff --git a/engines/titanic/simple_file.cpp b/engines/titanic/simple_file.cpp index ef6f26d827..4be8bb3d88 100644 --- a/engines/titanic/simple_file.cpp +++ b/engines/titanic/simple_file.cpp @@ -29,15 +29,7 @@ SimpleFile::SimpleFile(): _inStream(nullptr), _outStream(nullptr), _lineCount(1) } SimpleFile::~SimpleFile() { - _file.close(); -} - -void SimpleFile::open(const Common::String &name) { close(); - - if (!_file.open(name)) - error("Could not find file - %s", name.c_str()); - _inStream = &_file; } void SimpleFile::open(Common::SeekableReadStream *stream) { @@ -51,12 +43,16 @@ void SimpleFile::open(Common::OutSaveFile *stream) { } void SimpleFile::close() { - _file.close(); - if (_outStream) + if (_outStream) { _outStream->finalize(); + delete _outStream; + _outStream = nullptr; + } - _inStream = nullptr; - _outStream = nullptr; + if (_inStream) { + delete _inStream; + _inStream = nullptr; + } } void SimpleFile::safeRead(void *dst, size_t count) { diff --git a/engines/titanic/simple_file.h b/engines/titanic/simple_file.h index 8ea2b5a35d..4426380966 100644 --- a/engines/titanic/simple_file.h +++ b/engines/titanic/simple_file.h @@ -35,9 +35,11 @@ namespace Titanic { class Decompressor; class DecompressorData; +/** + * This class implements basic reading and writing to files + */ class SimpleFile { protected: - Common::File _file; Common::SeekableReadStream *_inStream; Common::OutSaveFile *_outStream; int _lineCount; @@ -46,11 +48,6 @@ public: virtual ~SimpleFile(); /** - * Open a file for access - */ - virtual void open(const Common::String &name); - - /** * Set up a stream for read access */ virtual void open(Common::SeekableReadStream *stream); |