ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
archive.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 DIRECTOR_ARCHIVE_H
23 #define DIRECTOR_ARCHIVE_H
24 
25 #include "common/file.h"
26 
27 namespace Common {
28 class MacResManager;
29 class SeekableMemoryWriteStream;
30 class SeekableReadStreamEndian;
31 class SeekableReadStream;
32 class Path;
33 }
34 
35 namespace Director {
36 
37 // Completely ripped off of Mohawk's Archive code
38 
39 struct Resource {
40  uint32 index;
41  int32 offset;
42  uint32 size;
43  uint32 uncompSize;
44  uint32 compressionType;
45  uint32 castId;
46  uint32 libResourceId;
47  uint32 tag;
48  Common::String name;
49  Common::Array<Resource> children;
50  bool accessed;
51 };
52 
53 class Archive {
54 public:
55  Archive();
56  virtual ~Archive();
57 
58  virtual bool openFile(const Common::Path &path);
59  virtual bool openStream(Common::SeekableReadStream *stream, uint32 offset = 0) = 0;
60  virtual void close();
61 
62  Common::Path getPathName() const { return _pathName; }
63  Common::String getFileName() const;
64  void setPathName(const Common::Path &name) { _pathName = name; }
65  virtual uint32 getFileSize();
66 
67  bool isOpen() const { return _stream != 0; }
68 
69  bool hasResource(uint32 tag, int id) const;
70  bool hasResource(uint32 tag, const Common::String &resName) const;
71  virtual Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id);
72  virtual Common::SeekableReadStreamEndian *getFirstResource(uint32 tag);
73  virtual Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, uint16 parentId);
74  virtual Resource getResourceDetail(uint32 tag, uint16 id);
75  uint32 getOffset(uint32 tag, uint16 id) const;
76  uint16 findResourceID(uint32 tag, const Common::String &resName, bool ignoreCase = false) const;
77  Common::String getName(uint32 tag, uint16 id) const;
78  Common::SeekableReadStreamEndian *getMovieResourceIfPresent(uint32 tag);
79 
80  Common::Array<uint32> getResourceTypeList() const;
81  Common::Array<uint16> getResourceIDList(uint32 type) const;
82  bool _isBigEndian;
83  static uint32 convertTagToUppercase(uint32 tag);
84 
85  virtual Common::String formatArchiveInfo();
86 
87  void listUnaccessedChunks();
88 
89 protected:
90  void dumpChunk(Resource &res, Common::DumpFile &out);
95  TypeMap _types;
96  MovieChunkMap _movieChunks;
97 
98  Common::Path _pathName;
99 };
100 
101 class MacArchive : public Archive {
102 public:
103  MacArchive();
104  ~MacArchive() override;
105 
106  uint32 getFileSize() override;
107  void close() override;
108  bool openFile(const Common::Path &path) override;
109  bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
110  Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id) override;
111  Common::String formatArchiveInfo() override;
112 
113 private:
114  Common::MacResManager *_resFork;
115 
116  void readTags();
117 };
118 
119 class RIFFArchive : public Archive {
120 public:
121  RIFFArchive() : Archive() { _startOffset = 0; }
122  ~RIFFArchive() override {}
123 
124  bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
125  Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id) override;
126  Common::String formatArchiveInfo() override;
127 
128  uint32 _startOffset;
129 };
130 
131 class RIFXArchive : public Archive {
132 public:
133  RIFXArchive();
134  ~RIFXArchive() override;
135 
136  bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
137  Common::SeekableReadStreamEndian *getFirstResource(uint32 tag) override;
138  virtual Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, bool fileEndianness);
139  Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, uint16 parentId) override;
140  Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id) override;
141  virtual Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id, bool fileEndianness);
142  Resource getResourceDetail(uint32 tag, uint16 id) override;
143  Common::String formatArchiveInfo() override;
144 
145 private:
146  bool readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset, Common::SeekableMemoryWriteStream *dumpStream, uint32 movieStartOffset);
147  bool readAfterburnerMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset);
148  void readCast(Common::SeekableReadStreamEndian &casStream, uint16 libResourceId);
149  void readKeyTable(Common::SeekableReadStreamEndian &keyStream);
150 
151 protected:
152  uint32 _rifxType;
153  Common::Array<Resource *> _resources;
155  uint32 _ilsBodyOffset;
159 };
160 
161 /*******************************************
162  *
163  * Projector Archive
164  *
165  *******************************************/
166 
168 public:
170  ~ProjectorArchive() override;
171 
172  bool hasFile(const Common::Path &path) const override;
173  int listMembers(Common::ArchiveMemberList &list) const override;
174  const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
175  Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
176  bool isLoaded() { return _isLoaded; }
177 private:
178  Common::SeekableReadStream *createBufferedReadStream();
179  bool loadArchive(Common::SeekableReadStream *stream);
180 
181  struct Entry {
182  uint32 offset;
183  uint32 size;
184  };
186  FileMap _files;
187  Common::Path _path;
188 
189  bool _isLoaded;
190 };
191 } // End of namespace Director
192 
193 #endif
Definition: archive.h:101
Definition: macresman.h:125
Definition: str.h:59
Definition: archive.h:167
Definition: archive.h:131
Definition: list.h:44
Definition: path.h:52
Definition: stream.h:745
Definition: file.h:145
Definition: archive.h:35
Definition: archive.h:141
Definition: archive.h:53
Path
Definition: game.h:75
Definition: hashmap.h:85
Definition: algorithm.h:29
Definition: archive.h:39
Definition: stream.h:944
Definition: archive.h:119
Definition: memstream.h:155