aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorWalter van Niftrik2016-03-24 09:50:52 +0100
committerWalter van Niftrik2016-06-06 20:35:49 +0200
commitf2de96512a4e53fa2b81c9a1c20f82f283e271ea (patch)
treeb0f4bfc1049caac013b179b4db0f40fd73258726 /engines
parentbfbacf9397f6baa03e5b79149fc357d6c8d74049 (diff)
downloadscummvm-rg350-f2de96512a4e53fa2b81c9a1c20f82f283e271ea.tar.gz
scummvm-rg350-f2de96512a4e53fa2b81c9a1c20f82f283e271ea.tar.bz2
scummvm-rg350-f2de96512a4e53fa2b81c9a1c20f82f283e271ea.zip
ADL: Add file-based disk access class
Diffstat (limited to 'engines')
-rw-r--r--engines/adl/disk.cpp21
-rw-r--r--engines/adl/disk.h27
2 files changed, 48 insertions, 0 deletions
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp
index b91efec1f1..e2c3da3d5c 100644
--- a/engines/adl/disk.cpp
+++ b/engines/adl/disk.cpp
@@ -21,6 +21,7 @@
*/
#include "common/stream.h"
+#include "common/substream.h"
#include "adl/disk.h"
@@ -87,4 +88,24 @@ bool DiskImage_DSK::open(const Common::String &filename) {
return true;
}
+Common::SeekableReadStream *FilesDataBlock::createReadStream() const {
+ return _files->createReadStream(_filename, _offset);
+}
+
+const DataBlockPtr PlainFiles::getDataBlock(const Common::String &filename, uint offset) const {
+ return Common::SharedPtr<FilesDataBlock>(new FilesDataBlock(this, filename, offset));
+}
+
+Common::SeekableReadStream *PlainFiles::createReadStream(const Common::String &filename, uint offset) const {
+ Common::File *f(new Common::File());
+
+ if (!f->open(filename))
+ error("Failed to open '%s'", filename.c_str());
+
+ if (offset == 0)
+ return f;
+ else
+ return new Common::SeekableSubReadStream(f, offset, f->size(), DisposeAfterUse::YES);
+}
+
} // End of namespace Adl
diff --git a/engines/adl/disk.h b/engines/adl/disk.h
index 0bf57c7661..b6a5c60262 100644
--- a/engines/adl/disk.h
+++ b/engines/adl/disk.h
@@ -43,6 +43,33 @@ public:
typedef Common::SharedPtr<DataBlock> DataBlockPtr;
+class Files {
+public:
+ virtual ~Files() { }
+
+ virtual const DataBlockPtr getDataBlock(const Common::String &filename, uint offset) const = 0;
+ virtual Common::SeekableReadStream *createReadStream(const Common::String &filename, uint offset) const = 0;
+};
+
+class FilesDataBlock : public DataBlock {
+public:
+ FilesDataBlock(const Files *files, const Common::String &filename, uint offset) : _files(files), _filename(filename), _offset(offset) { }
+
+ bool isValid() const { return true; }
+ Common::SeekableReadStream *createReadStream() const;
+
+private:
+ const Common::String _filename;
+ uint _offset;
+ const Files *_files;
+};
+
+class PlainFiles : public Files {
+public:
+ const DataBlockPtr getDataBlock(const Common::String &filename, uint offset = 0) const;
+ Common::SeekableReadStream *createReadStream(const Common::String &filename, uint offset = 0) const;
+};
+
class DiskImage {
public:
DiskImage();