[Scummvm-git-logs] scummvm master -> a2bdff02d78018b8aa2b763d7d1ae8ef050934cd

csnover csnover at users.noreply.github.com
Fri Nov 10 16:59:23 CET 2017


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

Summary:
dda0f77bcf COMMON: Add basic fixed-width word wrap to Common::String
66826a8b9b ENGINES: Continue to check file presence after a hash/size mismatch
a2bdff02d7 ENGINES: Improve output of unknown game variant detection


Commit: dda0f77bcf093dced1ad833982be8a9e0951a85e
    https://github.com/scummvm/scummvm/commit/dda0f77bcf093dced1ad833982be8a9e0951a85e
Author: Colin Snover (github.com at zetafleet.com)
Date: 2017-11-10T09:57:41-06:00

Commit Message:
COMMON: Add basic fixed-width word wrap to Common::String

Changed paths:
    common/str.cpp
    common/str.h
    test/common/str.h


diff --git a/common/str.cpp b/common/str.cpp
index 3a0fd6a..2ef6717 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -444,6 +444,44 @@ void String::trim() {
 	}
 }
 
+void String::wordWrap(const uint32 maxLength) {
+	if (_size < maxLength) {
+		return;
+	}
+
+	makeUnique();
+
+	enum { kNoSpace = 0xFFFFFFFF };
+
+	uint32 i = 0;
+	while (i < _size) {
+		uint32 lastSpace = kNoSpace;
+		uint32 x = 0;
+		while (i < _size && x <= maxLength) {
+			const char c = _str[i];
+			if (c == '\n') {
+				lastSpace = kNoSpace;
+				x = 0;
+			} else {
+				if (Common::isSpace(c)) {
+					lastSpace = i;
+				}
+				++x;
+			}
+			++i;
+		}
+
+		if (x > maxLength) {
+			if (lastSpace == kNoSpace) {
+				insertChar('\n', i - 1);
+			} else {
+				setChar('\n', lastSpace);
+				i = lastSpace + 1;
+			}
+		}
+	}
+}
+
 uint String::hash() const {
 	return hashit(c_str());
 }
diff --git a/common/str.h b/common/str.h
index ba1e0b8..fd77fa9 100644
--- a/common/str.h
+++ b/common/str.h
@@ -235,6 +235,17 @@ public:
 	 */
 	void trim();
 
+	/**
+	 * Wraps the text in the string to the given line maximum. Lines will be
+	 * broken at any whitespace character. New lines are assumed to be
+	 * represented using '\n'.
+	 *
+	 * This is a very basic line wrap which does not perform tab stop
+	 * calculation, consecutive whitespace collapsing, auto-hyphenation, or line
+	 * balancing.
+	 */
+	void wordWrap(const uint32 maxLength);
+
 	uint hash() const;
 
 	/**@{
diff --git a/test/common/str.h b/test/common/str.h
index b7ad28e..9f8c6fb 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -443,6 +443,28 @@ class StringTestSuite : public CxxTest::TestSuite
 		TS_ASSERT_LESS_THAN(scumm_strnicmp("abCd", "ABCde", 5), 0);
 	}
 
+	void test_wordWrap() {
+		Common::String testString("123456");
+		testString.wordWrap(10);
+		TS_ASSERT(testString == "123456");
+		testString.wordWrap(2);
+		TS_ASSERT(testString == "12\n34\n56");
+		testString = "1234 5678";
+		testString.wordWrap(4);
+		TS_ASSERT(testString == "1234\n5678");
+		testString = "12 3 45";
+		testString.wordWrap(4);
+		TS_ASSERT(testString == "12 3\n45");
+		testString = "\n1\n23 45\n\n";
+		testString.wordWrap(3);
+		TS_ASSERT(testString == "\n1\n23\n45\n\n");
+		testString = "123 ";
+		testString.wordWrap(4);
+		TS_ASSERT(testString == "123 ");
+		testString.wordWrap(3);
+		TS_ASSERT(testString == "123\n");
+	}
+
 	void test_replace() {
 		// Tests created with the results of the STL std::string class
 


Commit: 66826a8b9bd9f75010c513699ec31bfbfc822f39
    https://github.com/scummvm/scummvm/commit/66826a8b9bd9f75010c513699ec31bfbfc822f39
Author: Colin Snover (github.com at zetafleet.com)
Date: 2017-11-10T09:57:41-06:00

Commit Message:
ENGINES: Continue to check file presence after a hash/size mismatch

If an early file in the game's signature list has a hash/size
mismatch, it is still necessary to continue to check the rest of
the candidate files for existence, since the non-existence of
candidate files is supposed to disqualify a game description as
matching a game to an unknown variant.

By quitting the file check early, the detector had been allowing
descriptions to randomly match if there happened to be an early
file in the detection list with the right name but wrong hash/size,
even if some of the other signature files did not exist at all.

Changed paths:
    engines/advancedDetector.cpp


diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp
index 64f462a..a66fe3d 100644
--- a/engines/advancedDetector.cpp
+++ b/engines/advancedDetector.cpp
@@ -466,6 +466,7 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons
 
 		bool allFilesPresent = true;
 		int curFilesMatched = 0;
+		bool hashOrSizeMismatch = false;
 
 		// Try to match all files for this game
 		for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) {
@@ -477,16 +478,21 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons
 				break;
 			}
 
+			if (hashOrSizeMismatch)
+				continue;
+
 			if (fileDesc->md5 != NULL && fileDesc->md5 != filesProps[tstr].md5) {
 				debug(3, "MD5 Mismatch. Skipping (%s) (%s)", fileDesc->md5, filesProps[tstr].md5.c_str());
 				fileMissing = true;
-				break;
+				hashOrSizeMismatch = true;
+				continue;
 			}
 
 			if (fileDesc->fileSize != -1 && fileDesc->fileSize != filesProps[tstr].size) {
 				debug(3, "Size Mismatch. Skipping");
 				fileMissing = true;
-				break;
+				hashOrSizeMismatch = true;
+				continue;
 			}
 
 			debug(3, "Matched file: %s", tstr.c_str());


Commit: a2bdff02d78018b8aa2b763d7d1ae8ef050934cd
    https://github.com/scummvm/scummvm/commit/a2bdff02d78018b8aa2b763d7d1ae8ef050934cd
Author: Colin Snover (github.com at zetafleet.com)
Date: 2017-11-10T09:57:41-06:00

Commit Message:
ENGINES: Improve output of unknown game variant detection

When a user tries to add a game expecting it to be a particular
game for a particular engine, but a detector from another engine
happens to match some files that exist in the game directory and
reports on those files instead, this can cause a lot of confusion
because the detector doesn't say what engine or game it thought it
matched.

This patch adds the name of the matching engine as well as any
matching game IDs (if applicable) to the detector's logged output.
It also provides more specific guidance about where to send the
detection information (to the bug tracker), and properly wraps the
first part of the report to 80 columns.

Refs Trac#10272.

Changed paths:
    engines/advancedDetector.cpp
    engines/advancedDetector.h
    engines/gob/detection/detection.cpp


diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp
index a66fe3d..9d69505 100644
--- a/engines/advancedDetector.cpp
+++ b/engines/advancedDetector.cpp
@@ -325,17 +325,30 @@ Common::Error AdvancedMetaEngine::createInstance(OSystem *syst, Engine **engine)
 		return Common::kNoError;
 }
 
-void AdvancedMetaEngine::reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps) const {
-	// TODO: This message should be cleaned up / made more specific.
-	// For example, we should specify at least which engine triggered this.
-	//
-	// Might also be helpful to display the full path (for when this is used
-	// from the mass detector).
+void AdvancedMetaEngine::reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps, const ADGameIdList &matchedGameIds) const {
 	Common::String report = Common::String::format(
-			_("The game in '%s' seems to be unknown.\n"
-			  "Please, report the following data to the ScummVM team along with name\n"
-			  "of the game you tried to add and its version, language, etc.:"), path.getPath().c_str()) + "\n";
-	report += "\n";
+			_("The game in '%s' seems to be an unknown %s engine game "
+			  "variant.\n\nPlease report the following data to the ScummVM "
+			  "team at %s along with the name of the game you tried to add and "
+			  "its version, language, etc.:"),
+			path.getPath().c_str(), getName(), "https://bugs.scummvm.org/");
+
+	if (matchedGameIds.size()) {
+		report += "\n\n";
+		report += _("Matched game IDs:");
+		report += " ";
+
+		for (ADGameIdList::const_iterator gameId = matchedGameIds.begin(); gameId != matchedGameIds.end(); ++gameId) {
+			if (gameId != matchedGameIds.begin()) {
+				report += ", ";
+			}
+			report += *gameId;
+		}
+	}
+
+	report += "\n\n";
+
+	report.wordWrap(80);
 
 	for (ADFilePropertiesMap::const_iterator file = filesProps.begin(); file != filesProps.end(); ++file)
 		report += Common::String::format("  {\"%s\", 0, \"%s\", %d},\n", file->_key.c_str(), file->_value.md5.c_str(), file->_value.size);
@@ -444,6 +457,7 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons
 	}
 
 	ADGameDescList matched;
+	ADGameIdList matchedGameIds;
 	int maxFilesMatched = 0;
 	bool gotAnyMatchesWithAllFiles = false;
 
@@ -508,8 +522,11 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons
 		// Potentially this could rule out variants where some particular file
 		// is really missing, but the developers should better know about such
 		// cases.
-		if (allFilesPresent)
+		if (allFilesPresent) {
 			gotAnyMatchesWithAllFiles = true;
+			if (!matchedGameIds.size() || strcmp(matchedGameIds.back(), g->gameId) != 0)
+				matchedGameIds.push_back(g->gameId);
+		}
 
 		if (!fileMissing) {
 			debug(2, "Found game: %s (%s %s/%s) (%d)", g->gameId, g->extra,
@@ -536,7 +553,7 @@ ADGameDescList AdvancedMetaEngine::detectGame(const Common::FSNode &parent, cons
 	// We didn't find a match
 	if (matched.empty()) {
 		if (!filesProps.empty() && gotAnyMatchesWithAllFiles) {
-			reportUnknown(parent, filesProps);
+			reportUnknown(parent, filesProps, matchedGameIds);
 		}
 
 		// Filename based fallback
diff --git a/engines/advancedDetector.h b/engines/advancedDetector.h
index e218c41..61693d1 100644
--- a/engines/advancedDetector.h
+++ b/engines/advancedDetector.h
@@ -117,6 +117,11 @@ struct ADGameDescription {
 typedef Common::Array<const ADGameDescription *> ADGameDescList;
 
 /**
+ * A list of raw game ID strings.
+ */
+typedef Common::Array<const char *> ADGameIdList;
+
+/**
  * End marker for a table of ADGameDescription structs. Use this to
  * terminate a list to be passed to the AdvancedDetector API.
  */
@@ -328,7 +333,7 @@ protected:
 	 * Log and print a report that we found an unknown game variant, together with the file
 	 * names, sizes and MD5 sums.
 	 */
-	void reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps) const;
+	void reportUnknown(const Common::FSNode &path, const ADFilePropertiesMap &filesProps, const ADGameIdList &matchedGameIds = ADGameIdList()) const;
 
 	// TODO
 	void updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *realDesc) const;
diff --git a/engines/gob/detection/detection.cpp b/engines/gob/detection/detection.cpp
index b0aa78f..e204ced 100644
--- a/engines/gob/detection/detection.cpp
+++ b/engines/gob/detection/detection.cpp
@@ -77,7 +77,10 @@ const ADGameDescription *GobMetaEngine::fallbackDetect(const FileMap &allFiles,
 			return 0;
 	}
 
-	reportUnknown(fslist.begin()->getParent(), filesProps);
+	ADGameIdList gameIds;
+	gameIds.push_back(game->desc.gameId);
+
+	reportUnknown(fslist.begin()->getParent(), filesProps, gameIds);
 	return (const ADGameDescription *)game;
 }
 





More information about the Scummvm-git-logs mailing list