From a730d30f0cf4ae0752635d2ab0b515c17ebf64b1 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Tue, 22 Mar 2011 19:52:55 -0400 Subject: MOHAWK: Cleanup installer handling --- engines/mohawk/installer_archive.cpp | 86 ++++++++++++++---------------------- 1 file changed, 34 insertions(+), 52 deletions(-) (limited to 'engines/mohawk/installer_archive.cpp') diff --git a/engines/mohawk/installer_archive.cpp b/engines/mohawk/installer_archive.cpp index 560d99e121..4ea742dff6 100644 --- a/engines/mohawk/installer_archive.cpp +++ b/engines/mohawk/installer_archive.cpp @@ -40,11 +40,6 @@ InstallerArchive::~InstallerArchive() { close(); } -struct DirectoryEntry { - uint16 fileCount; - Common::String name; -}; - bool InstallerArchive::open(const Common::String &filename) { close(); @@ -60,68 +55,55 @@ bool InstallerArchive::open(const Common::String &filename) { return false; } - // Let's move to the directory + // Let's pull some relevant data from the header _stream->seek(41); - uint32 offset = _stream->readUint32LE(); - _stream->seek(offset); + uint32 directoryTableOffset = _stream->readUint32LE(); + /* uint32 directoryTableSize = */ _stream->readUint32LE(); + uint16 directoryCount = _stream->readUint16LE(); + uint32 fileTableOffset = _stream->readUint32LE(); + /* uint32 fileTableSize = */ _stream->readUint32LE(); + + // We need to have at least one directory in order for the archive to be valid + if (directoryCount == 0) { + close(); + return false; + } - // Now read in each file from the directory + // TODO: Currently, we only support getting files from the first directory + // To that end, get the number of files from that entry + _stream->seek(directoryTableOffset); uint16 fileCount = _stream->readUint16LE(); debug(2, "File count = %d", fileCount); - _stream->skip(9); - - Common::Array directories; - - for (uint16 i = 0; i < fileCount;) { - uint16 dirFileCount = _stream->readUint16LE(); + // Following the directory table is the file table with files stored recursively + // by directory. Since we're only using the first directory, we can just go + // right to that one. + _stream->seek(fileTableOffset); - if (dirFileCount == 0) { - // We've found a file - FileEntry entry; + for (uint16 i = 0; i < fileCount; i++) { + FileEntry entry; - _stream->skip(1); // Unknown + _stream->skip(3); // Unknown - entry.uncompressedSize = _stream->readUint32LE(); - entry.compressedSize = _stream->readUint32LE(); - entry.offset = _stream->readUint32LE(); + entry.uncompressedSize = _stream->readUint32LE(); + entry.compressedSize = _stream->readUint32LE(); + entry.offset = _stream->readUint32LE(); - _stream->skip(14); // Unknown + _stream->skip(14); // Unknown - byte nameLength = _stream->readByte(); - Common::String name; - while (nameLength--) - name += _stream->readByte(); + byte nameLength = _stream->readByte(); + Common::String name; + while (nameLength--) + name += _stream->readByte(); - _stream->skip(13); // Unknown + _stream->skip(13); // Unknown - _map[name] = entry; - i++; + _map[name] = entry; - debug(3, "Found file '%s' at 0x%08x (Comp: 0x%08x, Uncomp: 0x%08x)", name.c_str(), - entry.offset, entry.compressedSize, entry.uncompressedSize); - } else { - // We've found a directory - DirectoryEntry dirEntry; - - dirEntry.fileCount = dirFileCount; - /* uint16 entrySize = */ _stream->readUint16LE(); - - uint16 nameLength = _stream->readUint16LE(); - while (nameLength--) - dirEntry.name += _stream->readByte(); - - directories.push_back(dirEntry); - - _stream->skip(5); // Unknown - - debug(3, "Ignoring directory '%s'", dirEntry.name.c_str()); - } + debug(3, "Found file '%s' at 0x%08x (Comp: 0x%08x, Uncomp: 0x%08x)", name.c_str(), + entry.offset, entry.compressedSize, entry.uncompressedSize); } - // TODO: Handle files in directories - // Per directory found follows DirectoryEntry::fileCount files - return true; } -- cgit v1.2.3