diff options
author | Nipun Garg | 2019-05-28 17:37:43 +0530 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:16:41 +0200 |
commit | 432ae5ad57e307178fe3767e412cb1784bf0fe1f (patch) | |
tree | c8ece382066545b69f6ad667449d6f3bcdb55def /engines/hdb/file-manager.cpp | |
parent | 6a764f4252ab0705dce47e722ba112ba88c6cc50 (diff) | |
download | scummvm-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/file-manager.cpp')
-rw-r--r-- | engines/hdb/file-manager.cpp | 68 |
1 files changed, 54 insertions, 14 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 |