ADL: Add file-based disk access class
This commit is contained in:
parent
bfbacf9397
commit
f2de96512a
2 changed files with 48 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue