aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/file.cpp7
-rw-r--r--common/file.h4
-rw-r--r--common/savefile.h17
-rw-r--r--common/stream.h16
4 files changed, 29 insertions, 15 deletions
diff --git a/common/file.cpp b/common/file.cpp
index e84e337d2f..94b3e48930 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -553,5 +553,12 @@ uint32 DumpFile::write(const void *ptr, uint32 len) {
return (uint32)fwrite(ptr, 1, len, (FILE *)_handle);
}
+void DumpFile::flush() {
+ assert(_handle);
+ // TODO: Should check the return value of fflush, and if it is non-zero,
+ // check errno and set an error flag.
+ fflush((FILE *)_handle);
+}
+
} // End of namespace Common
diff --git a/common/file.h b/common/file.h
index 54168ffc7d..3adeb6ff36 100644
--- a/common/file.h
+++ b/common/file.h
@@ -148,7 +148,9 @@ public:
*/
virtual bool eof() const;
- uint32 write(const void *dataPtr, uint32 dataSize);
+ virtual uint32 write(const void *dataPtr, uint32 dataSize);
+
+ virtual void flush();
};
diff --git a/common/savefile.h b/common/savefile.h
index f30ddfc160..aa91b5859d 100644
--- a/common/savefile.h
+++ b/common/savefile.h
@@ -39,6 +39,7 @@ namespace Common {
* That typically means "save games", but also includes things like the
* IQ points in Indy3.
*/
+//typedef SeekableReadStream InSaveFile;
class InSaveFile : public SeekableReadStream {};
/**
@@ -46,20 +47,8 @@ class InSaveFile : public SeekableReadStream {};
* That typically means "save games", but also includes things like the
* IQ points in Indy3.
*/
-class OutSaveFile : public WriteStream {
-public:
- /**
- * Close this savefile, to be called right before destruction of this
- * savefile. The idea is that this ways, I/O errors that occur
- * during closing/flushing of the file can still be handled by the
- * game engine.
- *
- * By default, this just flushes the stream.
- */
- virtual void finalize() {
- flush();
- }
-};
+//typedef WriteStream OutSaveFile;
+class OutSaveFile : public WriteStream {};
/**
diff --git a/common/stream.h b/common/stream.h
index d07579c2d1..01a946e685 100644
--- a/common/stream.h
+++ b/common/stream.h
@@ -78,6 +78,22 @@ public:
*/
virtual void flush() {}
+ /**
+ * Finalize and close this stream. To be called right before this
+ * stream instance is deleted. The goal here is to enable calling
+ * code to detect and handle I/O errors which might occur when
+ * closing (and this flushing, if buffered) the stream.
+ *
+ * After this method has been called, no further writes may be
+ * peformed on the stream. Calling ioFailed() is allowed.
+ *
+ * By default, this just flushes the stream.
+ */
+ virtual void finalize() {
+ flush();
+ }
+
+
// The remaining methods all have default implementations; subclasses
// need not (and should not) overload them.