aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJohannes Schickel2008-09-07 22:30:34 +0000
committerJohannes Schickel2008-09-07 22:30:34 +0000
commitbd10e674a3c5e7b3ac87aaa405565a3f532de52c (patch)
tree8147aea48be74620936767b0416c05eb20777e7f /engines
parent2bc093828f0c626c7dd57f9cb300284b8563e411 (diff)
downloadscummvm-rg350-bd10e674a3c5e7b3ac87aaa405565a3f532de52c.tar.gz
scummvm-rg350-bd10e674a3c5e7b3ac87aaa405565a3f532de52c.tar.bz2
scummvm-rg350-bd10e674a3c5e7b3ac87aaa405565a3f532de52c.zip
Got rid of all Common::File usages in Kyra.
svn-id: r34435
Diffstat (limited to 'engines')
-rw-r--r--engines/kyra/resource.cpp25
-rw-r--r--engines/kyra/resource.h2
-rw-r--r--engines/kyra/sound_towns.cpp4
-rw-r--r--engines/kyra/staticres.cpp16
-rw-r--r--engines/kyra/vqa.cpp138
-rw-r--r--engines/kyra/vqa.h4
6 files changed, 96 insertions, 93 deletions
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp
index 362c6a205d..fe2b24e856 100644
--- a/engines/kyra/resource.cpp
+++ b/engines/kyra/resource.cpp
@@ -61,7 +61,7 @@ bool Resource::reset() {
if (!dir.exists() || !dir.isDirectory())
error("invalid game path '%s'", dir.getPath().c_str());
- if (!loadPakFile(StaticResource::staticDataFilename()) || !StaticResource::checkKyraDat()) {
+ if (!loadPakFile(StaticResource::staticDataFilename()) || !StaticResource::checkKyraDat(this)) {
Common::String errorMessage = "You're missing the '" + StaticResource::staticDataFilename() + "' file or it got corrupted, (re)get it from the ScummVM website";
_vm->GUIErrorMessage(errorMessage);
error(errorMessage.c_str());
@@ -71,10 +71,6 @@ bool Resource::reset() {
// We only need kyra.dat for the demo.
if (_vm->gameFlags().isDemo)
return true;
-
- // only VRM file we need in the *whole* game for kyra1
- if (_vm->gameFlags().isTalkie)
- loadPakFile("CHAPTER1.VRM");
} else if (_vm->game() == GI_KYRA2) {
if (_vm->gameFlags().useInstallerPackage)
_files.add("installer", loadInstallerArchive("WESTWOOD", "%03d", 6), 2);
@@ -118,7 +114,8 @@ bool Resource::reset() {
for (uint i = 0; i < ARRAYSIZE(list); ++i) {
Common::ArchivePtr archive = loadArchive(list[i]);
- _protectedFiles->add(list[i], archive, 0);
+ if (archive)
+ _protectedFiles->add(list[i], archive, 0);
}
} else {
for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
@@ -158,20 +155,20 @@ bool Resource::loadPakFile(Common::String filename) {
}
bool Resource::loadFileList(const Common::String &filedata) {
- Common::File f;
+ Common::SeekableReadStream *f = getFileStream(filedata);
- if (!f.open(filedata))
+ if (!f)
return false;
uint32 filenameOffset = 0;
- while ((filenameOffset = f.readUint32LE()) != 0) {
- uint32 offset = f.pos();
- f.seek(filenameOffset, SEEK_SET);
+ while ((filenameOffset = f->readUint32LE()) != 0) {
+ uint32 offset = f->pos();
+ f->seek(filenameOffset, SEEK_SET);
uint8 buffer[13];
- f.read(buffer, sizeof(buffer)-1);
+ f->read(buffer, sizeof(buffer)-1);
buffer[12] = 0;
- f.seek(offset + 16, SEEK_SET);
+ f->seek(offset + 16, SEEK_SET);
Common::String filename = Common::String((char *)buffer);
filename.toUppercase();
@@ -183,12 +180,14 @@ bool Resource::loadFileList(const Common::String &filedata) {
// so we don't do anything here if they are non
// existant.
} else if (!loadPakFile(filename)) {
+ delete f;
error("couldn't load file '%s'", filename.c_str());
return false;
}
}
}
+ delete f;
return true;
}
diff --git a/engines/kyra/resource.h b/engines/kyra/resource.h
index cfefa6e3b0..54b845c5c9 100644
--- a/engines/kyra/resource.h
+++ b/engines/kyra/resource.h
@@ -212,7 +212,7 @@ public:
StaticResource(KyraEngine_v1 *vm) : _vm(vm), _resList(), _fileLoader(0), _builtIn(0), _filenameTable(0) {}
~StaticResource() { deinit(); }
- static bool checkKyraDat();
+ static bool checkKyraDat(Resource *res);
bool init();
void deinit();
diff --git a/engines/kyra/sound_towns.cpp b/engines/kyra/sound_towns.cpp
index c57636a3fb..5bb09e5dc9 100644
--- a/engines/kyra/sound_towns.cpp
+++ b/engines/kyra/sound_towns.cpp
@@ -4122,9 +4122,9 @@ bool SoundTownsPC98_v2::init() {
// this misses the possibility that we play the tracks
// right off CD. So we should find another way to
// check if we have access to CD audio.
+ Resource *res = _vm->resource();
if (_musicEnabled &&
- (Common::File::exists("track1.mp3") || Common::File::exists("track1.ogg") ||
- Common::File::exists("track1.flac") || Common::File::exists("track1.fla")))
+ (res->exists("track1.mp3") || res->exists("track1.ogg") || res->exists("track1.flac") || res->exists("track1.fla")))
_musicEnabled = 2;
return _driver->init();
diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp
index 9156fa7e9c..78d0961011 100644
--- a/engines/kyra/staticres.cpp
+++ b/engines/kyra/staticres.cpp
@@ -45,20 +45,20 @@ namespace Kyra {
#define RESFILE_VERSION 32
-bool StaticResource::checkKyraDat() {
- Common::File kyraDat;
- if (!kyraDat.open(StaticResource::staticDataFilename()))
+bool StaticResource::checkKyraDat(Resource *res) {
+ Common::SharedPtr<Common::SeekableReadStream> kyraDat(res->getFileStream(StaticResource::staticDataFilename()));
+ if (!kyraDat)
return false;
- uint32 size = kyraDat.size() - 16;
+ uint32 size = kyraDat->size() - 16;
uint8 digest[16];
- kyraDat.seek(size, SEEK_SET);
- if (kyraDat.read(digest, 16) != 16)
+ kyraDat->seek(size, SEEK_SET);
+ if (kyraDat->read(digest, 16) != 16)
return false;
- kyraDat.close();
uint8 digestCalc[16];
- if (!Common::md5_file(StaticResource::staticDataFilename().c_str(), digestCalc, size))
+ kyraDat->seek(0, SEEK_SET);
+ if (!Common::md5_file(*kyraDat, digestCalc, size))
return false;
for (int i = 0; i < 16; ++i)
diff --git a/engines/kyra/vqa.cpp b/engines/kyra/vqa.cpp
index d5b63bdf6b..9a9941e20e 100644
--- a/engines/kyra/vqa.cpp
+++ b/engines/kyra/vqa.cpp
@@ -38,6 +38,7 @@
#include "kyra/sound.h"
#include "kyra/screen.h"
#include "kyra/vqa.h"
+#include "kyra/resource.h"
namespace Kyra {
@@ -90,10 +91,10 @@ uint32 VQAMovie::readTag() {
// Some tags have to be on an even offset, so they are padded with a
// zero byte. Skip that.
- uint32 tag = _file.readUint32BE();
+ uint32 tag = _file->readUint32BE();
if (!(tag & 0xFF000000)) {
- tag = (tag << 8) | _file.readByte();
+ tag = (tag << 8) | _file->readByte();
}
return tag;
@@ -184,18 +185,19 @@ bool VQAMovie::open(const char *filename) {
debugC(9, kDebugLevelMovie, "VQAMovie::open('%s')", filename);
close();
- if (!_file.open(filename))
+ _file = _vm->resource()->getFileStream(filename);
+ if (!_file)
return false;
- if (_file.readUint32BE() != MKID_BE('FORM')) {
+ if (_file->readUint32BE() != MKID_BE('FORM')) {
warning("VQAMovie::open: Cannot find `FORM' tag");
return false;
}
// For now, we ignore the size of the FORM chunk.
- _file.readUint32BE();
+ _file->readUint32BE();
- if (_file.readUint32BE() != MKID_BE('WVQA')) {
+ if (_file->readUint32BE() != MKID_BE('WVQA')) {
warning("WQAMovie::open: Cannot find `WVQA' tag");
return false;
}
@@ -208,30 +210,30 @@ bool VQAMovie::open(const char *filename) {
while (!foundHeader || !foundFrameInfo) {
uint32 tag = readTag();
- uint32 size = _file.readUint32BE();
+ uint32 size = _file->readUint32BE();
switch (tag) {
case MKID_BE('VQHD'): // VQA header
- _header.version = _file.readUint16LE();
- _header.flags = _file.readUint16LE();
- _header.numFrames = _file.readUint16LE();
- _header.width = _file.readUint16LE();
- _header.height = _file.readUint16LE();
- _header.blockW = _file.readByte();
- _header.blockH = _file.readByte();
- _header.frameRate = _file.readByte();
- _header.cbParts = _file.readByte();
- _header.colors = _file.readUint16LE();
- _header.maxBlocks = _file.readUint16LE();
- _header.unk1 = _file.readUint32LE();
- _header.unk2 = _file.readUint16LE();
- _header.freq = _file.readUint16LE();
- _header.channels = _file.readByte();
- _header.bits = _file.readByte();
- _header.unk3 = _file.readUint32LE();
- _header.unk4 = _file.readUint16LE();
- _header.maxCBFZSize = _file.readUint32LE();
- _header.unk5 = _file.readUint32LE();
+ _header.version = _file->readUint16LE();
+ _header.flags = _file->readUint16LE();
+ _header.numFrames = _file->readUint16LE();
+ _header.width = _file->readUint16LE();
+ _header.height = _file->readUint16LE();
+ _header.blockW = _file->readByte();
+ _header.blockH = _file->readByte();
+ _header.frameRate = _file->readByte();
+ _header.cbParts = _file->readByte();
+ _header.colors = _file->readUint16LE();
+ _header.maxBlocks = _file->readUint16LE();
+ _header.unk1 = _file->readUint32LE();
+ _header.unk2 = _file->readUint16LE();
+ _header.freq = _file->readUint16LE();
+ _header.channels = _file->readByte();
+ _header.bits = _file->readByte();
+ _header.unk3 = _file->readUint32LE();
+ _header.unk4 = _file->readUint16LE();
+ _header.maxCBFZSize = _file->readUint32LE();
+ _header.unk5 = _file->readUint32LE();
// Kyrandia 3 uses version 1 VQA files, and is the only
// known game to do so. This version of the format has
@@ -301,7 +303,7 @@ bool VQAMovie::open(const char *filename) {
foundFrameInfo = true;
for (int i = 0; i < _header.numFrames; i++) {
- _frameInfo[i] = 2 * _file.readUint32LE();
+ _frameInfo[i] = 2 * _file->readUint32LE();
}
// HACK: This flag is set in jung2.vqa, and its
@@ -317,31 +319,31 @@ bool VQAMovie::open(const char *filename) {
// to the first VQFR chunk.
if (_frameInfo[0] & 0x01000000) {
- uint32 oldPos = _file.pos();
+ uint32 oldPos = _file->pos();
while (1) {
uint32 scanTag = readTag();
- uint32 scanSize = _file.readUint32BE();
+ uint32 scanSize = _file->readUint32BE();
- if (_file.eos())
+ if (_file->eos())
break;
if (scanTag == MKID_BE('VQFR')) {
- _frameInfo[0] = (_file.pos() - 8) | 0x80000000;
+ _frameInfo[0] = (_file->pos() - 8) | 0x80000000;
break;
}
- _file.seek(scanSize, SEEK_CUR);
+ _file->seek(scanSize, SEEK_CUR);
}
- _file.seek(oldPos);
+ _file->seek(oldPos);
}
break;
default:
warning("VQAMovie::open: Unknown tag `%c%c%c%c'", char((tag >> 24) & 0xFF), char((tag >> 16) & 0xFF), char((tag >> 8) & 0xFF), char(tag & 0xFF));
- _file.seek(size, SEEK_CUR);
+ _file->seek(size, SEEK_CUR);
break;
}
}
@@ -372,8 +374,8 @@ void VQAMovie::close() {
_vectorPointers = NULL;
_stream = NULL;
- if (_file.isOpen())
- _file.close();
+ delete _file;
+ _file = 0;
freeBuffers();
@@ -390,13 +392,13 @@ void VQAMovie::displayFrame(uint frameNum) {
bool foundFrame = false;
uint i;
- _file.seek(_frameInfo[frameNum] & 0x7FFFFFFF);
+ _file->seek(_frameInfo[frameNum] & 0x7FFFFFFF);
while (!foundSound || !foundFrame) {
uint32 tag = readTag();
- uint32 size = _file.readUint32BE();
+ uint32 size = _file->readUint32BE();
- if (_file.eos()) {
+ if (_file->eos()) {
// This happens at the last frame. Apparently it has
// no sound?
break;
@@ -410,18 +412,18 @@ void VQAMovie::displayFrame(uint frameNum) {
case MKID_BE('SND0'): // Uncompressed sound
foundSound = true;
inbuf = new byte[size];
- _file.read(inbuf, size);
+ _file->read(inbuf, size);
assert(_stream);
_stream->queueBuffer(inbuf, size);
break;
case MKID_BE('SND1'): // Compressed sound, almost like AUD
foundSound = true;
- outsize = _file.readUint16LE();
- insize = _file.readUint16LE();
+ outsize = _file->readUint16LE();
+ insize = _file->readUint16LE();
inbuf = new byte[insize];
- _file.read(inbuf, insize);
+ _file->read(inbuf, insize);
if (insize == outsize) {
assert(_stream);
@@ -438,50 +440,50 @@ void VQAMovie::displayFrame(uint frameNum) {
case MKID_BE('SND2'): // Compressed sound
foundSound = true;
warning("VQAMovie::displayFrame: `SND2' is not implemented");
- _file.seek(size, SEEK_CUR);
+ _file->seek(size, SEEK_CUR);
break;
case MKID_BE('VQFR'):
foundFrame = true;
- end = _file.pos() + size - 8;
+ end = _file->pos() + size - 8;
- while (_file.pos() < end) {
+ while (_file->pos() < end) {
tag = readTag();
- size = _file.readUint32BE();
+ size = _file->readUint32BE();
switch (tag) {
case MKID_BE('CBF0'): // Full codebook
- _file.read(_codeBook, size);
+ _file->read(_codeBook, size);
break;
case MKID_BE('CBFZ'): // Full codebook
inbuf = (byte *)allocBuffer(0, size);
- _file.read(inbuf, size);
+ _file->read(inbuf, size);
Screen::decodeFrame4(inbuf, _codeBook, _codeBookSize);
break;
case MKID_BE('CBP0'): // Partial codebook
_compressedCodeBook = false;
- _file.read(_partialCodeBook + _partialCodeBookSize, size);
+ _file->read(_partialCodeBook + _partialCodeBookSize, size);
_partialCodeBookSize += size;
_numPartialCodeBooks++;
break;
case MKID_BE('CBPZ'): // Partial codebook
_compressedCodeBook = true;
- _file.read(_partialCodeBook + _partialCodeBookSize, size);
+ _file->read(_partialCodeBook + _partialCodeBookSize, size);
_partialCodeBookSize += size;
_numPartialCodeBooks++;
break;
case MKID_BE('CPL0'): // Palette
assert(size <= 3 * 256);
- _file.read(_vm->screen()->_currentPalette, size);
+ _file->read(_vm->screen()->_currentPalette, size);
break;
case MKID_BE('CPLZ'): // Palette
inbuf = (byte *)allocBuffer(0, size);
- _file.read(inbuf, size);
+ _file->read(inbuf, size);
Screen::decodeFrame4(inbuf, _vm->screen()->_currentPalette, 768);
break;
@@ -489,14 +491,14 @@ void VQAMovie::displayFrame(uint frameNum) {
assert(size / 2 <= _numVectorPointers);
for (i = 0; i < size / 2; i++)
- _vectorPointers[i] = _file.readUint16LE();
+ _vectorPointers[i] = _file->readUint16LE();
break;
case MKID_BE('VPTZ'): // Frame data
inbuf = (byte *)allocBuffer(0, size);
outbuf = (byte *)allocBuffer(1, 2 * _numVectorPointers);
- _file.read(inbuf, size);
+ _file->read(inbuf, size);
size = Screen::decodeFrame4(inbuf, outbuf, 2 * _numVectorPointers);
assert(size / 2 <= _numVectorPointers);
@@ -507,7 +509,7 @@ void VQAMovie::displayFrame(uint frameNum) {
default:
warning("VQAMovie::displayFrame: Unknown `VQFR' sub-tag `%c%c%c%c'", char((tag >> 24) & 0xFF), char((tag >> 16) & 0xFF), char((tag >> 8) & 0xFF), char(tag & 0xFF));
- _file.seek(size, SEEK_CUR);
+ _file->seek(size, SEEK_CUR);
break;
}
@@ -517,7 +519,7 @@ void VQAMovie::displayFrame(uint frameNum) {
default:
warning("VQAMovie::displayFrame: Unknown tag `%c%c%c%c'", char((tag >> 24) & 0xFF), char((tag >> 16) & 0xFF), char((tag >> 8) & 0xFF), char(tag & 0xFF));
- _file.seek(size, SEEK_CUR);
+ _file->seek(size, SEEK_CUR);
break;
}
}
@@ -592,11 +594,11 @@ void VQAMovie::play() {
uint32 insize, outsize;
if (_stream) {
- while (_file.pos() < (_frameInfo[0] & 0x7FFFFFFF)) {
+ while (_file->pos() < (_frameInfo[0] & 0x7FFFFFFF)) {
uint32 tag = readTag();
- uint32 size = _file.readUint32BE();
+ uint32 size = _file->readUint32BE();
- if (_file.eos()) {
+ if (_file->eos()) {
warning("VQAMovie::play: Unexpected EOF");
break;
}
@@ -604,16 +606,16 @@ void VQAMovie::play() {
switch (tag) {
case MKID_BE('SND0'): // Uncompressed sound
inbuf = new byte[size];
- _file.read(inbuf, size);
+ _file->read(inbuf, size);
_stream->queueBuffer(inbuf, size);
break;
case MKID_BE('SND1'): // Compressed sound
- outsize = _file.readUint16LE();
- insize = _file.readUint16LE();
+ outsize = _file->readUint16LE();
+ insize = _file->readUint16LE();
inbuf = new byte[insize];
- _file.read(inbuf, insize);
+ _file->read(inbuf, insize);
if (insize == outsize) {
_stream->queueBuffer(inbuf, insize);
@@ -627,17 +629,17 @@ void VQAMovie::play() {
case MKID_BE('SND2'): // Compressed sound
warning("VQAMovie::play: `SND2' is not implemented");
- _file.seek(size, SEEK_CUR);
+ _file->seek(size, SEEK_CUR);
break;
case MKID_BE('CMDS'): // Unused tag, always empty in kyra3
debugC(9, kDebugLevelMovie, "VQAMovie::play: skipping CMDS tag");
- _file.seek(size, SEEK_CUR);
+ _file->seek(size, SEEK_CUR);
break;
default:
warning("VQAMovie::play: Unknown tag `%c%c%c%c'", char((tag >> 24) & 0xFF), char((tag >> 16) & 0xFF), char((tag >> 8) & 0xFF), char(tag & 0xFF));
- _file.seek(size, SEEK_CUR);
+ _file->seek(size, SEEK_CUR);
break;
}
}
diff --git a/engines/kyra/vqa.h b/engines/kyra/vqa.h
index f600f008b7..46d3bd48fb 100644
--- a/engines/kyra/vqa.h
+++ b/engines/kyra/vqa.h
@@ -26,6 +26,8 @@
#ifndef KYRA_VQA_H
#define KYRA_VQA_H
+#include "common/stream.h"
+
class OSystem;
namespace Kyra {
@@ -98,7 +100,7 @@ protected:
void displayFrame(uint frameNum);
- Common::File _file;
+ Common::SeekableReadStream *_file;
VQAHeader _header;
uint32 *_frameInfo;