aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJohannes Schickel2006-07-08 14:25:23 +0000
committerJohannes Schickel2006-07-08 14:25:23 +0000
commitabdebd3bfd3596d073f40cc4d7452a053906f8b5 (patch)
tree893fb0e79992c2c7f5739f7a05b40424f6b5da1b /engines
parent700ff85a638fef71e709049dbbac96d538810408 (diff)
downloadscummvm-rg350-abdebd3bfd3596d073f40cc4d7452a053906f8b5.tar.gz
scummvm-rg350-abdebd3bfd3596d073f40cc4d7452a053906f8b5.tar.bz2
scummvm-rg350-abdebd3bfd3596d073f40cc4d7452a053906f8b5.zip
- fixes some c/p errors from my last commit
- fixes embedded pak loading svn-id: r23425
Diffstat (limited to 'engines')
-rw-r--r--engines/kyra/resource.cpp90
-rw-r--r--engines/kyra/resource.h8
2 files changed, 60 insertions, 38 deletions
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp
index 6c099ff22b..02be4f31ff 100644
--- a/engines/kyra/resource.cpp
+++ b/engines/kyra/resource.cpp
@@ -156,16 +156,7 @@ Resource::Resource(KyraEngine *engine) {
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 @@ bool Resource::loadPakFile(const Common::String &filename) {
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 @@ PAKFile::PAKFile(const char *file, bool isAmiga) : ResourceFile() {
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 @@ PAKFile::PAKFile(const char *file, const uint8 *buffer, uint32 filesize, bool is
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 @@ uint8 *PAKFile::getFile(const char *file) {
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 @@ bool PAKFile::getFileHandle(const char *file, Common::File &filehandle) {
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 @@ uint32 PAKFile::getFileSize(const char* file) {
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 @@ INSFile::INSFile(const char *file) : ResourceFile(), _files() {
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 @@ uint8 *INSFile::getFile(const char *file) {
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 @@ uint8 *INSFile::getFile(const char *file) {
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) {
diff --git a/engines/kyra/resource.h b/engines/kyra/resource.h
index bd93ef76aa..7cb16f9918 100644
--- a/engines/kyra/resource.h
+++ b/engines/kyra/resource.h
@@ -61,14 +61,20 @@ class PAKFile : public ResourceFile {
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
};