ScummVM API documentation
macresman.h
Go to the documentation of this file.
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 
27 #include "common/array.h"
28 #include "common/fs.h"
29 #include "common/rect.h"
30 #include "common/str.h"
31 #include "common/str-array.h"
32 
33 #ifndef COMMON_MACRESMAN_H
34 #define COMMON_MACRESMAN_H
35 
36 namespace Common {
37 
56 typedef Array<uint16> MacResIDArray;
57 typedef Array<uint32> MacResTagArray;
58 
63  byte data[16];
64 };
65 
70  byte data[16];
71 };
72 
76 struct MacFinderInfo {
77  enum FinderFlags {
78  kFinderFlagAlias = (1 << 15),
79  kFinderFlagInvisible = (1 << 14),
80  kFinderFlagBundle = (1 << 13),
81  kFinderFlagNameLocked = (1 << 12),
82  kFinderFlagStationery = (1 << 11),
83  kFinderFlagCustomIcon = (1 << 10),
84  kFinderFlagInited = (1 << 8),
85  kFinderFlagNoInit = (1 << 7),
86  kFinderFlagShared = (1 << 6),
87 
88  kFinderFlagColorBit2 = (1 << 3),
89  kFinderFlagColorBit1 = (1 << 2),
90  kFinderFlagColorBit0 = (1 << 1),
91  };
92 
93  MacFinderInfo();
94  explicit MacFinderInfo(const MacFinderInfoData &data);
95 
96  MacFinderInfoData toData() const;
97 
98  byte type[4];
99  byte creator[4];
100  uint16 flags;
101  Common::Point position;
102  int16 windowID;
103 };
104 
109  static const uint kDataSize = 16;
110 
112  explicit MacFinderExtendedInfo(const MacFinderExtendedInfoData &data);
113 
114  MacFinderExtendedInfoData toData() const;
115 
116  int16 iconID;
117  int16 commentID;
118  int32 homeDirectoryID;
119 };
120 
126 
127 #define MBI_INFOHDR 128
128 
129 public:
130  MacResManager();
131  ~MacResManager();
132 
143  bool open(const Path &fileName);
144 
153  bool open(const Path &fileName, Archive &archive);
154 
159  static SeekableReadStream *openFileOrDataFork(const Path &fileName, Archive &archive);
160  static SeekableReadStream *openFileOrDataFork(const Path &fileName);
161 
166  static SeekableReadStream *openDataForkFromMacBinary(SeekableReadStream *inStream, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO);
167 
173  static bool exists(const Path &fileName);
174 
183  static bool getFileFinderInfo(const Path &fileName, Archive &archive, MacFinderInfo &outFinderInfo);
184  static bool getFileFinderInfo(const Path &fileName, Archive &archive, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
185  static bool getFileFinderInfo(const Path &fileName, MacFinderInfo &outFinderInfo);
186  static bool getFileFinderInfo(const Path &fileName, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
187 
196  static void listFiles(Array<Path> &files, const Path &pattern);
197 
201  void close();
202 
207  bool hasResFork() const;
208 
215  SeekableReadStream *getResource(uint32 typeID, uint16 resID);
216 
223  SeekableReadStream *getResource(const String &filename);
224 
231  SeekableReadStream *getResource(uint32 typeID, const String &filename);
232 
233  static int getDataForkOffset() { return MBI_INFOHDR; }
234 
241  String getResName(uint32 typeID, uint16 resID) const;
242 
249  uint32 getResLength(uint32 typeID, uint16 resID);
250 
255  uint32 getResForkDataSize() const;
256 
263  String computeResForkMD5AsString(uint32 length = 0, bool tail = false) const;
264 
269  Path getBaseFileName() const { return _baseFileName; }
270 
271  void setBaseFileName(Common::Path str) { _baseFileName = str; }
272 
276  MacResIDArray getResIDArray(uint32 typeID);
277 
281  MacResTagArray getResTagArray();
282 
286  bool loadFromMacBinary(SeekableReadStream *stream);
287 
291  void dumpRaw();
292 
297  static bool isMacBinary(SeekableReadStream &stream);
298 
299  struct MacVers {
300  byte majorVer;
301  byte minorVer;
302  byte devStage;
303  String devStr;
304  byte preReleaseVer;
305  uint16 region;
306  String str;
307  String msg;
308  };
309  static MacVers *parseVers(SeekableReadStream *vvers);
310 
311 private:
312  SeekableReadStream *_stream;
313  Path _baseFileName;
314 
315  bool load(SeekableReadStream *stream);
316 
317  bool loadFromRawFork(SeekableReadStream *stream);
318  bool loadFromAppleDouble(SeekableReadStream *stream);
319 
323  static bool getFinderInfoFromMacBinary(SeekableReadStream *stream, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
324 
328  static bool getFinderInfoFromAppleDouble(SeekableReadStream *stream, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
329 
330  static bool readAndValidateMacBinaryHeader(SeekableReadStream &stream, byte (&outMacBinaryHeader)[MBI_INFOHDR]);
331 
332  static Path constructAppleDoubleName(const Path &name);
333  static Path disassembleAppleDoubleName(const Path &name, bool *isAppleDouble);
334 
335  static SeekableReadStream *openAppleDoubleWithAppleOrOSXNaming(Archive& archive, const Path &fileName);
336 
342  static bool isRawFork(SeekableReadStream &stream);
343 
344  enum {
345  kResForkNone = 0,
346  kResForkRaw,
347  kResForkMacBinary,
348  kResForkAppleDouble
349  } _mode;
350 
351  void readMap();
352 
353  struct ResMap {
354  uint16 resAttr;
355  uint16 typeOffset;
356  uint16 nameOffset;
357  uint16 numTypes;
358 
359  void reset() {
360  resAttr = 0;
361  typeOffset = 0;
362  nameOffset = 0;
363  numTypes = 0;
364  }
365 
366  ResMap() { reset(); }
367  };
368 
369  struct ResType {
370  uint32 id;
371  uint16 items;
372  uint16 offset;
373  };
374 
375  struct Resource {
376  uint16 id;
377  int16 nameOffset;
378  byte attr;
379  uint32 dataOffset;
380  char *name;
381  };
382 
383  typedef Resource *ResPtr;
384 
385  int32 _resForkOffset;
386  uint32 _resForkSize;
387 
388  uint32 _dataOffset;
389  uint32 _dataLength;
390  uint32 _mapOffset;
391  uint32 _mapLength;
392  ResMap _resMap;
393  ResType *_resTypes;
394  ResPtr *_resLists;
395 };
396 
399 } // End of namespace Common
400 
401 #endif
Definition: macresman.h:125
Definition: str.h:59
Definition: array.h:52
Path getBaseFileName() const
Definition: macresman.h:269
Definition: path.h:52
Definition: stream.h:745
Definition: archive.h:141
Definition: macresman.h:76
Definition: macresman.h:299
Definition: macresman.h:108
Definition: algorithm.h:29
Definition: rect.h:45
Definition: macresman.h:62
Definition: macresman.h:69