ScummVM API documentation
mscab.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MSCAB_H
23 #define MSCAB_H
24 
25 #include "common/hashmap.h"
26 #include "common/hash-str.h"
27 #include "common/stream.h"
28 #include "common/archive.h"
29 #include "common/str.h"
30 #include "common/util.h"
31 
32 namespace Grim {
33 
34 class MsCabinet : public Common::Archive {
35 public:
37  ~MsCabinet();
38 
39  // Common::Archive API implementation
40  bool hasFile(const Common::Path &path) const override;
41  int listMembers(Common::ArchiveMemberList &list) const override;
42  const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
44 
45 private:
47 
48  struct FolderEntry {
49  uint16 comp_type; // The compression type
50  uint16 num_blocks; // The total number of data blocks used by this folder
51  uint32 offset; // The cabinet offset of first datablock
52  };
53 
54  struct FileEntry {
55  uint32 length; // Uncompressed size of the file in bytes
56  FolderEntry *folder; // Folder holding this file
57  uint32 folderOffset; // Uncompressed offset in the folder
58  };
59 
61  FileMap _fileMap;
62 
64  FolderMap _folderMap;
65 
66  Common::String readString(Common::ReadStream *stream);
67 
68  // Decompressor
69  class Decompressor {
70  public:
71  Decompressor(const FolderEntry *folder, Common::SeekableReadStream *_data);
72  ~Decompressor();
73  bool decompressFile(byte *&fileBuf, const FileEntry &entry);
74  const FolderEntry *getFolder() const {
75  return _curFolder;
76  }
77  private:
79  const FolderEntry *_curFolder;
80  int16 _curBlock;
81  byte *_compressedBlock, *_decompressedBlock;
82  byte *_fileBuf;
83  uint16 _startBlock, _inBlockStart, _endBlock, _inBlockEnd;
84 
85  void copyBlock(byte *&data_ptr) const;
86 
87  enum {
88  kMszipCompression = 1,
89  kCabBlockSize = 0x8000,
90  kCabInputmax = kCabBlockSize + 12
91  };
92  };
93 
94  mutable Decompressor *_decompressor;
95 
96  // Cache
98  mutable CacheMap _cache;
99 };
100 
101 } // End of namespace Grim
102 
103 #endif
bool hasFile(const Common::Path &path) const override
Definition: str.h:59
Definition: list.h:44
Definition: path.h:52
Definition: stream.h:745
Definition: actor.h:33
Definition: archive.h:141
const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override
Definition: stream.h:385
Definition: mscab.h:34
Common::SeekableReadStream * createReadStreamForMember(const Common::Path &path) const override
int listMembers(Common::ArchiveMemberList &list) const override