[Scummvm-cvs-logs] SF.net SVN: scummvm:[49074] scummvm/trunk/common
sev at users.sourceforge.net
sev at users.sourceforge.net
Tue May 18 12:39:09 CEST 2010
Revision: 49074
http://scummvm.svn.sourceforge.net/scummvm/?rev=49074&view=rev
Author: sev
Date: 2010-05-18 10:39:08 +0000 (Tue, 18 May 2010)
Log Message:
-----------
Added getBaseFileName() method and enhanced open() with trying macbinary format in plain files
Modified Paths:
--------------
scummvm/trunk/common/macresman.cpp
scummvm/trunk/common/macresman.h
Modified: scummvm/trunk/common/macresman.cpp
===================================================================
--- scummvm/trunk/common/macresman.cpp 2010-05-18 10:01:31 UTC (rev 49073)
+++ scummvm/trunk/common/macresman.cpp 2010-05-18 10:39:08 UTC (rev 49074)
@@ -135,7 +135,13 @@
// Fine, what about just the data fork?
if (file->open(filename)) {
_baseFileName = filename;
- _stream = file;
+
+ if (isMacBinary(*file)) {
+ file->seek(0, SEEK_SET);
+ loadFromMacBinary(*file);
+ } else {
+ _stream = file;
+ }
return true;
}
@@ -184,7 +190,12 @@
fsNode = path.getChild(filename);
if (fsNode.exists() && !fsNode.isDirectory()) {
_baseFileName = filename;
- _stream = fsNode.createReadStream();
+
+ if (isMacBinary(*fsNode.createReadStream())) {
+ loadFromMacBinary(*fsNode.createReadStream());
+ } else {
+ _stream = fsNode.createReadStream();
+ }
return true;
}
@@ -217,6 +228,34 @@
return false;
}
+bool MacResManager::isMacBinary(Common::SeekableReadStream &stream) {
+ byte infoHeader[MBI_INFOHDR];
+ int resForkOffset = -1;
+
+ stream.read(infoHeader, MBI_INFOHDR);
+
+ if (infoHeader[MBI_ZERO1] == 0 && infoHeader[MBI_ZERO2] == 0 &&
+ infoHeader[MBI_ZERO3] == 0 && infoHeader[MBI_NAMELEN] <= MAXNAMELEN) {
+
+ // Pull out fork lengths
+ uint32 dataSize = READ_BE_UINT32(infoHeader + MBI_DFLEN);
+ uint32 rsrcSize = READ_BE_UINT32(infoHeader + MBI_RFLEN);
+
+ uint32 dataSizePad = (((dataSize + 127) >> 7) << 7);
+ uint32 rsrcSizePad = (((rsrcSize + 127) >> 7) << 7);
+
+ // Length check
+ if (MBI_INFOHDR + dataSizePad + rsrcSizePad == (uint32)stream.size()) {
+ resForkOffset = MBI_INFOHDR + dataSizePad;
+ }
+ }
+
+ if (resForkOffset < 0)
+ return false;
+
+ return true;
+}
+
bool MacResManager::loadFromMacBinary(Common::SeekableReadStream &stream) {
byte infoHeader[MBI_INFOHDR];
stream.read(infoHeader, MBI_INFOHDR);
Modified: scummvm/trunk/common/macresman.h
===================================================================
--- scummvm/trunk/common/macresman.h 2010-05-18 10:01:31 UTC (rev 49073)
+++ scummvm/trunk/common/macresman.h 2010-05-18 10:39:08 UTC (rev 49074)
@@ -53,6 +53,8 @@
bool hasDataFork();
bool hasResFork();
+ bool isMacBinary(Common::SeekableReadStream &stream);
+
/**
* Read resource from the Mac Binary file
* @param typeID FourCC with type ID
@@ -72,6 +74,8 @@
Common::String getResName(uint32 typeID, uint16 resID);
uint32 getResForkSize();
bool getResForkMD5(char *md5str, uint32 length);
+
+ Common::String getBaseFileName() { return _baseFileName; }
/**
* Convert cursor from crsr format to format suitable for feeding to CursorMan
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list