[Scummvm-cvs-logs] SF.net SVN: scummvm:[41550] scummvm/branches/gsoc2009-draci/engines/draci

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Mon Jun 15 19:08:39 CEST 2009


Revision: 41550
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41550&view=rev
Author:   dkasak13
Date:     2009-06-15 17:08:39 +0000 (Mon, 15 Jun 2009)

Log Message:
-----------
Added BArchive::isOpen() method. Modified DraciEngine::go() to use it. Updated BArchive docs.

Modified Paths:
--------------
    scummvm/branches/gsoc2009-draci/engines/draci/barchive.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/barchive.h

Modified: scummvm/branches/gsoc2009-draci/engines/draci/barchive.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/barchive.cpp	2009-06-15 17:03:49 UTC (rev 41549)
+++ scummvm/branches/gsoc2009-draci/engines/draci/barchive.cpp	2009-06-15 17:08:39 UTC (rev 41550)
@@ -115,8 +115,11 @@
 		_files[i]._crc = 0; // Dummy value; not used in DFW archives
 	}
 
+	// Indicate that the archive was successfully opened
+	_opened = true;
+		
+	// Cleanup
 	delete[] table;
-	
 	f.close();
 }		
 
@@ -173,12 +176,17 @@
 	f.read(buf, 4);
 	if (memcmp(buf, _magicNumber, 4) == 0) {
 		debugC(2, kDraciArchiverDebugLevel, "Success");
+			
+		// Indicate this archive is a BAR	
 		_isDFW = false;
 	} else {
 		debugC(2, kDraciArchiverDebugLevel, "Not a BAR archive");
 		debugCN(2, kDraciArchiverDebugLevel, "Retrying as DFW: ");
 		f.close();
+
+		// Try to open as DFW
 		openDFW(_path);
+
 		return;
 	}
 
@@ -203,25 +211,30 @@
 		uint32 fileOffset;			
 		
 		fileOffset = reader.readUint32LE();
-		f.seek(fileOffset); // Seek to next file in archive
+		f.seek(fileOffset); 						// Seek to next file in archive
+
 		_files[i]._compLength = f.readUint16LE(); 	// Compressed size 
 													// should be the same as uncompressed
-		_files[i]._length = f.readUint16LE(); // Original size
-		_files[i]._offset = fileOffset;
 
+		_files[i]._length = f.readUint16LE(); 		// Original size
+	
+		_files[i]._offset = fileOffset;				// Offset of file from start
+
 		assert(f.readByte() == 0 && 
 			"Compression type flag is non-zero (file is compressed)");
 
-		_files[i]._crc = f.readByte(); // CRC checksum of the file
-		_files[i]._data = NULL; // File data will be read in on demand
-		_files[i]._stopper = 0; // Dummy value; not used in BAR files, needed in DFW
+		_files[i]._crc = f.readByte(); 	// CRC checksum of the file
+		_files[i]._data = NULL; 		// File data will be read in on demand
+		_files[i]._stopper = 0; 		// Dummy value; not used in BAR files, needed in DFW
 	}	
 	
 	// Last footer item should be equal to footerOffset
 	assert(reader.readUint32LE() == footerOffset && "Footer offset mismatch");
+
+	// Indicate that the archive has been successfully opened
+	_opened = true; 
 	
 	delete[] footer;
-
 	f.close();
 }
 
@@ -232,7 +245,7 @@
  * free up memory.
  */
 void BArchive::closeArchive(void) {
-	if (!_files) {
+	if (!_opened) {
 		return;
 	}
 
@@ -244,6 +257,7 @@
 
 	delete[] _files;
 
+	_opened = false;
 	_files = NULL;
 	_fileCount = 0;
 }
@@ -382,6 +396,8 @@
 	}
 	
 	BAFile *file;
+	
+	// file will be NULL if something goes wrong
 	if (_isDFW) {
 		file = loadFileDFW(i);
 	} else {

Modified: scummvm/branches/gsoc2009-draci/engines/draci/barchive.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/barchive.h	2009-06-15 17:03:49 UTC (rev 41549)
+++ scummvm/branches/gsoc2009-draci/engines/draci/barchive.h	2009-06-15 17:08:39 UTC (rev 41550)
@@ -51,14 +51,25 @@
 
 class BArchive {
 public:
-	BArchive() : _files(NULL), _fileCount(0) {}
-	BArchive(Common::String &path) : _files(NULL), _fileCount(0) { openArchive(path); }
+	BArchive() : _files(NULL), _fileCount(0), _opened(false) {}
+
+	BArchive(Common::String &path) :
+	_files(NULL), _fileCount(0), _opened(false) { 
+		openArchive(path); 
+	}
+
 	~BArchive() { closeArchive(); }
 
 	void openArchive(const Common::String &path);
 	void closeArchive(void);
 	uint16 size() const { return _fileCount; }
 
+	/** 
+	 * Checks whether there is an archive opened. Should be called before reading
+	 * from the archive to check whether openArchive() succeeded.
+	 */	
+	bool isOpen() const { return _opened; }
+
 	BAFile *operator[](unsigned int i) const;
 
 private:
@@ -74,6 +85,7 @@
 	BAFile *_files;          //!< Internal array of files
 	uint16 _fileCount;       //!< Number of files in archive
 	bool _isDFW;			 //!< True if the archive is in DFW format, false otherwise
+	bool _opened;			 //!< True if the archive is opened, false otherwise
 
 	void openDFW(const Common::String &path);
 	BAFile *loadFileDFW(unsigned int i) const;


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