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 
304  String getOriginalFileName() const { return _originalFileName; }
305 
309  MacResIDArray getResIDArray(uint32 typeID);
310 
314  MacResTagArray getResTagArray();
315 
319  bool loadFromMacBinary(SeekableReadStream *stream);
320 
324  void dumpRaw();
325 
330  static bool isMacBinary(SeekableReadStream &stream);
331 
332  struct MacVers {
333  byte majorVer;
334  byte minorVer;
335  byte devStage;
336  String devStr;
337  byte preReleaseVer;
338  uint16 region;
339  String str;
340  String msg;
341  };
342  static MacVers *parseVers(SeekableReadStream *vvers);
343 
344  enum {
345  kResForkNone = 0,
346  kResForkRaw,
347  kResForkMacBinary,
348  kResForkAppleDouble
349  } _mode;
350 
351  static Path constructAppleDoubleName(const Path &name);
352 
353 private:
354  SeekableReadStream *_stream;
355  Path _baseFileName;
356  String _originalFileName;
357 
358  bool load(SeekableReadStream *stream);
359 
360  bool loadFromRawFork(SeekableReadStream *stream);
361  bool loadFromAppleDouble(SeekableReadStream *stream);
362 
366  static bool getFinderInfoFromMacBinary(SeekableReadStream *stream, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
367 
371  static bool getFinderInfoFromAppleDouble(SeekableReadStream *stream, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
372 
373  static bool readAndValidateMacBinaryHeader(SeekableReadStream &stream, byte (&outMacBinaryHeader)[MBI_INFOHDR]);
374 
375  static Path disassembleAppleDoubleName(const Path &name, bool *isAppleDouble);
376 
377  static SeekableReadStream *openAppleDoubleWithAppleOrOSXNaming(Archive& archive, const Path &fileName);
378 
384  static bool isRawFork(SeekableReadStream &stream);
385 
386  void readMap();
387 
388  struct ResMap {
389  uint16 resAttr;
390  uint16 typeOffset;
391  uint16 nameOffset;
392  uint16 numTypes;
393 
394  void reset() {
395  resAttr = 0;
396  typeOffset = 0;
397  nameOffset = 0;
398  numTypes = 0;
399  }
400 
401  ResMap() { reset(); }
402  };
403 
404  struct ResType {
405  uint32 id;
406  uint16 items;
407  uint16 offset;
408  };
409 
410  struct Resource {
411  uint16 id;
412  int16 nameOffset;
413  byte attr;
414  uint32 dataOffset;
415  char *name;
416  };
417 
418  typedef Resource *ResPtr;
419 
420  int32 _resForkOffset;
421  uint32 _resForkSize;
422 
423  uint32 _dataOffset;
424  uint32 _dataLength;
425  uint32 _mapOffset;
426  uint32 _mapLength;
427  ResMap _resMap;
428  ResType *_resTypes;
429  ResPtr *_resLists;
430 };
431 
434 } // End of namespace Common
435 
436 #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:332
Definition: macresman.h:109
Definition: algorithm.h:29
Definition: rect.h:144
Definition: macresman.h:63
String getOriginalFileName() const
Definition: macresman.h:304
Definition: macresman.h:70