2005-01-09 16:06:29 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2004-2006 The ScummVM project
|
2004-10-15 06:06:47 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-10-15 06:06:47 +00:00
|
|
|
*
|
2006-02-09 12:19:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-10-15 06:06:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2006-07-15 20:30:36 +00:00
|
|
|
#include "common/config-manager.h"
|
2006-03-29 15:59:37 +00:00
|
|
|
#include "common/endian.h"
|
2004-10-15 06:06:47 +00:00
|
|
|
#include "common/file.h"
|
2006-07-15 20:30:36 +00:00
|
|
|
#include "common/fs.h"
|
2006-09-16 20:51:05 +00:00
|
|
|
#include "common/hash-str.h"
|
2006-07-08 12:23:44 +00:00
|
|
|
|
|
|
|
#include "gui/message.h"
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
#include "kyra/resource.h"
|
2005-06-24 16:01:42 +00:00
|
|
|
#include "kyra/script.h"
|
2005-08-19 22:12:09 +00:00
|
|
|
#include "kyra/wsamovie.h"
|
2006-02-09 07:37:19 +00:00
|
|
|
#include "kyra/screen.h"
|
2004-10-15 06:06:47 +00:00
|
|
|
|
|
|
|
namespace Kyra {
|
2006-02-10 16:39:56 +00:00
|
|
|
Resource::Resource(KyraEngine *engine) {
|
2004-11-14 20:11:22 +00:00
|
|
|
_engine = engine;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-05-28 04:08:25 +00:00
|
|
|
if (_engine->game() == GI_KYRA1) {
|
2006-07-08 13:56:56 +00:00
|
|
|
// we're loading KYRA.DAT here too (but just for Kyrandia 1)
|
2006-10-22 20:08:23 +00:00
|
|
|
if (!loadPakFile("KYRA.DAT", true) || !StaticResource::checkKyraDat()) {
|
2006-07-15 20:46:27 +00:00
|
|
|
GUI::MessageDialog errorMsg("You're missing the 'KYRA.DAT' file or it got corrupted, (re)get it from the ScummVM website");
|
2006-07-08 12:23:44 +00:00
|
|
|
errorMsg.runModal();
|
2006-07-15 20:46:27 +00:00
|
|
|
error("You're missing the 'KYRA.DAT' file or it got corrupted, (re)get it from the ScummVM website");
|
2006-05-28 04:08:25 +00:00
|
|
|
}
|
2006-07-15 20:30:36 +00:00
|
|
|
|
2006-07-15 20:32:54 +00:00
|
|
|
// We only need kyra.dat for the demo.
|
2006-09-17 20:21:40 +00:00
|
|
|
if (_engine->gameFlags().isDemo)
|
2006-07-15 20:32:54 +00:00
|
|
|
return;
|
|
|
|
|
2006-07-15 20:30:36 +00:00
|
|
|
// only VRM file we need in the *whole* game for kyra1
|
2006-09-17 20:21:40 +00:00
|
|
|
if (_engine->gameFlags().isTalkie) {
|
2006-07-16 19:44:39 +00:00
|
|
|
loadPakFile("CHAPTER1.VRM");
|
2006-07-15 20:30:36 +00:00
|
|
|
}
|
2006-07-08 13:56:56 +00:00
|
|
|
} else if (_engine->game() == GI_KYRA3) {
|
|
|
|
// load the installation package file for kyra3
|
|
|
|
INSFile *insFile = new INSFile("WESTWOOD.001");
|
|
|
|
assert(insFile);
|
|
|
|
if (!insFile->isValid())
|
|
|
|
return;
|
|
|
|
_pakfiles.push_back(insFile);
|
2006-05-28 04:08:25 +00:00
|
|
|
}
|
2006-07-15 20:32:54 +00:00
|
|
|
|
2006-07-15 20:30:36 +00:00
|
|
|
FSList fslist;
|
|
|
|
FilesystemNode dir(ConfMan.get("path"));
|
2006-07-15 20:32:54 +00:00
|
|
|
|
2006-07-15 20:30:36 +00:00
|
|
|
if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) {
|
|
|
|
error("invalid game path '%s'", dir.path().c_str());
|
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
|
2006-09-17 20:21:40 +00:00
|
|
|
if (_engine->game() == GI_KYRA1 && _engine->gameFlags().isTalkie) {
|
2006-09-16 14:36:53 +00:00
|
|
|
static const char *list[] = {
|
2006-10-24 00:30:48 +00:00
|
|
|
"ADL.PAK", "CHAPTER1.VRM", "COL.PAK", "FINALE.PAK", "INTRO1.PAK", "INTRO2.PAK",
|
|
|
|
"INTRO3.PAK", "INTRO4.PAK", "MISC.PAK", "SND.PAK", "STARTUP.PAK", "XMI.PAK",
|
|
|
|
"CAVE.APK", "DRAGON1.APK", "DRAGON2.APK", "LAGOON.APK", 0
|
2006-09-16 14:36:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; list[i]; ++i) {
|
|
|
|
if (!loadPakFile(list[i]))
|
|
|
|
error("couldn't open pakfile '%s'", list[i]);
|
|
|
|
}
|
2006-10-24 00:56:10 +00:00
|
|
|
|
|
|
|
Common::List<ResourceFile*>::iterator start = _pakfiles.begin();
|
|
|
|
for (;start != _pakfiles.end(); ++start) {
|
|
|
|
(*start)->protect();
|
|
|
|
}
|
2006-09-16 14:36:53 +00:00
|
|
|
} else {
|
|
|
|
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
|
|
|
|
Common::String filename = file->name();
|
|
|
|
filename.toUppercase();
|
|
|
|
if (filename.hasSuffix("PAK") || filename.hasSuffix("APK")) {
|
|
|
|
if (!loadPakFile(file->name())) {
|
|
|
|
error("couldn't open pakfile '%s'", file->name().c_str());
|
|
|
|
}
|
2006-07-15 20:37:32 +00:00
|
|
|
}
|
2006-07-15 20:30:36 +00:00
|
|
|
}
|
2007-01-25 14:38:11 +00:00
|
|
|
|
|
|
|
if (_engine->gameFlags().platform == Common::kPlatformFMTowns) {
|
|
|
|
Common::List<ResourceFile*>::iterator start = _pakfiles.begin();
|
|
|
|
uint unloadHash = (_engine->gameFlags().lang == Common::EN_ANY) ? Common::hashit_lower("JMC.PAK") : Common::hashit_lower("EMC.PAK");
|
|
|
|
|
|
|
|
for (;start != _pakfiles.end(); ++start) {
|
|
|
|
if ((*start)->filename() == unloadHash) {
|
|
|
|
delete *start;
|
|
|
|
*start = 0;
|
|
|
|
_pakfiles.erase(start);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
Resource::~Resource() {
|
2006-07-08 13:56:56 +00:00
|
|
|
Common::List<ResourceFile*>::iterator start = _pakfiles.begin();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
for (;start != _pakfiles.end(); ++start) {
|
2006-07-08 13:56:56 +00:00
|
|
|
delete *start;
|
|
|
|
*start = 0;
|
2005-10-12 19:15:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-22 20:08:23 +00:00
|
|
|
bool Resource::loadPakFile(const Common::String &filename, const bool forcePC) {
|
2006-09-16 20:51:05 +00:00
|
|
|
Common::List<ResourceFile*>::iterator start = _pakfiles.begin();
|
|
|
|
uint hash = Common::hashit_lower(filename.c_str());
|
|
|
|
for (;start != _pakfiles.end(); ++start) {
|
|
|
|
if ((*start)->filename() == hash) {
|
|
|
|
(*start)->open();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-07-08 13:56:56 +00:00
|
|
|
|
|
|
|
uint32 size = 0;
|
2006-09-09 12:21:49 +00:00
|
|
|
|
2006-07-08 14:25:23 +00:00
|
|
|
Common::File handle;
|
2006-09-09 17:14:47 +00:00
|
|
|
if (!getFileHandle(filename.c_str(), &size, handle)) {
|
2006-06-03 18:30:07 +00:00
|
|
|
warning("couldn't load file: '%s'", filename.c_str());
|
2006-03-18 14:43:18 +00:00
|
|
|
return false;
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2006-07-08 13:56:56 +00:00
|
|
|
|
2006-07-08 14:25:23 +00:00
|
|
|
PAKFile *file = 0;
|
|
|
|
|
2006-10-22 20:08:23 +00:00
|
|
|
file = new PAKFile(filename.c_str(), handle.name(), handle, (_engine->gameFlags().platform == Common::kPlatformAmiga) && !forcePC);
|
2006-07-08 14:25:23 +00:00
|
|
|
handle.close();
|
2006-07-08 13:56:56 +00:00
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return false;
|
2006-07-08 14:25:23 +00:00
|
|
|
if (!file->isValid()) {
|
2006-08-28 14:21:23 +00:00
|
|
|
warning("'%s' is no valid pak file", filename.c_str());
|
2006-07-08 14:25:23 +00:00
|
|
|
delete file;
|
|
|
|
return false;
|
|
|
|
}
|
2006-07-08 13:56:56 +00:00
|
|
|
|
|
|
|
_pakfiles.push_back(file);
|
2005-10-12 19:15:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-06-03 18:30:07 +00:00
|
|
|
void Resource::unloadPakFile(const Common::String &filename) {
|
2006-07-08 13:56:56 +00:00
|
|
|
Common::List<ResourceFile*>::iterator start = _pakfiles.begin();
|
2006-09-16 20:51:05 +00:00
|
|
|
uint hash = Common::hashit_lower(filename.c_str());
|
2005-10-12 19:15:32 +00:00
|
|
|
for (;start != _pakfiles.end(); ++start) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if ((*start)->filename() == hash) {
|
|
|
|
(*start)->close();
|
2005-10-12 19:15:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-06-03 18:30:07 +00:00
|
|
|
bool Resource::isInPakList(const Common::String &filename) {
|
2006-07-08 13:56:56 +00:00
|
|
|
Common::List<ResourceFile*>::iterator start = _pakfiles.begin();
|
2006-09-16 20:51:05 +00:00
|
|
|
uint hash = Common::hashit_lower(filename.c_str());
|
2005-10-12 19:15:32 +00:00
|
|
|
for (;start != _pakfiles.end(); ++start) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if ((*start)->filename() == hash)
|
2005-10-12 19:15:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-02-10 16:39:56 +00:00
|
|
|
uint8 *Resource::fileData(const char *file, uint32 *size) {
|
2007-03-20 20:46:19 +00:00
|
|
|
Common::File fileHandle;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-07-30 07:51:11 +00:00
|
|
|
if (size)
|
|
|
|
*size = 0;
|
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
// test to open it in the main dir
|
2007-03-20 20:46:19 +00:00
|
|
|
if (fileHandle.open(file)) {
|
|
|
|
uint32 fileSize = fileHandle.size();
|
|
|
|
uint8 *buffer = new uint8[fileSize];
|
2004-11-14 20:11:22 +00:00
|
|
|
assert(buffer);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-03-20 20:46:19 +00:00
|
|
|
fileHandle.read(buffer, fileSize);
|
2006-07-30 08:22:39 +00:00
|
|
|
|
|
|
|
if (size)
|
2007-03-20 20:46:19 +00:00
|
|
|
*size = fileSize;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-03-20 20:46:19 +00:00
|
|
|
return buffer;
|
2004-11-14 20:11:22 +00:00
|
|
|
} else {
|
|
|
|
// opens the file in a PAK File
|
2006-07-08 13:56:56 +00:00
|
|
|
Common::List<ResourceFile*>::iterator start = _pakfiles.begin();
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
uint fileHash = Common::hashit_lower(file);
|
2004-11-14 20:11:22 +00:00
|
|
|
for (;start != _pakfiles.end(); ++start) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if (!(*start)->isOpen())
|
|
|
|
continue;
|
|
|
|
|
2007-03-20 20:46:19 +00:00
|
|
|
uint32 fileSize = (*start)->getFileSize(fileHash);
|
2006-07-30 07:51:11 +00:00
|
|
|
|
2007-03-20 20:46:19 +00:00
|
|
|
if (!fileSize)
|
2004-11-14 20:11:22 +00:00
|
|
|
continue;
|
2006-07-30 07:51:11 +00:00
|
|
|
|
|
|
|
if (size)
|
2007-03-20 20:46:19 +00:00
|
|
|
*size = fileSize;
|
2006-07-30 07:51:11 +00:00
|
|
|
|
2007-03-20 20:46:19 +00:00
|
|
|
return (*start)->getFile(fileHash);
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-03-20 20:46:19 +00:00
|
|
|
return 0;
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-09-09 17:14:47 +00:00
|
|
|
bool Resource::getFileHandle(const char *file, uint32 *size, Common::File &filehandle) {
|
2006-02-10 16:39:56 +00:00
|
|
|
filehandle.close();
|
|
|
|
|
|
|
|
if (filehandle.open(file))
|
|
|
|
return true;
|
|
|
|
|
2006-07-08 13:56:56 +00:00
|
|
|
Common::List<ResourceFile*>::iterator start = _pakfiles.begin();
|
2006-02-10 16:39:56 +00:00
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
uint fileHash = Common::hashit_lower(file);
|
2006-02-10 16:39:56 +00:00
|
|
|
for (;start != _pakfiles.end(); ++start) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if (!(*start)->isOpen())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*size = (*start)->getFileSize(fileHash);
|
2006-02-10 16:39:56 +00:00
|
|
|
|
|
|
|
if (!(*size))
|
|
|
|
continue;
|
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
if ((*start)->getFileHandle(fileHash, filehandle)) {
|
2006-02-10 16:39:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-07-31 16:37:34 +00:00
|
|
|
uint32 Resource::getFileSize(const char *file) {
|
|
|
|
Common::List<ResourceFile*>::iterator start = _pakfiles.begin();
|
|
|
|
|
|
|
|
Common::File temp;
|
|
|
|
if (temp.open(file))
|
|
|
|
return temp.size();
|
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
uint fileHash = Common::hashit_lower(file);
|
2006-07-31 16:37:34 +00:00
|
|
|
for (;start != _pakfiles.end(); ++start) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if (!(*start)->isOpen())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uint32 size = (*start)->getFileSize(fileHash);
|
2006-07-31 16:37:34 +00:00
|
|
|
|
|
|
|
if (size)
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Resource::loadFileToBuf(const char *file, void *buf, uint32 maxSize) {
|
|
|
|
Common::File tempHandle;
|
|
|
|
uint32 size = 0;
|
2006-09-09 17:14:47 +00:00
|
|
|
if (!getFileHandle(file, &size, tempHandle))
|
2006-07-31 16:37:34 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (size > maxSize)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
memset(buf, 0, maxSize);
|
|
|
|
tempHandle.read(buf, size);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-10-15 06:06:47 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// Pak file manager
|
2006-06-03 17:58:13 +00:00
|
|
|
#define PAKFile_Iterate Common::List<PakChunk>::iterator start=_files.begin();start != _files.end(); ++start
|
2006-09-10 13:16:34 +00:00
|
|
|
PAKFile::PAKFile(const char *file, const char *physfile, Common::File &pakfile, bool isAmiga) : ResourceFile() {
|
2006-03-18 14:55:29 +00:00
|
|
|
_isAmiga = isAmiga;
|
2006-01-09 19:45:36 +00:00
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
_open = false;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-09-10 13:16:34 +00:00
|
|
|
if (!pakfile.isOpen()) {
|
2006-06-03 18:30:07 +00:00
|
|
|
debug(3, "couldn't open pakfile '%s'\n", file);
|
2004-11-14 20:11:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2006-09-10 13:16:34 +00:00
|
|
|
uint32 off = pakfile.pos();
|
2004-11-14 20:11:22 +00:00
|
|
|
uint32 filesize = pakfile.size();
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
// works with the file
|
|
|
|
uint32 pos = 0, startoffset = 0, endoffset = 0;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2006-03-18 14:55:29 +00:00
|
|
|
if (!_isAmiga) {
|
2006-09-10 13:16:34 +00:00
|
|
|
startoffset = pakfile.readUint32LE();
|
2006-03-14 19:48:08 +00:00
|
|
|
} else {
|
2006-09-10 13:16:34 +00:00
|
|
|
startoffset = pakfile.readUint32BE();
|
2006-03-14 19:48:08 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
pos += 4;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
while (pos < filesize) {
|
2006-06-03 17:58:13 +00:00
|
|
|
PakChunk chunk;
|
2006-09-10 13:16:34 +00:00
|
|
|
uint8 buffer[64];
|
2006-09-09 12:21:49 +00:00
|
|
|
uint32 nameLength;
|
|
|
|
|
|
|
|
// Move to the position of the next file entry
|
|
|
|
pakfile.seek(pos);
|
|
|
|
|
|
|
|
// Read in the header
|
2006-09-10 13:16:34 +00:00
|
|
|
pakfile.read(&buffer, 64);
|
2006-09-09 12:21:49 +00:00
|
|
|
|
|
|
|
// Quit now if we encounter an empty string
|
|
|
|
if (!(*((const char*)buffer)))
|
2006-08-08 21:34:19 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
chunk._name = Common::hashit_lower((const char*)buffer);
|
2006-09-10 13:16:34 +00:00
|
|
|
nameLength = strlen((const char*)buffer) + 1;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2006-03-18 14:55:29 +00:00
|
|
|
if (!_isAmiga) {
|
2006-09-09 12:21:49 +00:00
|
|
|
endoffset = READ_LE_UINT32(buffer + nameLength);
|
2006-03-14 19:48:08 +00:00
|
|
|
} else {
|
2006-09-09 12:21:49 +00:00
|
|
|
endoffset = READ_BE_UINT32(buffer + nameLength);
|
2006-03-14 19:48:08 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
if (endoffset == 0) {
|
|
|
|
endoffset = filesize;
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2006-06-03 17:58:13 +00:00
|
|
|
chunk._start = startoffset;
|
|
|
|
chunk._size = endoffset - startoffset;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
_files.push_back(chunk);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
if (endoffset == filesize)
|
|
|
|
break;
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
startoffset = endoffset;
|
2006-09-09 12:21:49 +00:00
|
|
|
pos += nameLength + 4;
|
2004-10-16 22:28:29 +00:00
|
|
|
}
|
2006-07-08 13:56:56 +00:00
|
|
|
|
2006-09-10 13:16:34 +00:00
|
|
|
_open = true;
|
2006-09-16 20:51:05 +00:00
|
|
|
_filename = Common::hashit_lower(file);
|
2006-07-08 14:25:23 +00:00
|
|
|
_physfile = physfile;
|
|
|
|
_physOffset = off;
|
2006-07-08 13:56:56 +00:00
|
|
|
}
|
|
|
|
|
2006-09-10 13:16:34 +00:00
|
|
|
|
2004-11-14 20:11:22 +00:00
|
|
|
PAKFile::~PAKFile() {
|
2006-07-08 14:25:23 +00:00
|
|
|
_physfile.clear();
|
2004-11-14 20:11:22 +00:00
|
|
|
_open = false;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2006-06-03 17:58:13 +00:00
|
|
|
_files.clear();
|
2004-11-14 20:11:22 +00:00
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
uint8 *PAKFile::getFile(uint hash) {
|
2004-11-14 20:11:22 +00:00
|
|
|
for (PAKFile_Iterate) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if (start->_name == hash) {
|
2005-12-12 17:39:01 +00:00
|
|
|
Common::File pakfile;
|
2006-07-08 14:25:23 +00:00
|
|
|
if (!openFile(pakfile))
|
|
|
|
return false;
|
|
|
|
pakfile.seek(start->_start, SEEK_CUR);
|
2006-06-03 17:58:13 +00:00
|
|
|
uint8 *buffer = new uint8[start->_size];
|
2005-12-12 17:39:01 +00:00
|
|
|
assert(buffer);
|
2006-06-03 17:58:13 +00:00
|
|
|
pakfile.read(buffer, start->_size);
|
2005-12-12 17:39:01 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
bool PAKFile::getFileHandle(uint hash, Common::File &filehandle) {
|
2006-02-10 16:39:56 +00:00
|
|
|
filehandle.close();
|
|
|
|
|
|
|
|
for (PAKFile_Iterate) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if (start->_name == hash) {
|
2006-07-08 14:25:23 +00:00
|
|
|
if (!openFile(filehandle))
|
|
|
|
return false;
|
|
|
|
filehandle.seek(start->_start, SEEK_CUR);
|
2006-02-10 16:39:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
uint32 PAKFile::getFileSize(uint hash) {
|
2004-11-14 20:11:22 +00:00
|
|
|
for (PAKFile_Iterate) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if (start->_name == hash)
|
2006-06-03 17:58:13 +00:00
|
|
|
return start->_size;
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2004-11-14 20:11:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-02-09 07:37:19 +00:00
|
|
|
|
2006-07-08 14:25:23 +00:00
|
|
|
bool PAKFile::openFile(Common::File &filehandle) {
|
|
|
|
filehandle.close();
|
|
|
|
|
2006-09-10 13:16:34 +00:00
|
|
|
if (!filehandle.open(_physfile)) {
|
2006-07-08 14:25:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-09-10 13:16:34 +00:00
|
|
|
filehandle.seek(_physOffset, SEEK_CUR);
|
2006-07-08 14:25:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-07-08 13:56:56 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// Ins file manager
|
|
|
|
#define INSFile_Iterate Common::List<FileEntry>::iterator start=_files.begin();start != _files.end(); ++start
|
|
|
|
INSFile::INSFile(const char *file) : ResourceFile(), _files() {
|
|
|
|
Common::File pakfile;
|
|
|
|
_open = false;
|
|
|
|
|
|
|
|
if (!pakfile.open(file)) {
|
|
|
|
debug(3, "couldn't open insfile '%s'\n", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// thanks to eriktorbjorn for this code (a bit modified though)
|
|
|
|
|
|
|
|
// skip first three bytes
|
|
|
|
pakfile.seek(3);
|
|
|
|
|
|
|
|
// first file is the index table
|
|
|
|
uint32 filesize = pakfile.readUint32LE();
|
|
|
|
|
|
|
|
Common::String temp = "";
|
|
|
|
|
|
|
|
for (uint i = 0; i < filesize; ++i) {
|
|
|
|
byte c = pakfile.readByte();
|
|
|
|
|
|
|
|
if (c == '\\') {
|
|
|
|
temp = "";
|
|
|
|
} else if (c == 0x0D) {
|
|
|
|
// line endings are CRLF
|
|
|
|
c = pakfile.readByte();
|
|
|
|
assert(c == 0x0A);
|
|
|
|
++i;
|
|
|
|
|
|
|
|
FileEntry newEntry;
|
2006-09-16 20:51:05 +00:00
|
|
|
newEntry._name = Common::hashit_lower(temp.c_str());
|
2006-07-08 13:56:56 +00:00
|
|
|
newEntry._start = 0;
|
|
|
|
newEntry._size = 0;
|
|
|
|
_files.push_back(newEntry);
|
|
|
|
|
|
|
|
temp = "";
|
|
|
|
} else {
|
|
|
|
temp += (char)c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pakfile.seek(3);
|
|
|
|
|
|
|
|
for (INSFile_Iterate) {
|
|
|
|
filesize = pakfile.readUint32LE();
|
|
|
|
start->_size = filesize;
|
|
|
|
start->_start = pakfile.pos();
|
|
|
|
pakfile.seek(filesize, SEEK_CUR);
|
|
|
|
}
|
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
_filename = Common::hashit_lower(file);
|
|
|
|
_physfile = file;
|
2006-07-08 13:56:56 +00:00
|
|
|
_open = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
INSFile::~INSFile() {
|
|
|
|
_open = false;
|
|
|
|
|
|
|
|
_files.clear();
|
|
|
|
}
|
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
uint8 *INSFile::getFile(uint hash) {
|
2006-07-08 13:56:56 +00:00
|
|
|
for (INSFile_Iterate) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if (start->_name == hash) {
|
2006-07-08 13:56:56 +00:00
|
|
|
Common::File pakfile;
|
2006-09-16 20:51:05 +00:00
|
|
|
if (!pakfile.open(_physfile)) {
|
2006-07-08 14:25:23 +00:00
|
|
|
return false;
|
2006-07-08 13:56:56 +00:00
|
|
|
}
|
|
|
|
pakfile.seek(start->_start);
|
|
|
|
uint8 *buffer = new uint8[start->_size];
|
|
|
|
assert(buffer);
|
|
|
|
pakfile.read(buffer, start->_size);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
bool INSFile::getFileHandle(uint hash, Common::File &filehandle) {
|
2006-07-08 13:56:56 +00:00
|
|
|
for (INSFile_Iterate) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if (start->_name == hash) {
|
|
|
|
if (!filehandle.open(_physfile)) {
|
2006-07-08 14:25:23 +00:00
|
|
|
return false;
|
2006-07-08 13:56:56 +00:00
|
|
|
}
|
2006-07-08 14:25:23 +00:00
|
|
|
filehandle.seek(start->_start, SEEK_CUR);
|
|
|
|
return true;
|
2006-07-08 13:56:56 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-08 14:25:23 +00:00
|
|
|
return false;
|
2006-07-08 13:56:56 +00:00
|
|
|
}
|
|
|
|
|
2006-09-16 20:51:05 +00:00
|
|
|
uint32 INSFile::getFileSize(uint hash) {
|
2006-07-08 13:56:56 +00:00
|
|
|
for (INSFile_Iterate) {
|
2006-09-16 20:51:05 +00:00
|
|
|
if (start->_name == hash)
|
2006-07-08 13:56:56 +00:00
|
|
|
return start->_size;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-10-15 06:06:47 +00:00
|
|
|
} // end of namespace Kyra
|