[Scummvm-cvs-logs] scummvm master -> b6a8907edf0d604aa37300f4d1485d8d6e542994

lordhoto lordhoto at gmail.com
Tue Mar 1 19:29:14 CET 2016


This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
1ae2e0594d SCI: Use MacResManager when checking for Mac resource forks.
91b5c5a413 COMMON: Add a method to list files to MacResManager.
fd5799aa19 SCI: Fix Macintosh game sources listing.
b8fb9e6a51 COMMON: Cleanup: Use StringArray instead of custom type.
b6a8907edf SCI: Cleanup: Use Common::StringArray instead of custom type.


Commit: 1ae2e0594d45a43c5502e3b8e8b68aec26b64d7f
    https://github.com/scummvm/scummvm/commit/1ae2e0594d45a43c5502e3b8e8b68aec26b64d7f
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2016-03-01T19:16:10+01:00

Commit Message:
SCI: Use MacResManager when checking for Mac resource forks.

Changed paths:
    engines/sci/resource.cpp



diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 42afa68..578a8cb 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -596,7 +596,7 @@ int ResourceManager::addAppropriateSources() {
 
 #ifdef ENABLE_SCI32
 		// There can also be a "Patches" resource fork with patches
-		if (Common::File::exists("Patches"))
+		if (Common::MacResManager::exists("Patches"))
 			addSource(new MacResourceForkResourceSource("Patches", 100));
 	} else {
 		// SCI2.1-SCI3 file naming scheme


Commit: 91b5c5a413af1e2a61d3f8457deff54a75a8d754
    https://github.com/scummvm/scummvm/commit/91b5c5a413af1e2a61d3f8457deff54a75a8d754
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2016-03-01T19:16:10+01:00

Commit Message:
COMMON: Add a method to list files to MacResManager.

Changed paths:
    common/macresman.cpp
    common/macresman.h



diff --git a/common/macresman.cpp b/common/macresman.cpp
index d83bde8..e28bd96 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -29,6 +29,7 @@
 #include "common/md5.h"
 #include "common/substream.h"
 #include "common/textconsole.h"
+#include "common/archive.h"
 
 #ifdef MACOSX
 #include "common/config-manager.h"
@@ -261,6 +262,76 @@ bool MacResManager::exists(const String &fileName) {
 	return false;
 }
 
+void MacResManager::listFiles(Array<String> &files, const String &pattern) {
+	// Base names discovered so far.
+	typedef HashMap<String, bool, IgnoreCase_Hash, IgnoreCase_EqualTo> BaseNameSet;
+	BaseNameSet baseNames;
+
+	// List files itself.
+	ArchiveMemberList memberList;
+	SearchMan.listMatchingMembers(memberList, pattern);
+	SearchMan.listMatchingMembers(memberList, pattern + ".rsrc");
+	SearchMan.listMatchingMembers(memberList, pattern + ".bin");
+	SearchMan.listMatchingMembers(memberList, constructAppleDoubleName(pattern));
+
+	for (ArchiveMemberList::const_iterator i = memberList.begin(), end = memberList.end(); i != end; ++i) {
+		String filename = (*i)->getName();
+
+		// For raw resource forks and MacBinary files we strip the extension
+		// here to obtain a valid base name.
+		int lastDotPos = filename.size() - 1;
+		for (; lastDotPos >= 0; --lastDotPos) {
+			if (filename[lastDotPos] == '.') {
+				break;
+			}
+		}
+
+		if (lastDotPos != -1) {
+			const char *extension = filename.c_str() + lastDotPos + 1;
+			bool removeExtension = false;
+
+			// TODO: Should we really keep filenames suggesting raw resource
+			// forks or MacBinary files but not being such around? This might
+			// depend on the pattern the client requests...
+			if (!scumm_stricmp(extension, "rsrc")) {
+				SeekableReadStream *stream = (*i)->createReadStream();
+				removeExtension = stream && isRawFork(*stream);
+				delete stream;
+			} else if (!scumm_stricmp(extension, "bin")) {
+				SeekableReadStream *stream = (*i)->createReadStream();
+				removeExtension = stream && isMacBinary(*stream);
+				delete stream;
+			}
+
+			if (removeExtension) {
+				filename.erase(lastDotPos);
+			}
+		}
+
+		// Strip AppleDouble '._' prefix if applicable.
+		bool isAppleDoubleName = false;
+		const String filenameAppleDoubleStripped = disassembleAppleDoubleName(filename, &isAppleDoubleName);
+
+		if (isAppleDoubleName) {
+			SeekableReadStream *stream = (*i)->createReadStream();
+			if (stream->readUint32BE() == 0x00051607) {
+				filename = filenameAppleDoubleStripped;
+			}
+			// TODO: Should we really keep filenames suggesting AppleDouble
+			// but not being AppleDouble around? This might depend on the
+			// pattern the client requests...
+			delete stream;
+		}
+
+		baseNames[filename] = true;
+	}
+
+	// Append resulting base names to list to indicate found files.
+	for (BaseNameSet::const_iterator i = baseNames.begin(), end = baseNames.end(); i != end; ++i) {
+		files.push_back(i->_key);
+	}
+}
+
 bool MacResManager::loadFromAppleDouble(SeekableReadStream &stream) {
 	if (stream.readUint32BE() != 0x00051607) // tag
 		return false;
@@ -314,6 +385,18 @@ bool MacResManager::isMacBinary(SeekableReadStream &stream) {
 	return true;
 }
 
+bool MacResManager::isRawFork(SeekableReadStream &stream) {
+	// TODO: Is there a better way to detect whether this is a raw fork?
+	const uint32 dataOffset = stream.readUint32BE();
+	const uint32 mapOffset = stream.readUint32BE();
+	const uint32 dataLength = stream.readUint32BE();
+	const uint32 mapLength = stream.readUint32BE();
+
+	return    !stream.eos() && !stream.err()
+	       && dataOffset < (uint32)stream.size() && dataOffset + dataLength <= (uint32)stream.size()
+	       && mapOffset < (uint32)stream.size() && mapOffset + mapLength <= (uint32)stream.size();
+}
+
 bool MacResManager::loadFromMacBinary(SeekableReadStream &stream) {
 	byte infoHeader[MBI_INFOHDR];
 	stream.read(infoHeader, MBI_INFOHDR);
@@ -592,4 +675,32 @@ String MacResManager::constructAppleDoubleName(String name) {
 	return name;
 }
 
+String MacResManager::disassembleAppleDoubleName(String name, bool *isAppleDouble) {
+	if (isAppleDouble) {
+		*isAppleDouble = false;
+	}
+
+	// Remove "._" before the last portion of a path name.
+	for (int i = name.size() - 1; i >= 0; --i) {
+		if (i == 0) {
+			if (name.size() > 2 && name[0] == '.' && name[1] == '_') {
+				name.erase(0, 2);
+				if (isAppleDouble) {
+					*isAppleDouble = true;
+				}
+			}
+		} else if (name[i] == '/') {
+			if ((uint)(i + 2) < name.size() && name[i + 1] == '.' && name[i + 2] == '_') {
+				name.erase(i + 1, 2);
+				if (isAppleDouble) {
+					*isAppleDouble = true;
+				}
+			}
+			break;
+		}
+	}
+
+	return name;
+}
+
 } // End of namespace Common
diff --git a/common/macresman.h b/common/macresman.h
index 43ec8d8..5cc2542 100644
--- a/common/macresman.h
+++ b/common/macresman.h
@@ -82,6 +82,16 @@ public:
 	static bool exists(const String &fileName);
 
 	/**
+	 * List all filenames matching pattern for opening with open().
+	 *
+	 * @param files Array containing all matching filenames discovered. Only
+	 *              adds to the list.
+	 * @param pattern Pattern to match against. Taking String::matchPattern's
+	 *                format.
+	 */
+	static void listFiles(Array<String> &files, const String &pattern);
+
+	/**
 	 * Close the Mac data/resource fork pair.
 	 */
 	void close();
@@ -176,6 +186,7 @@ private:
 	bool loadFromAppleDouble(SeekableReadStream &stream);
 
 	static String constructAppleDoubleName(String name);
+	static String disassembleAppleDoubleName(String name, bool *isAppleDouble);
 
 	/**
 	 * Check if the given stream is in the MacBinary format.
@@ -183,6 +194,13 @@ private:
 	 */
 	static bool isMacBinary(SeekableReadStream &stream);
 
+	/**
+	 * Do a sanity check whether the given stream is a raw resource fork.
+	 *
+	 * @param stream Stream object to check. Will not preserve its position.
+	 */
+	static bool isRawFork(SeekableReadStream &stream);
+
 	enum {
 		kResForkNone = 0,
 		kResForkRaw,


Commit: fd5799aa194f2a81cc79075c7a42586d0d5b2693
    https://github.com/scummvm/scummvm/commit/fd5799aa194f2a81cc79075c7a42586d0d5b2693
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2016-03-01T19:16:10+01:00

Commit Message:
SCI: Fix Macintosh game sources listing.

Changed paths:
    engines/sci/resource.cpp



diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 578a8cb..7fb09fe 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -565,12 +565,11 @@ Resource *ResourceManager::testResource(ResourceId id) {
 }
 
 int ResourceManager::addAppropriateSources() {
-	Common::ArchiveMemberList files;
-
 	if (Common::File::exists("resource.map")) {
 		// SCI0-SCI2 file naming scheme
 		ResourceSource *map = addExternalMap("resource.map");
 
+		Common::ArchiveMemberList files;
 		SearchMan.listMatchingMembers(files, "resource.0??");
 
 		for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) {
@@ -587,11 +586,11 @@ int ResourceManager::addAppropriateSources() {
 #endif
 	} else if (Common::MacResManager::exists("Data1")) {
 		// Mac SCI1.1+ file naming scheme
-		SearchMan.listMatchingMembers(files, "Data?*");
+		Common::Array<Common::String> files;
+		Common::MacResManager::listFiles(files, "Data?");
 
-		for (Common::ArchiveMemberList::const_iterator x = files.begin(); x != files.end(); ++x) {
-			Common::String filename = (*x)->getName();
-			addSource(new MacResourceForkResourceSource(filename, atoi(filename.c_str() + 4)));
+		for (Common::Array<Common::String>::const_iterator x = files.begin(); x != files.end(); ++x) {
+			addSource(new MacResourceForkResourceSource(*x, atoi(x->c_str() + 4)));
 		}
 
 #ifdef ENABLE_SCI32
@@ -600,7 +599,7 @@ int ResourceManager::addAppropriateSources() {
 			addSource(new MacResourceForkResourceSource("Patches", 100));
 	} else {
 		// SCI2.1-SCI3 file naming scheme
-		Common::ArchiveMemberList mapFiles;
+		Common::ArchiveMemberList mapFiles, files;
 		SearchMan.listMatchingMembers(mapFiles, "resmap.0??");
 		SearchMan.listMatchingMembers(files, "ressci.0??");
 


Commit: b8fb9e6a51606aa674c4897dddad6c0922e5137d
    https://github.com/scummvm/scummvm/commit/b8fb9e6a51606aa674c4897dddad6c0922e5137d
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2016-03-01T19:18:23+01:00

Commit Message:
COMMON: Cleanup: Use StringArray instead of custom type.

Changed paths:
    common/macresman.cpp
    common/macresman.h



diff --git a/common/macresman.cpp b/common/macresman.cpp
index e28bd96..adca1ea 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -262,7 +262,7 @@ bool MacResManager::exists(const String &fileName) {
 	return false;
 }
 
-void MacResManager::listFiles(Array<String> &files, const String &pattern) {
+void MacResManager::listFiles(StringArray &files, const String &pattern) {
 	// Base names discovered so far.
 	typedef HashMap<String, bool, IgnoreCase_Hash, IgnoreCase_EqualTo> BaseNameSet;
 	BaseNameSet baseNames;
diff --git a/common/macresman.h b/common/macresman.h
index 5cc2542..05b2a87 100644
--- a/common/macresman.h
+++ b/common/macresman.h
@@ -33,6 +33,7 @@
 #include "common/array.h"
 #include "common/fs.h"
 #include "common/str.h"
+#include "common/str-array.h"
 
 #ifndef COMMON_MACRESMAN_H
 #define COMMON_MACRESMAN_H
@@ -89,7 +90,7 @@ public:
 	 * @param pattern Pattern to match against. Taking String::matchPattern's
 	 *                format.
 	 */
-	static void listFiles(Array<String> &files, const String &pattern);
+	static void listFiles(StringArray &files, const String &pattern);
 
 	/**
 	 * Close the Mac data/resource fork pair.


Commit: b6a8907edf0d604aa37300f4d1485d8d6e542994
    https://github.com/scummvm/scummvm/commit/b6a8907edf0d604aa37300f4d1485d8d6e542994
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2016-03-01T19:18:36+01:00

Commit Message:
SCI: Cleanup: Use Common::StringArray instead of custom type.

Changed paths:
    engines/sci/resource.cpp



diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index 7fb09fe..6a5af1a 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -586,10 +586,10 @@ int ResourceManager::addAppropriateSources() {
 #endif
 	} else if (Common::MacResManager::exists("Data1")) {
 		// Mac SCI1.1+ file naming scheme
-		Common::Array<Common::String> files;
+		Common::StringArray files;
 		Common::MacResManager::listFiles(files, "Data?");
 
-		for (Common::Array<Common::String>::const_iterator x = files.begin(); x != files.end(); ++x) {
+		for (Common::StringArray::const_iterator x = files.begin(); x != files.end(); ++x) {
 			addSource(new MacResourceForkResourceSource(*x, atoi(x->c_str() + 4)));
 		}
 






More information about the Scummvm-git-logs mailing list