[Scummvm-cvs-logs] SF.net SVN: scummvm:[48314] scummvm/trunk/engines/teenagent

megath at users.sourceforge.net megath at users.sourceforge.net
Sat Mar 20 14:52:08 CET 2010


Revision: 48314
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48314&view=rev
Author:   megath
Date:     2010-03-20 13:52:08 +0000 (Sat, 20 Mar 2010)

Log Message:
-----------
added TransientFilePack

Modified Paths:
--------------
    scummvm/trunk/engines/teenagent/pack.cpp
    scummvm/trunk/engines/teenagent/pack.h

Modified: scummvm/trunk/engines/teenagent/pack.cpp
===================================================================
--- scummvm/trunk/engines/teenagent/pack.cpp	2010-03-20 13:18:47 UTC (rev 48313)
+++ scummvm/trunk/engines/teenagent/pack.cpp	2010-03-20 13:52:08 UTC (rev 48314)
@@ -77,11 +77,87 @@
 
 Common::SeekableReadStream *FilePack::getStream(uint32 id) const {
 	if (id < 1 || id > _fileCount)
+		return NULL;
+	//debug(0, "stream: %04x-%04x", offsets[id - 1], offsets[id]);
+	file.seek(offsets[id - 1]);
+	uint32 size = offsets[id] - offsets[id - 1];
+	byte *ptr = (byte *)malloc(size);
+	if (ptr == NULL)
+		return NULL;
+	uint32 r = file.read(ptr, size);
+	return new Common::MemoryReadStream(ptr, r, DisposeAfterUse::YES);
+}
+
+
+TransientFilePack::TransientFilePack() : offsets(0) {}
+
+TransientFilePack::~TransientFilePack() {
+	close();
+}
+
+void TransientFilePack::close() {
+	delete[] offsets;
+	offsets = NULL;
+	_filename.clear();
+}
+
+bool TransientFilePack::open(const Common::String &filename) {
+	_filename = filename;
+
+	Common::File file;
+	if (!file.open(filename))
+		return false;
+
+	_fileCount = file.readUint32LE();
+	debug(0, "opened %s, found %u entries", filename.c_str(), _fileCount);
+	offsets = new uint32[_fileCount + 1];
+	for (uint32 i = 0; i <= _fileCount; ++i) {
+		offsets[i] = file.readUint32LE();
+	}
+	return true;
+}
+
+uint32 TransientFilePack::getSize(uint32 id) const {
+	if (id < 1 || id > _fileCount)
 		return 0;
+	return offsets[id] - offsets[id - 1];
+}
+
+uint32 TransientFilePack::read(uint32 id, byte *dst, uint32 size) const {
+	if (id < 1 || id > _fileCount)
+		return 0;
+
+	Common::File file;
+	if (!file.open(_filename))
+		return 0;
+
+	file.seek(offsets[id - 1]);
+	uint32 rsize = offsets[id] - offsets[id - 1];
+	uint32 r = file.read(dst, MIN(rsize, size));
+	file.close();
+	//debug(0, "read(%u, %u) = %u", id, size, r);
+	return r;
+}
+
+Common::SeekableReadStream *TransientFilePack::getStream(uint32 id) const {
+	if (id < 1 || id > _fileCount)
+		return NULL;
 	//debug(0, "stream: %04x-%04x", offsets[id - 1], offsets[id]);
-	return new Common::SeekableSubReadStream(&file, offsets[id - 1], offsets[id], DisposeAfterUse::NO);
+	Common::File file;
+	if (!file.open(_filename))
+		return NULL;
+
+	file.seek(offsets[id - 1]);
+	uint32 size = offsets[id] - offsets[id - 1];
+	byte *ptr = (byte *)malloc(size);
+	if (ptr == NULL)
+		return NULL;
+	uint32 r = file.read(ptr, size);
+	file.close();
+	return new Common::MemoryReadStream(ptr, r, DisposeAfterUse::YES);
 }
 
+
 void MemoryPack::close() {
 	chunks.clear();
 }

Modified: scummvm/trunk/engines/teenagent/pack.h
===================================================================
--- scummvm/trunk/engines/teenagent/pack.h	2010-03-20 13:18:47 UTC (rev 48313)
+++ scummvm/trunk/engines/teenagent/pack.h	2010-03-20 13:52:08 UTC (rev 48314)
@@ -62,6 +62,22 @@
 	virtual Common::SeekableReadStream *getStream(uint32 id) const;
 };
 
+class TransientFilePack : public Pack {
+	uint32 *offsets;
+	Common::String _filename;
+
+public:
+	TransientFilePack();
+	~TransientFilePack();
+
+	virtual bool open(const Common::String &filename);
+	virtual void close();
+
+	virtual uint32 getSize(uint32 id) const;
+	virtual uint32 read(uint32 id, byte *dst, uint32 size) const;
+	virtual Common::SeekableReadStream *getStream(uint32 id) const;
+};
+
 class MemoryPack : public Pack {
 	struct Chunk {
 		byte *data;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list