ScummVM API documentation
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 libId;
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 Resource getResourceDetail(uint32 tag, uint16 id);
74  uint32 getOffset(uint32 tag, uint16 id) const;
75  uint16 findResourceID(uint32 tag, const Common::String &resName, bool ignoreCase = false) const;
76  Common::String getName(uint32 tag, uint16 id) const;
77  Common::SeekableReadStreamEndian *getMovieResourceIfPresent(uint32 tag);
78 
79  Common::Array<uint32> getResourceTypeList() const;
80  Common::Array<uint16> getResourceIDList(uint32 type) const;
81  bool _isBigEndian;
82  static uint32 convertTagToUppercase(uint32 tag);
83 
84  virtual Common::String formatArchiveInfo();
85 
86  void listUnaccessedChunks();
87 
88 protected:
89  void dumpChunk(Resource &res, Common::DumpFile &out);
94  TypeMap _types;
95  MovieChunkMap _movieChunks;
96 
97  Common::Path _pathName;
98 };
99 
100 class MacArchive : public Archive {
101 public:
102  MacArchive();
103  ~MacArchive() override;
104 
105  uint32 getFileSize() override;
106  void close() override;
107  bool openFile(const Common::Path &path) override;
108  bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
109  Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id) override;
110  Common::String formatArchiveInfo() override;
111 
112 private:
113  Common::MacResManager *_resFork;
114 
115  void readTags();
116 };
117 
118 class RIFFArchive : public Archive {
119 public:
120  RIFFArchive() : Archive() { _startOffset = 0; }
121  ~RIFFArchive() override {}
122 
123  bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
124  Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id) override;
125  Common::String formatArchiveInfo() override;
126 
127  uint32 _startOffset;
128 };
129 
130 class RIFXArchive : public Archive {
131 public:
132  RIFXArchive();
133  ~RIFXArchive() override;
134 
135  bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
136  Common::SeekableReadStreamEndian *getFirstResource(uint32 tag) override;
137  virtual Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, bool fileEndianness);
138  Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id) override;
139  virtual Common::SeekableReadStreamEndian *getResource(uint32 tag, uint16 id, bool fileEndianness);
140  Resource getResourceDetail(uint32 tag, uint16 id) override;
141  Common::String formatArchiveInfo() override;
142 
143 private:
144  bool readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset, Common::SeekableMemoryWriteStream *dumpStream, uint32 movieStartOffset);
145  bool readAfterburnerMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset);
146  void readCast(Common::SeekableReadStreamEndian &casStream, uint16 libId);
147  void readKeyTable(Common::SeekableReadStreamEndian &keyStream);
148 
149 protected:
150  uint32 _rifxType;
151  Common::Array<Resource *> _resources;
153  uint32 _ilsBodyOffset;
157 };
158 
159 /*******************************************
160  *
161  * Projector Archive
162  *
163  *******************************************/
164 
166 public:
168  ~ProjectorArchive() override;
169 
170  bool hasFile(const Common::Path &path) const override;
171  int listMembers(Common::ArchiveMemberList &list) const override;
172  const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
173  Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
174  bool isLoaded() { return _isLoaded; }
175 private:
176  Common::SeekableReadStream *createBufferedReadStream();
177  bool loadArchive(Common::SeekableReadStream *stream);
178 
179  struct Entry {
180  uint32 offset;
181  uint32 size;
182  };
184  FileMap _files;
185  Common::Path _path;
186 
187  bool _isLoaded;
188 };
189 } // End of namespace Director
190 
191 #endif
Definition: archive.h:100
Definition: macresman.h:125
Definition: str.h:59
Definition: archive.h:165
Definition: archive.h:130
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:118
Definition: memstream.h:155