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 typedef bool (* ProgressUpdateCallback)(void *, int);
59 
64  byte data[16];
65 };
66 
71  byte data[16];
72 };
73 
77 struct MacFinderInfo {
78  enum FinderFlags {
79  kFinderFlagAlias = (1 << 15),
80  kFinderFlagInvisible = (1 << 14),
81  kFinderFlagBundle = (1 << 13),
82  kFinderFlagNameLocked = (1 << 12),
83  kFinderFlagStationery = (1 << 11),
84  kFinderFlagCustomIcon = (1 << 10),
85  kFinderFlagInited = (1 << 8),
86  kFinderFlagNoInit = (1 << 7),
87  kFinderFlagShared = (1 << 6),
88 
89  kFinderFlagColorBit2 = (1 << 3),
90  kFinderFlagColorBit1 = (1 << 2),
91  kFinderFlagColorBit0 = (1 << 1),
92  };
93 
94  MacFinderInfo();
95  explicit MacFinderInfo(const MacFinderInfoData &data);
96 
97  MacFinderInfoData toData() const;
98 
99  byte type[4];
100  byte creator[4];
101  uint16 flags;
102  Common::Point position;
103  int16 windowID;
104 };
105 
110  static const uint kDataSize = 16;
111 
113  explicit MacFinderExtendedInfo(const MacFinderExtendedInfoData &data);
114 
115  MacFinderExtendedInfoData toData() const;
116 
117  int16 iconID;
118  int16 commentID;
119  int32 homeDirectoryID;
120 };
121 
127 
128 #define MBI_INFOHDR 128
129 
130 public:
131  MacResManager();
132  ~MacResManager();
133 
144  bool open(const Path &fileName);
145 
154  bool open(const Path &fileName, Archive &archive);
155 
160  static SeekableReadStream *openFileOrDataFork(const Path &fileName, Archive &archive);
161  static SeekableReadStream *openFileOrDataFork(const Path &fileName);
162 
167  static SeekableReadStream *openDataForkFromMacBinary(SeekableReadStream *inStream, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO);
168 
174  static bool exists(const Path &fileName);
175 
184  static bool getFileFinderInfo(const Path &fileName, Archive &archive, MacFinderInfo &outFinderInfo);
185  static bool getFileFinderInfo(const Path &fileName, Archive &archive, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
186  static bool getFileFinderInfo(const Path &fileName, MacFinderInfo &outFinderInfo);
187  static bool getFileFinderInfo(const Path &fileName, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
188 
197  static void listFiles(Array<Path> &files, const Path &pattern);
198 
202  void close();
203 
208  bool hasResFork() const;
209 
214  bool hasDataFork() const;
215 
220  bool isMacFile() const { return _mode != kResForkNone; }
221 
222  int getMode() const { return _mode; }
223 
230  SeekableReadStream *getResource(uint32 typeID, uint16 resID);
231 
238  SeekableReadStream *getResource(const String &filename);
239 
246  SeekableReadStream *getResource(uint32 typeID, const String &filename);
247 
248  static int getDataForkOffset() { return MBI_INFOHDR; }
249 
256  String getResName(uint32 typeID, uint16 resID) const;
257 
264  uint32 getResLength(uint32 typeID, uint16 resID);
265 
270  uint32 getResForkDataSize() const;
271 
272  uint32 getResForkSize() const {
273  if (!hasResFork())
274  return 0;
275  return _resForkSize;
276  }
277 
278  uint32 getDataForkSize() const {
279  if (!hasDataFork())
280  return 0;
281  return _dataLength;
282  }
283 
290  String computeResForkMD5AsString(uint32 length = 0, bool tail = false, ProgressUpdateCallback progressUpdateCallback = nullptr, void *callbackParameter = nullptr) const;
291 
296  Path getBaseFileName() const { return _baseFileName; }
297 
298  void setBaseFileName(Common::Path str) { _baseFileName = str; }
299 
303  MacResIDArray getResIDArray(uint32 typeID);
304 
308  MacResTagArray getResTagArray();
309 
313  bool loadFromMacBinary(SeekableReadStream *stream);
314 
318  void dumpRaw();
319 
324  static bool isMacBinary(SeekableReadStream &stream);
325 
326  struct MacVers {
327  byte majorVer;
328  byte minorVer;
329  byte devStage;
330  String devStr;
331  byte preReleaseVer;
332  uint16 region;
333  String str;
334  String msg;
335  };
336  static MacVers *parseVers(SeekableReadStream *vvers);
337 
338  enum {
339  kResForkNone = 0,
340  kResForkRaw,
341  kResForkMacBinary,
342  kResForkAppleDouble
343  } _mode;
344 
345  static Path constructAppleDoubleName(const Path &name);
346 
347 private:
348  SeekableReadStream *_stream;
349  Path _baseFileName;
350 
351  bool load(SeekableReadStream *stream);
352 
353  bool loadFromRawFork(SeekableReadStream *stream);
354  bool loadFromAppleDouble(SeekableReadStream *stream);
355 
359  static bool getFinderInfoFromMacBinary(SeekableReadStream *stream, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
360 
364  static bool getFinderInfoFromAppleDouble(SeekableReadStream *stream, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
365 
366  static bool readAndValidateMacBinaryHeader(SeekableReadStream &stream, byte (&outMacBinaryHeader)[MBI_INFOHDR]);
367 
368  static Path disassembleAppleDoubleName(const Path &name, bool *isAppleDouble);
369 
370  static SeekableReadStream *openAppleDoubleWithAppleOrOSXNaming(Archive& archive, const Path &fileName);
371 
377  static bool isRawFork(SeekableReadStream &stream);
378 
379  void readMap();
380 
381  struct ResMap {
382  uint16 resAttr;
383  uint16 typeOffset;
384  uint16 nameOffset;
385  uint16 numTypes;
386 
387  void reset() {
388  resAttr = 0;
389  typeOffset = 0;
390  nameOffset = 0;
391  numTypes = 0;
392  }
393 
394  ResMap() { reset(); }
395  };
396 
397  struct ResType {
398  uint32 id;
399  uint16 items;
400  uint16 offset;
401  };
402 
403  struct Resource {
404  uint16 id;
405  int16 nameOffset;
406  byte attr;
407  uint32 dataOffset;
408  char *name;
409  };
410 
411  typedef Resource *ResPtr;
412 
413  int32 _resForkOffset;
414  uint32 _resForkSize;
415 
416  uint32 _dataOffset;
417  uint32 _dataLength;
418  uint32 _mapOffset;
419  uint32 _mapLength;
420  ResMap _resMap;
421  ResType *_resTypes;
422  ResPtr *_resLists;
423 };
424 
427 } // End of namespace Common
428 
429 #endif
Definition: macresman.h:126
Definition: str.h:59
Definition: array.h:52
Path getBaseFileName() const
Definition: macresman.h:296
Definition: path.h:52
Definition: stream.h:745
Definition: archive.h:141
Definition: macresman.h:77
bool isMacFile() const
Definition: macresman.h:220
Definition: macresman.h:326
Definition: macresman.h:109
Definition: algorithm.h:29
Definition: rect.h:144
Definition: macresman.h:63
Definition: macresman.h:70