[Scummvm-cvs-logs] SF.net SVN: scummvm: [23425] scummvm/trunk/engines/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sat Jul 8 16:25:30 CEST 2006


Revision: 23425
Author:   lordhoto
Date:     2006-07-08 07:25:23 -0700 (Sat, 08 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=23425&view=rev

Log Message:
-----------
- fixes some c/p errors from my last commit
- fixes embedded pak loading

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/resource.cpp
    scummvm/trunk/engines/kyra/resource.h
Modified: scummvm/trunk/engines/kyra/resource.cpp
===================================================================
--- scummvm/trunk/engines/kyra/resource.cpp	2006-07-08 14:25:25 UTC (rev 23424)
+++ scummvm/trunk/engines/kyra/resource.cpp	2006-07-08 14:25:23 UTC (rev 23425)
@@ -156,16 +156,7 @@
 		error("no filelist found for this game");
 
 	for (uint32 tmp = 0; usedFilelist[tmp]; ++tmp) {
-		// prefetch file
-		PAKFile *file = new PAKFile(usedFilelist[tmp], (_engine->features() & GF_AMIGA) != 0);
-		assert(file);
-
-		if (file->isOpen() && file->isValid()) {
-			_pakfiles.push_back(file);
-		} else {
-			delete file;
-			debug(3, "couldn't load file '%s' correctly", usedFilelist[tmp]);
-		}
+		loadPakFile(usedFilelist[tmp]);
 	}
 }
 
@@ -183,17 +174,32 @@
 		return true;
 
 	uint32 size = 0;
-	uint8 *buf = fileData(filename.c_str(), &size);
-	if (!buf || size == 0) {
+	Common::File handle;
+	if (!fileHandle(filename.c_str(), &size, handle)) {
 		warning("couldn't load file: '%s'", filename.c_str());
 		return false;
 	}
 
-	PAKFile *file = new PAKFile(filename.c_str(), buf, size);
-	delete [] buf;
+	PAKFile *file = 0;
 
+	if (handle.name() == filename) {
+		file = new PAKFile(filename.c_str(), (_engine->features() & GF_AMIGA) != 0);
+	} else {
+		uint32 offset = handle.pos();
+		uint8 *buf = new uint8[size];
+		handle.read(buf, size);
+		file = new PAKFile(filename.c_str(), handle.name(), offset, buf, size, (_engine->features() & GF_AMIGA) != 0);
+		delete [] buf;
+	}
+	handle.close();
+
 	if (!file)
 		return false;
+	if (!file->isValid()) {
+		warning("'%s' is no valid pak file!", filename.c_str());
+		delete file;
+		return false;
+	}
 
 	_pakfiles.push_back(file);
 	return true;
@@ -344,9 +350,10 @@
 	delete [] buffer;
 	
 	_filename = file;
+	_physfile = "";
 }
 
-PAKFile::PAKFile(const char *file, const uint8 *buffer, uint32 filesize, bool isAmiga) : ResourceFile() {
+PAKFile::PAKFile(const char *file, const char *physfile, const uint32 off, const uint8 *buffer, uint32 filesize, bool isAmiga) : ResourceFile() {
 	_isAmiga = isAmiga;
 	_open = false;
 
@@ -391,12 +398,15 @@
 		startoffset = endoffset;
 	}
 
-	_open = true;	
+	_open = true;
+	_physfile = physfile;
+	_physOffset = off;
 	_filename = file;
 }
 
 PAKFile::~PAKFile() {
 	_filename.clear();
+	_physfile.clear();
 	_open = false;
 
 	_files.clear();
@@ -406,11 +416,9 @@
 	for (PAKFile_Iterate) {
 		if (!scumm_stricmp(start->_name.c_str(), file)) {
 			Common::File pakfile;
-			if (!pakfile.open(_filename)) {
-				debug(3, "couldn't open pakfile '%s'\n", _filename.c_str());
-				return 0;
-			}
-			pakfile.seek(start->_start);
+			if (!openFile(pakfile))
+				return false;
+			pakfile.seek(start->_start, SEEK_CUR);
 			uint8 *buffer = new uint8[start->_size];
 			assert(buffer);
 			pakfile.read(buffer, start->_size);
@@ -425,11 +433,9 @@
 
 	for (PAKFile_Iterate) {
 		if (!scumm_stricmp(start->_name.c_str(), file)) {
-			if (!filehandle.open(_filename)) {
-				debug(3, "couldn't open pakfile '%s'\n", _filename.c_str());
-				return 0;
-			}
-			filehandle.seek(start->_start);
+			if (!openFile(filehandle))
+				return false;
+			filehandle.seek(start->_start, SEEK_CUR);
 			return true;
 		}
 	}
@@ -444,6 +450,21 @@
 	return 0;
 }
 
+bool PAKFile::openFile(Common::File &filehandle) {
+	filehandle.close();
+
+	if (!filehandle.open(_physfile == "" ? _filename : _physfile)) {
+		debug(3, "couldn't open pakfile '%s'\n", _filename.c_str());
+		return false;
+	}
+
+	if (_physfile != "") {
+		filehandle.seek(_physOffset, SEEK_CUR);
+	}
+
+	return true;
+}
+
 ///////////////////////////////////////////
 // Ins file manager
 #define INSFile_Iterate Common::List<FileEntry>::iterator start=_files.begin();start != _files.end(); ++start
@@ -495,7 +516,6 @@
 		filesize = pakfile.readUint32LE();
 		start->_size = filesize;
 		start->_start = pakfile.pos();
-		printf("'%s', %d, %d\n", start->_name.c_str(), start->_start, start->_size);
 		pakfile.seek(filesize, SEEK_CUR);
 	}
 
@@ -516,7 +536,7 @@
 			Common::File pakfile;
 			if (!pakfile.open(_filename)) {
 				debug(3, "couldn't open insfile '%s'\n", _filename.c_str());
-				return 0;
+				return false;
 			}
 			pakfile.seek(start->_start);
 			uint8 *buffer = new uint8[start->_size];
@@ -531,19 +551,15 @@
 bool INSFile::getFileHandle(const char *file, Common::File &filehandle) {
 	for (INSFile_Iterate) {
 		if (!scumm_stricmp(start->_name.c_str(), file)) {
-			Common::File pakfile;
-			if (!pakfile.open(_filename)) {
+			if (!filehandle.open(_filename)) {
 				debug(3, "couldn't open insfile '%s'\n", _filename.c_str());
-				return 0;
+				return false;
 			}
-			pakfile.seek(start->_start);
-			uint8 *buffer = new uint8[start->_size];
-			assert(buffer);
-			pakfile.read(buffer, start->_size);
-			return buffer;
+			filehandle.seek(start->_start, SEEK_CUR);
+			return true;
 		}
 	}
-	return 0;
+	return false;
 }
 
 uint32 INSFile::getFileSize(const char *file) {

Modified: scummvm/trunk/engines/kyra/resource.h
===================================================================
--- scummvm/trunk/engines/kyra/resource.h	2006-07-08 14:25:25 UTC (rev 23424)
+++ scummvm/trunk/engines/kyra/resource.h	2006-07-08 14:25:23 UTC (rev 23425)
@@ -61,14 +61,20 @@
 
 public:
 	PAKFile(const char *file, bool isAmiga = false);
-	PAKFile(const char *file, const uint8 *buf, uint32 size, bool isAmiga = false);
+	PAKFile(const char *file, const char *physfile, const uint32 off, const uint8 *buf, uint32 size, bool isAmiga = false);
 	~PAKFile();
 
 	uint8 *getFile(const char *file);
 	bool getFileHandle(const char *file, Common::File &filehandle);
 	uint32 getFileSize(const char *file);
 private:
+	bool openFile(Common::File &filehandle);
+
 	bool _isAmiga;
+
+	Common::String _physfile;
+	uint32 _physOffset;
+
 	Common::List<PakChunk> _files; // the entries
 };
 


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