ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

mscab.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef MSCAB_H
00024 #define MSCAB_H
00025 
00026 #include "common/hashmap.h"
00027 #include "common/hash-str.h"
00028 #include "common/stream.h"
00029 #include "common/archive.h"
00030 #include "common/str.h"
00031 #include "common/util.h"
00032 
00033 namespace Grim {
00034 
00035 class MsCabinet : public Common::Archive {
00036 public:
00037     MsCabinet(Common::SeekableReadStream *data);
00038     ~MsCabinet();
00039 
00040     // Common::Archive API implementation
00041     bool hasFile(const Common::String &name) const override;
00042     int listMembers(Common::ArchiveMemberList &list) const override;
00043     const Common::ArchiveMemberPtr getMember(const Common::String &name) const override;
00044     Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const override;
00045 
00046 private:
00047     Common::SeekableReadStream *_data;
00048 
00049     struct FolderEntry {
00050         uint16 comp_type;           //The compression type
00051         uint16 num_blocks;          //The total number of data blocks used by this folder
00052         uint32 offset;              //The cabinet offset of first datablock
00053     };
00054 
00055     struct FileEntry {
00056         uint32 length;              //Uncompressed size of the file in bytes
00057         FolderEntry *folder;        //Folder holding this file
00058         uint32 folderOffset;        //Uncompressed offset in the folder
00059     };
00060 
00061     typedef Common::HashMap<Common::String, FileEntry, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> FileMap;
00062     FileMap _fileMap;
00063 
00064     typedef Common::HashMap<uint16, FolderEntry> FolderMap;
00065     FolderMap _folderMap;
00066 
00067     Common::String readString(Common::ReadStream *stream);
00068 
00069     //Decompressor
00070     class Decompressor {
00071     public:
00072         Decompressor(const FolderEntry *folder, Common::SeekableReadStream *_data);
00073         ~Decompressor();
00074         bool decompressFile(byte *&fileBuf, const FileEntry &entry);
00075         const FolderEntry *getFolder() const {
00076             return _curFolder;
00077         }
00078     private:
00079         Common::SeekableReadStream *_data;
00080         const FolderEntry *_curFolder;
00081         int16 _curBlock;
00082         byte *_compressedBlock, *_decompressedBlock;
00083         byte *_fileBuf;
00084         uint16 _startBlock, _inBlockStart, _endBlock, _inBlockEnd;
00085 
00086         void copyBlock(byte *&data_ptr) const;
00087 
00088         enum {
00089             kMszipCompression = 1,
00090             kCabBlockSize = 0x8000,
00091             kCabInputmax = kCabBlockSize + 12
00092         };
00093     };
00094 
00095     mutable Decompressor *_decompressor;
00096 
00097     //Cache
00098     typedef Common::HashMap<Common::String, byte *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> CacheMap;
00099     mutable CacheMap _cache;
00100 };
00101 
00102 } // End of namespace Grim
00103 
00104 #endif


Generated on Sat Oct 19 2019 05:01:06 for ResidualVM by doxygen 1.7.1
curved edge   curved edge