[Scummvm-cvs-logs] SF.net SVN: scummvm:[34923] scummvm/trunk/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Nov 7 10:50:51 CET 2008


Revision: 34923
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34923&view=rev
Author:   fingolfin
Date:     2008-11-07 09:50:51 +0000 (Fri, 07 Nov 2008)

Log Message:
-----------
Refactoring the Arj decoder code, phase 2

Modified Paths:
--------------
    scummvm/trunk/common/unarj.cpp
    scummvm/trunk/common/unarj.h

Modified: scummvm/trunk/common/unarj.cpp
===================================================================
--- scummvm/trunk/common/unarj.cpp	2008-11-07 09:46:12 UTC (rev 34922)
+++ scummvm/trunk/common/unarj.cpp	2008-11-07 09:50:51 UTC (rev 34923)
@@ -179,10 +179,9 @@
 	return CRC ^ 0xFFFFFFFF;
 }
 
-ArjFile::ArjFile() : _uncompressedData(NULL) {
+ArjFile::ArjFile() : _uncompressed(0) {
 	_decoder = new ArjDecoder;
 	InitCRC();
-	_isOpen = false;
 	_fallBack = false;
 }
 
@@ -342,15 +341,12 @@
 
 
 bool ArjFile::open(const Common::String &filename) {
-	if (_isOpen)
+	if (_uncompressed)
 		error("Attempt to open another instance of archive");
 
-	_isOpen = false;
-
 	if (_fallBack) {
 		_currArchive.open(filename);
 		if (_currArchive.isOpen()) {
-			_isOpen = true;
 			_uncompressed = &_currArchive;
 			return true;
 		}
@@ -359,27 +355,21 @@
 	if (!_fileMap.contains(filename))
 		return false;
 
-	_isOpen = true;
-
 	ArjHeader *hdr = _headers[_fileMap[filename]];
 
 	_decoder->_compsize = hdr->compSize;
 	_decoder->_origsize = hdr->origSize;
 
-	// FIXME: This hotfix prevents Drascula from leaking memory.
-	// As far as sanity checks go this is not bad, but the engine should be fixed.
-	free(_uncompressedData);
+	byte *uncompressedData = (byte *)malloc(_decoder->_origsize);
+	_decoder->_outstream = new MemoryWriteStream(uncompressedData, _decoder->_origsize);
 
-	_uncompressedData = (byte *)malloc(_decoder->_origsize);
-	_decoder->_outstream = new MemoryWriteStream(_uncompressedData, _decoder->_origsize);
-
 	_currArchive.open(_archMap[filename]);
 	_currArchive.seek(hdr->pos, SEEK_SET);
 
 printf("Arj archive method %d, file '%s'\n", hdr->method, filename.c_str());
 
 	if (hdr->method == 0) { // store
-        _currArchive.read(_uncompressedData, _decoder->	_origsize);
+        _currArchive.read(uncompressedData, _decoder->	_origsize);
 	} else {
 		byte *_compressedData = (byte *)malloc(_decoder->_compsize);
 		_currArchive.read(_compressedData, _decoder->_compsize);
@@ -399,47 +389,47 @@
 	delete _decoder->_outstream;
 	_decoder->_outstream = NULL;
 
-	_uncompressed = new MemoryReadStream(_uncompressedData, _decoder->_origsize);
+	_uncompressed = new MemoryReadStream(uncompressedData, _decoder->_origsize, true);
+	assert(_uncompressed);
 
 	return true;
 }
 
 void ArjFile::close() {
-	if (!_isOpen)
+	if (!_uncompressed)
 		return;
 
-	_isOpen = false;
-
 	if (_fallBack) {
 		_currArchive.close();
-		return;
 	} else {
 		delete _uncompressed;
 	}
 
 	_uncompressed = NULL;
-
-	free(_uncompressedData);
-	_uncompressedData = NULL;
 }
 
 uint32 ArjFile::read(void *dataPtr, uint32 dataSize) {
+	assert(_uncompressed);
 	return _uncompressed->read(dataPtr, dataSize);
 }
 
 bool ArjFile::eos() const {
+	assert(_uncompressed);
 	return _uncompressed->eos();
 }
 
 int32 ArjFile::pos() const {
+	assert(_uncompressed);
 	return _uncompressed->pos();
 }
 
 int32 ArjFile::size() const {
+	assert(_uncompressed);
 	return _uncompressed->size();
 }
 
 bool ArjFile::seek(int32 offset, int whence) {
+	assert(_uncompressed);
 	return _uncompressed->seek(offset, whence);
 }
 

Modified: scummvm/trunk/common/unarj.h
===================================================================
--- scummvm/trunk/common/unarj.h	2008-11-07 09:46:12 UTC (rev 34922)
+++ scummvm/trunk/common/unarj.h	2008-11-07 09:50:51 UTC (rev 34923)
@@ -53,7 +53,7 @@
 	int32 pos() const;
 	int32 size() const;
 	bool seek(int32 offset, int whence = SEEK_SET);
-	bool isOpen() { return _isOpen; }
+	bool isOpen() { return _uncompressed != 0; }
 
 private:
 	bool _fallBack;
@@ -63,11 +63,8 @@
 	ArjFilesMap _fileMap;
 	StringMap _archMap;
 
-	byte *_uncompressedData;
 	SeekableReadStream *_uncompressed;
 
-	bool _isOpen;
-	
 	ArjDecoder *_decoder;
 };
 


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