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
36namespace Common {
37
56typedef Array<uint16> MacResIDArray;
57typedef Array<uint32> MacResTagArray;
58typedef bool (* ProgressUpdateCallback)(void *, int);
59
64 byte data[16];
65};
66
71 byte data[16];
72};
73
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
95 explicit MacFinderInfo(const MacFinderInfoData &data);
96
97 MacFinderInfoData toData() const;
98
99 uint32 type;
100 uint32 creator;
101 uint16 flags;
102 Common::Point position;
103 int16 windowID;
104};
105
110 static const uint kDataSize = 16;
111
114
115 MacFinderExtendedInfoData toData() const;
116
117 int16 iconID;
118 int16 commentID;
119 int32 homeDirectoryID;
120};
121
127
128#define MBI_INFOHDR 128
129
130public:
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
172 static void writeMacBinary(SeekableWriteStream *outStream, SeekableReadStream *dataFork, SeekableReadStream *resourceFork, const Common::String &name, const MacFinderInfo &info, TimeDate *created = nullptr, TimeDate *modified = nullptr);
173
179 static bool exists(const Path &fileName);
180
189 static bool getFileFinderInfo(const Path &fileName, Archive &archive, MacFinderInfo &outFinderInfo);
190 static bool getFileFinderInfo(const Path &fileName, Archive &archive, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
191 static bool getFileFinderInfo(const Path &fileName, MacFinderInfo &outFinderInfo);
192 static bool getFileFinderInfo(const Path &fileName, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
193
202 static void listFiles(Array<Path> &files, const Path &pattern);
203
207 void close();
208
213 bool hasResFork() const;
214
219 bool hasDataFork() const;
220
225 bool isMacFile() const { return _mode != kResForkNone; }
226
227 int getMode() const { return _mode; }
228
235 SeekableReadStream *getResource(uint32 typeID, uint16 resID);
236
244
251 SeekableReadStream *getResource(uint32 typeID, const String &filename);
252
253 static int getDataForkOffset() { return MBI_INFOHDR; }
254
261 String getResName(uint32 typeID, uint16 resID) const;
262
269 uint32 getResLength(uint32 typeID, uint16 resID);
270
277 uint16 getResID(uint32 typeID, const Common::String &filename);
278
283 uint32 getResForkDataSize() const;
284
285 uint32 getResForkSize() const {
286 if (!hasResFork())
287 return 0;
288 return _resForkSize;
289 }
290
291 uint32 getDataForkSize() const {
292 if (!hasDataFork())
293 return 0;
294 return _dataLength;
295 }
296
303 String computeResForkMD5AsString(uint32 length = 0, bool tail = false, ProgressUpdateCallback progressUpdateCallback = nullptr, void *callbackParameter = nullptr) const;
304
309 Path getBaseFileName() const { return _baseFileName; }
310
311 void setBaseFileName(Common::Path str) { _baseFileName = str; }
312
317 String getOriginalFileName() const { return _originalFileName; }
318
323
328
333
337 void dumpRaw();
338
343 static bool isMacBinary(SeekableReadStream &stream);
344
345 struct MacVers {
346 byte majorVer;
347 byte minorVer;
348 byte devStage;
349 String devStr;
350 byte preReleaseVer;
351 uint16 region;
352 String str;
353 String msg;
354 };
355 static MacVers *parseVers(SeekableReadStream *vvers);
356
357 enum {
358 kResForkNone = 0,
359 kResForkRaw,
360 kResForkMacBinary,
361 kResForkAppleDouble
362 } _mode;
363
364 static Path constructAppleDoubleName(const Path &name);
365
366private:
367 SeekableReadStream *_stream;
368 Path _baseFileName;
369 String _originalFileName;
370
371 bool load(SeekableReadStream *stream);
372
373 bool loadFromRawFork(SeekableReadStream *stream);
374 bool loadFromAppleDouble(SeekableReadStream *stream);
375
376public:
380 static bool getFinderInfoFromMacBinary(SeekableReadStream *stream, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
381
382private:
386 static bool getFinderInfoFromAppleDouble(SeekableReadStream *stream, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo);
387
388 static bool readAndValidateMacBinaryHeader(SeekableReadStream &stream, byte (&outMacBinaryHeader)[MBI_INFOHDR]);
389
390 static Path disassembleAppleDoubleName(const Path &name, bool *isAppleDouble);
391
392 static SeekableReadStream *openAppleDoubleWithAppleOrOSXNaming(Archive& archive, const Path &fileName);
393
399 static bool isRawFork(SeekableReadStream &stream);
400
401 void readMap();
402
403 struct ResMap {
404 uint16 resAttr;
405 uint16 typeOffset;
406 uint16 nameOffset;
407 uint16 numTypes;
408
409 void reset() {
410 resAttr = 0;
411 typeOffset = 0;
412 nameOffset = 0;
413 numTypes = 0;
414 }
415
416 ResMap() { reset(); }
417 };
418
419 struct ResType {
420 uint32 id;
421 uint16 items;
422 uint16 offset;
423 };
424
425 struct Resource {
426 uint16 id;
427 int16 nameOffset;
428 byte attr;
429 uint32 dataOffset;
430 char *name;
431 };
432
433 typedef Resource *ResPtr;
434
435 int32 _resForkOffset;
436 uint32 _resForkSize;
437
438 uint32 _dataOffset;
439 uint32 _dataLength;
440 uint32 _mapOffset;
441 uint32 _mapLength;
442 ResMap _resMap;
443 ResType *_resTypes;
444 ResPtr *_resLists;
445};
446
449} // End of namespace Common
450
451#endif
Definition: archive.h:141
Definition: array.h:52
Definition: macresman.h:126
uint32 getResLength(uint32 typeID, uint16 resID)
MacResTagArray getResTagArray()
SeekableReadStream * getResource(uint32 typeID, uint16 resID)
static bool getFinderInfoFromMacBinary(SeekableReadStream *stream, MacFinderInfo &outFinderInfo, MacFinderExtendedInfo &outFinderExtendedInfo)
SeekableReadStream * getResource(const String &filename)
static bool isMacBinary(SeekableReadStream &stream)
Path getBaseFileName() const
Definition: macresman.h:309
uint16 getResID(uint32 typeID, const Common::String &filename)
static void listFiles(Array< Path > &files, const Path &pattern)
MacResIDArray getResIDArray(uint32 typeID)
bool open(const Path &fileName, Archive &archive)
bool isMacFile() const
Definition: macresman.h:225
bool loadFromMacBinary(SeekableReadStream *stream)
String getOriginalFileName() const
Definition: macresman.h:317
String computeResForkMD5AsString(uint32 length=0, bool tail=false, ProgressUpdateCallback progressUpdateCallback=nullptr, void *callbackParameter=nullptr) const
uint32 getResForkDataSize() const
bool open(const Path &fileName)
SeekableReadStream * getResource(uint32 typeID, const String &filename)
bool hasResFork() const
static SeekableReadStream * openDataForkFromMacBinary(SeekableReadStream *inStream, DisposeAfterUse::Flag disposeAfterUse=DisposeAfterUse::NO)
static bool exists(const Path &fileName)
static bool getFileFinderInfo(const Path &fileName, Archive &archive, MacFinderInfo &outFinderInfo)
static SeekableReadStream * openFileOrDataFork(const Path &fileName, Archive &archive)
String getResName(uint32 typeID, uint16 resID) const
static void writeMacBinary(SeekableWriteStream *outStream, SeekableReadStream *dataFork, SeekableReadStream *resourceFork, const Common::String &name, const MacFinderInfo &info, TimeDate *created=nullptr, TimeDate *modified=nullptr)
bool hasDataFork() const
Definition: path.h:52
Definition: stream.h:745
Definition: stream.h:351
Definition: str.h:59
Definition: algorithm.h:29
Definition: macresman.h:70
Definition: macresman.h:109
Definition: macresman.h:63
Definition: macresman.h:77
Definition: macresman.h:345
Definition: rect.h:144
Definition: system.h:111