aboutsummaryrefslogtreecommitdiff
path: root/engines/hdb
diff options
context:
space:
mode:
authorNipun Garg2019-05-28 17:37:43 +0530
committerEugene Sandulenko2019-09-03 17:16:41 +0200
commit432ae5ad57e307178fe3767e412cb1784bf0fe1f (patch)
treec8ece382066545b69f6ad667449d6f3bcdb55def /engines/hdb
parent6a764f4252ab0705dce47e722ba112ba88c6cc50 (diff)
downloadscummvm-rg350-432ae5ad57e307178fe3767e412cb1784bf0fe1f.tar.gz
scummvm-rg350-432ae5ad57e307178fe3767e412cb1784bf0fe1f.tar.bz2
scummvm-rg350-432ae5ad57e307178fe3767e412cb1784bf0fe1f.zip
HDB: Add the find functions to the file-manager
Diffstat (limited to 'engines/hdb')
-rw-r--r--engines/hdb/file-manager.cpp68
-rw-r--r--engines/hdb/file-manager.h23
2 files changed, 71 insertions, 20 deletions
diff --git a/engines/hdb/file-manager.cpp b/engines/hdb/file-manager.cpp
index 1530c64d12..a6c12f32b5 100644
--- a/engines/hdb/file-manager.cpp
+++ b/engines/hdb/file-manager.cpp
@@ -27,15 +27,15 @@
namespace HDB {
-bool FileMan::openMSD(const Common::String &filename) {
+bool FileMan::openMPC(const Common::String &filename) {
uint32 offset;
- if (!_msdFile->open(filename)) {
+ if (!_mpcFile->open(filename)) {
error("FileMan::openMSD(): Error reading the MSD file");
return false;
}
- _msdFile->read(&dataHeader.id, 4);
+ _mpcFile->read(&dataHeader.id, 4);
if (dataHeader.id == MKTAG('M', 'P', 'C', 'C')) {
_compressed = true;
@@ -45,25 +45,25 @@ bool FileMan::openMSD(const Common::String &filename) {
else if (dataHeader.id == MKTAG('M', 'P', 'C', 'U')) {
_compressed = false;
- offset = _msdFile->readUint32LE();
- _msdFile->seek((int32)offset, SEEK_SET);
+ offset = _mpcFile->readUint32LE();
+ _mpcFile->seek((int32)offset, SEEK_SET);
// Note: The MPC archive format assumes the offset to be uint32,
// but Common::File::seek() takes the offset as int32.
- dataHeader.dirSize = _msdFile->readUint32LE();
+ dataHeader.dirSize = _mpcFile->readUint32LE();
for (uint32 fileIndex = 0; fileIndex < dataHeader.dirSize; fileIndex++) {
- MSDEntry *dirEntry = new MSDEntry();
+ MPCEntry *dirEntry = new MPCEntry();
for (int fileNameIndex = 0; fileNameIndex < 64; fileNameIndex++) {
- dirEntry->filename[fileNameIndex] = _msdFile->readByte();
+ dirEntry->filename[fileNameIndex] = _mpcFile->readByte();
}
- dirEntry->offset = _msdFile->readUint32LE();
- dirEntry->length = _msdFile->readUint32LE();
- dirEntry->ulength = _msdFile->readUint32LE();
- dirEntry->type = (DataType)_msdFile->readUint32LE();
+ dirEntry->offset = _mpcFile->readUint32LE();
+ dirEntry->length = _mpcFile->readUint32LE();
+ dirEntry->ulength = _mpcFile->readUint32LE();
+ dirEntry->type = (DataType)_mpcFile->readUint32LE();
_dir.push_back(dirEntry);
}
@@ -77,9 +77,49 @@ bool FileMan::openMSD(const Common::String &filename) {
}
-void FileMan::closeMSD() {
+void FileMan::closeMPC() {
_dir.clear();
- _msdFile->close();
+ _mpcFile->close();
+}
+
+MPCEntry **FileMan::findFirstData(char *string, DataType type) {
+ Common::String fileString;
+
+ for (MPCIterator it = _dir.begin(); it != _dir.end(); it++) {
+ fileString = (*it)->filename;
+ if (fileString.contains(string)) {
+ if ((*it)->type == type) {
+ return it;
+ }
+ }
+ }
+ return NULL;
+}
+
+MPCEntry **FileMan::findNextData(MPCIterator begin) {
+ Common::String fileString;
+
+ for (MPCIterator it = begin+1; it != _dir.end(); it++) {
+ fileString = (*it)->filename;
+ if (fileString.contains((*begin)->filename)) {
+ if ((*it)->type == (*begin)->type) {
+ return it;
+ }
+ }
+ }
+ return NULL;
+}
+
+int FileMan::findAmount(char *string, DataType type) {
+ int count = 0;
+
+ MPCIterator it = findFirstData(string, type);
+ while (it && (*it)->type == type) {
+ count++;
+ it = findNextData(it);
+ }
+
+ return count;
}
} // End of Namespace HDB
diff --git a/engines/hdb/file-manager.h b/engines/hdb/file-manager.h
index 5b754cd981..38be6844fd 100644
--- a/engines/hdb/file-manager.h
+++ b/engines/hdb/file-manager.h
@@ -27,6 +27,8 @@
#include "common/file.h"
#include "common/error.h"
+#define MPCIterator Common::Array<MPCEntry *>::iterator
+
namespace HDB {
// Each entry in a MSD file is of the following types
@@ -42,7 +44,7 @@ enum DataType {
ENDOFTYPES
};
-struct MSDEntry {
+struct MPCEntry {
char filename[64]; // filename
int32 offset; // offset in MSD file of data
int32 length; // compressed length of data
@@ -88,8 +90,8 @@ struct CharInfo {
class FileMan {
private:
- Common::File *_msdFile;
- Common::Array<MSDEntry *> _dir;
+ Common::File *_mpcFile;
+ Common::Array<MPCEntry *> _dir;
int _numEntries;
bool _compressed;
@@ -100,10 +102,19 @@ public:
uint32 dirSize;
} dataHeader;
- long readOffset;
+ uint32 readOffset;
- bool openMSD(const Common::String &filename);
- void closeMSD();
+ bool openMPC(const Common::String &filename);
+ void closeMPC();
+ /*
+ TODO: Implement the loadData functions for the various
+ DataTypes as they are encountered.
+
+ void loadData(char *string, uint32 *length);
+ */
+ MPCEntry **findFirstData(char *string, DataType type);
+ MPCEntry **findNextData(MPCIterator it);
+ int findAmount(char *string, DataType type);
};