aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Hesse2009-06-22 10:12:33 +0000
committerSven Hesse2009-06-22 10:12:33 +0000
commitdd9e62e31e18188f43980b24ac9cc5c2ae00623f (patch)
tree024cf88fb409e0eb6c58c6a46e0d8c2326b9efbe
parent1dafcabb4379c205add3d27c428e22c2f970f865 (diff)
downloadscummvm-rg350-dd9e62e31e18188f43980b24ac9cc5c2ae00623f.tar.gz
scummvm-rg350-dd9e62e31e18188f43980b24ac9cc5c2ae00623f.tar.bz2
scummvm-rg350-dd9e62e31e18188f43980b24ac9cc5c2ae00623f.zip
Adding DataIO::existData()
svn-id: r41752
-rw-r--r--engines/gob/dataio.cpp10
-rw-r--r--engines/gob/dataio.h1
-rw-r--r--engines/gob/game.cpp55
-rw-r--r--engines/gob/game.h2
-rw-r--r--engines/gob/init.cpp50
-rw-r--r--engines/gob/inter_v2.cpp7
-rw-r--r--engines/gob/inter_v6.cpp5
-rw-r--r--engines/gob/map_v1.cpp11
-rw-r--r--engines/gob/sound/sound.cpp14
-rw-r--r--engines/gob/videoplayer.cpp6
10 files changed, 59 insertions, 102 deletions
diff --git a/engines/gob/dataio.cpp b/engines/gob/dataio.cpp
index a37586aee6..0a0b8b8c49 100644
--- a/engines/gob/dataio.cpp
+++ b/engines/gob/dataio.cpp
@@ -488,6 +488,16 @@ int16 DataIO::openData(const char *path) {
return file_open(path);
}
+bool DataIO::existData(const char *path) {
+ int16 handle = openData(path);
+
+ if (handle < 0)
+ return false;
+
+ closeData(handle);
+ return true;
+}
+
DataStream *DataIO::openAsStream(int16 handle, bool dispose) {
uint32 curPos = getPos(handle);
seekData(handle, 0, SEEK_END);
diff --git a/engines/gob/dataio.h b/engines/gob/dataio.h
index c67dc89df8..6cdf1fc6d2 100644
--- a/engines/gob/dataio.h
+++ b/engines/gob/dataio.h
@@ -80,6 +80,7 @@ public:
byte *getUnpackedData(const char *name);
void closeData(int16 handle);
int16 openData(const char *path);
+ bool existData(const char *path);
DataStream *openAsStream(int16 handle, bool dispose = false);
int32 getDataSize(const char *name);
diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp
index 09addc3900..8ead71411c 100644
--- a/engines/gob/game.cpp
+++ b/engines/gob/game.cpp
@@ -417,21 +417,18 @@ int16 Game::adjustKey(int16 key) {
}
int32 Game::loadTotFile(const char *path) {
- int16 handle;
int32 size;
_lomHandle = -1;
size = -1;
- handle = _vm->_dataIO->openData(path);
- if (handle >= 0) {
-
+ if (_vm->_dataIO->existData(path)) {
if (!scumm_stricmp(path + strlen(path) - 3, "LOM")) {
warning("Urban Stub: loadTotFile %s", path);
- _lomHandle = handle;
+ _lomHandle = _vm->_dataIO->openData(path);
- DataStream *stream = _vm->_dataIO->openAsStream(handle);
+ DataStream *stream = _vm->_dataIO->openAsStream(_lomHandle);
stream->seek(48);
size = stream->readUint32LE();
@@ -442,7 +439,6 @@ int32 Game::loadTotFile(const char *path) {
delete stream;
} else {
- _vm->_dataIO->closeData(handle);
size = _vm->_dataIO->getDataSize(path);
_totFileData = _vm->_dataIO->getData(path);
}
@@ -497,7 +493,6 @@ void Game::loadExtTable(void) {
void Game::loadImFile(void) {
char path[20];
- int16 handle;
if ((_totFileData[0x3D] != 0) && (_totFileData[0x3B] == 0))
return;
@@ -506,11 +501,9 @@ void Game::loadImFile(void) {
if (_totFileData[0x3B] != 0)
path[strlen(path) - 1] = '0' + _totFileData[0x3B];
- handle = _vm->_dataIO->openData(path);
- if (handle < 0)
+ if (!_vm->_dataIO->existData(path))
return;
- _vm->_dataIO->closeData(handle);
_imFileData = _vm->_dataIO->getData(path);
}
@@ -675,12 +668,10 @@ void Game::switchTotSub(int16 index, int16 skipPlay) {
strcat(_curExtFile, ".EXT");
}
-int16 Game::openLocTextFile(char *locTextFile, int language) {
- int n;
-
- n = strlen(locTextFile);
+bool Game::getLocTextFile(char *locTextFile, int language) {
+ int n = strlen(locTextFile);
if (n < 4)
- return -1;
+ return false;
locTextFile[n - 4] = 0;
switch (language) {
@@ -712,43 +703,42 @@ int16 Game::openLocTextFile(char *locTextFile, int language) {
strcat(locTextFile, ".ang");
break;
}
- return _vm->_dataIO->openData(locTextFile);
+
+ return _vm->_dataIO->existData(locTextFile);
}
byte *Game::loadLocTexts(int32 *dataSize) {
char locTextFile[20];
- int16 handle;
- int i;
strcpy(locTextFile, _curTotFile);
- handle = openLocTextFile(locTextFile, _vm->_global->_languageWanted);
- if (handle >= 0) {
+ bool found = getLocTextFile(locTextFile, _vm->_global->_languageWanted);
+ if (found) {
_foundTotLoc = true;
_vm->_global->_language = _vm->_global->_languageWanted;
} else if (!_foundTotLoc) {
- bool found = false;
-
+ // Trying US for GB and vice versa
if (_vm->_global->_languageWanted == 2) {
- handle = openLocTextFile(locTextFile, 5);
- if (handle >= 0) {
+ found = getLocTextFile(locTextFile, 5);
+ if (found) {
_vm->_global->_language = 5;
found = true;
}
} else if (_vm->_global->_languageWanted == 5) {
- handle = openLocTextFile(locTextFile, 2);
- if (handle >= 0) {
+ found = getLocTextFile(locTextFile, 2);
+ if (found) {
_vm->_global->_language = 2;
found = true;
}
}
if (!found) {
- for (i = 0; i < 10; i++) {
- handle = openLocTextFile(locTextFile, i);
- if (handle >= 0) {
+ // Looking for the first existing language
+ for (int i = 0; i < 10; i++) {
+ found = getLocTextFile(locTextFile, i);
+ if (found) {
_vm->_global->_language = i;
break;
}
@@ -760,14 +750,13 @@ byte *Game::loadLocTexts(int32 *dataSize) {
debugC(1, kDebugFileIO, "Using language %d for %s",
_vm->_global->_language, _curTotFile);
- if (handle >= 0) {
- _vm->_dataIO->closeData(handle);
-
+ if (found) {
if (dataSize)
*dataSize = _vm->_dataIO->getDataSize(locTextFile);
return _vm->_dataIO->getData(locTextFile);
}
+
return 0;
}
diff --git a/engines/gob/game.h b/engines/gob/game.h
index 6e87d8cdd0..8ab3521633 100644
--- a/engines/gob/game.h
+++ b/engines/gob/game.h
@@ -229,7 +229,7 @@ protected:
void loadImFile(void);
void collAreaSub(int16 index, int8 enter);
- int16 openLocTextFile(char *locTextFile, int language);
+ bool getLocTextFile(char *locTextFile, int language);
virtual void setCollisions(byte arg_0 = 1);
virtual void collSub(uint16 offset);
diff --git a/engines/gob/init.cpp b/engines/gob/init.cpp
index 8bf9536286..9d17e6b054 100644
--- a/engines/gob/init.cpp
+++ b/engines/gob/init.cpp
@@ -80,9 +80,6 @@ void Init::doDemo() {
}
void Init::initGame() {
- int16 handle2;
- int16 handle;
- int16 imdHandle;
byte *infBuf;
char *infPtr;
char *infEnd;
@@ -91,11 +88,8 @@ void Init::initGame() {
initVideo();
if (!_vm->isDemo()) {
- handle2 = _vm->_dataIO->openData(_vm->_startStk.c_str());
- if (handle2 >= 0) {
- _vm->_dataIO->closeData(handle2);
+ if (_vm->_dataIO->existData(_vm->_startStk.c_str()))
_vm->_dataIO->openDataFile(_vm->_startStk.c_str());
- }
}
_vm->_util->initInput();
@@ -127,19 +121,13 @@ void Init::initGame() {
return;
}
- handle = _vm->_dataIO->openData("intro.inf");
+ if (!_vm->_dataIO->existData("intro.inf")) {
- if (handle < 0) {
- for (int i = 0; i < 4; i++) {
- handle2 = _vm->_dataIO->openData(_fontNames[i]);
- if (handle2 >= 0) {
- _vm->_dataIO->closeData(handle2);
+ for (int i = 0; i < 4; i++)
+ if (_vm->_dataIO->existData(_fontNames[i]))
_vm->_draw->_fonts[i] = _vm->_util->loadFont(_fontNames[i]);
- }
- }
- } else {
- _vm->_dataIO->closeData(handle);
+ } else {
infBuf = _vm->_dataIO->getData("intro.inf");
infPtr = (char *) infBuf;
@@ -153,11 +141,8 @@ void Init::initGame() {
buffer[j] = 0;
strcat(buffer, ".let");
- handle2 = _vm->_dataIO->openData(buffer);
- if (handle2 >= 0) {
- _vm->_dataIO->closeData(handle2);
+ if (_vm->_dataIO->existData(buffer))
_vm->_draw->_fonts[i] = _vm->_util->loadFont(buffer);
- }
if ((infPtr + 1) >= infEnd)
break;
@@ -167,26 +152,21 @@ void Init::initGame() {
delete[] infBuf;
}
- strcpy(buffer, _vm->_startTot.c_str());
- handle = _vm->_dataIO->openData(buffer);
-
- if (handle >= 0) {
- DataStream *stream = _vm->_dataIO->openAsStream(handle, true);
+ if (_vm->_dataIO->existData(_vm->_startTot.c_str())) {
+ DataStream *stream = _vm->_dataIO->getDataStream(_vm->_startTot.c_str());
stream->seek(0x2C);
_vm->_inter->allocateVars(stream->readUint16LE());
delete stream;
- strcpy(_vm->_game->_curTotFile, buffer);
+ strcpy(_vm->_game->_curTotFile, _vm->_startTot.c_str());
_vm->_sound->cdTest(1, "GOB");
_vm->_sound->cdLoadLIC("gob.lic");
// Search for a Coktel logo animation or image to display
- imdHandle = _vm->_dataIO->openData("coktel.imd");
- if (imdHandle >= 0) {
- _vm->_dataIO->closeData(imdHandle);
+ if (_vm->_dataIO->existData("coktel.imd")) {
_vm->_draw->initScreen();
_vm->_draw->_cursorIndex = -1;
@@ -198,19 +178,17 @@ void Init::initGame() {
}
_vm->_draw->closeScreen();
- } else if ((imdHandle = _vm->_dataIO->openData("coktel.clt")) >= 0) {
+ } else if (_vm->_dataIO->existData("coktel.clt")) {
_vm->_draw->initScreen();
-
- stream = _vm->_dataIO->openAsStream(imdHandle, true);
_vm->_util->clearPalette();
+
+ stream = _vm->_dataIO->getDataStream("coktel.clt");
stream->read((byte *) _vm->_draw->_vgaPalette, 768);
delete stream;
- imdHandle = _vm->_dataIO->openData("coktel.ims");
- if (imdHandle >= 0) {
+ if (_vm->_dataIO->existData("coktel.ims")) {
byte *sprBuf;
- _vm->_dataIO->closeData(imdHandle);
sprBuf = _vm->_dataIO->getData("coktel.ims");
_vm->_video->drawPackedSprite(sprBuf, 320, 200, 0, 0, 0,
*_vm->_draw->_frontSurface);
diff --git a/engines/gob/inter_v2.cpp b/engines/gob/inter_v2.cpp
index 7508bca214..5c846a1105 100644
--- a/engines/gob/inter_v2.cpp
+++ b/engines/gob/inter_v2.cpp
@@ -1317,13 +1317,12 @@ bool Inter_v2::o2_checkData(OpFuncParams &params) {
mode = _vm->_saveLoad->getSaveMode(_vm->_parse->getResultStr());
if (mode == SaveLoad::kSaveModeNone) {
- handle = _vm->_dataIO->openData(_vm->_parse->getResultStr());
- if (handle >= 0) {
- _vm->_dataIO->closeData(handle);
+ if (_vm->_dataIO->existData(_vm->_parse->getResultStr()))
size = _vm->_dataIO->getDataSize(_vm->_parse->getResultStr());
- } else
+ else
warning("File \"%s\" not found", _vm->_parse->getResultStr());
+
} else if (mode == SaveLoad::kSaveModeSave)
size = _vm->_saveLoad->getSize(_vm->_parse->getResultStr());
else if (mode == SaveLoad::kSaveModeExists)
diff --git a/engines/gob/inter_v6.cpp b/engines/gob/inter_v6.cpp
index 365457abeb..a37164c283 100644
--- a/engines/gob/inter_v6.cpp
+++ b/engines/gob/inter_v6.cpp
@@ -432,11 +432,8 @@ void Inter_v6::probe16bitMusic(char *fileName) {
fileName[len - 1] = 'V';
- int16 handle;
- if ((handle = _vm->_dataIO->openData(fileName)) >= 0) {
- _vm->_dataIO->closeData(handle);
+ if (_vm->_dataIO->existData(fileName))
return;
- }
fileName[len - 1] = '8';
}
diff --git a/engines/gob/map_v1.cpp b/engines/gob/map_v1.cpp
index 2c94b3fb24..dacc72d6c7 100644
--- a/engines/gob/map_v1.cpp
+++ b/engines/gob/map_v1.cpp
@@ -64,7 +64,6 @@ void Map_v1::init(void) {
void Map_v1::loadMapObjects(const char *avjFile) {
char avoName[128];
byte *dataBuf;
- int16 handle;
int16 tmp;
int32 flag;
int16 gobDataCount;
@@ -75,15 +74,14 @@ void Map_v1::loadMapObjects(const char *avjFile) {
strcpy(avoName, _sourceFile);
strcat(avoName, ".avo");
- handle = _vm->_dataIO->openData(avoName);
- if (handle >= 0) {
+ if (_vm->_dataIO->existData(avoName)) {
_loadFromAvo = true;
- _vm->_dataIO->closeData(handle);
dataBuf = _vm->_dataIO->getData(avoName);
} else {
_loadFromAvo = false;
dataBuf = _vm->_dataIO->getData(avjFile);
}
+
Common::MemoryReadStream mapData(dataBuf, 4294967295U);
init();
@@ -146,7 +144,6 @@ void Map_v1::loadMapObjects(const char *avjFile) {
void Map_v1::loadSounds(Common::SeekableReadStream &data) {
int16 count;
- int16 handle;
char buf[19];
char sndNames[20][14];
@@ -162,11 +159,9 @@ void Map_v1::loadSounds(Common::SeekableReadStream &data) {
_vm->_sound->sampleLoad(&_vm->_goblin->_soundData[14], SOUND_SND, "diamant1.snd");
for (int i = 0; i < count; i++) {
- handle = _vm->_dataIO->openData(sndNames[i]);
- if (handle < 0)
+ if (!_vm->_dataIO->existData(sndNames[i]))
continue;
- _vm->_dataIO->closeData(handle);
_vm->_sound->sampleLoad(&_vm->_goblin->_soundData[i], SOUND_SND, sndNames[i]);
}
}
diff --git a/engines/gob/sound/sound.cpp b/engines/gob/sound/sound.cpp
index d6dd128f42..21e06e4700 100644
--- a/engines/gob/sound/sound.cpp
+++ b/engines/gob/sound/sound.cpp
@@ -114,14 +114,11 @@ bool Sound::sampleLoad(SoundDesc *sndDesc, SoundType type, const char *fileName,
debugC(2, kDebugSound, "Loading sample \"%s\"", fileName);
- int16 handle = _vm->_dataIO->openData(fileName);
- if (handle < 0) {
+ if (!_vm->_dataIO->existData(fileName)) {
warning("Can't open sample file \"%s\"", fileName);
return false;
}
- _vm->_dataIO->closeData(handle);
-
byte *data;
uint32 size;
@@ -503,17 +500,12 @@ void Sound::cdLoadLIC(const char *fname) {
debugC(1, kDebugSound, "CDROM: Loading LIC \"%s\"", fname);
- int handle = _vm->_dataIO->openData(fname);
-
- if (handle == -1)
+ if (!_vm->_dataIO->existData(fname))
return;
- _vm->_dataIO->closeData(handle);
-
_vm->_dataIO->getUnpackedData(fname);
- handle = _vm->_dataIO->openData(fname);
- DataStream *stream = _vm->_dataIO->openAsStream(handle, true);
+ DataStream *stream = _vm->_dataIO->getDataStream(fname);
_cdrom->readLIC(*stream);
diff --git a/engines/gob/videoplayer.cpp b/engines/gob/videoplayer.cpp
index e82805d6ac..6c07d22333 100644
--- a/engines/gob/videoplayer.cpp
+++ b/engines/gob/videoplayer.cpp
@@ -201,15 +201,11 @@ bool VideoPlayer::findFile(char *fileName, Type &which) {
int i;
for (i = 0; i < ARRAYSIZE(_extensions); i++) {
if ((which == kVideoTypeTry) || (which == ((Type) i))) {
- int16 handle;
-
fileName[len] = '.';
fileName[len + 1] = 0;
strcat(fileName, _extensions[i]);
- handle = _vm->_dataIO->openData(fileName);
- if (handle >= 0) {
- _vm->_dataIO->closeData(handle);
+ if (_vm->_dataIO->existData(fileName)) {
which = (Type) i;
break;
}