[Scummvm-git-logs] scummvm master -> 44254e04f6a6373ca59dd17f1154e20ba12d04b7

rvanlaar roland at rolandvanlaar.nl
Thu Jul 30 19:55:22 UTC 2020


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

Summary:
44254e04f6 DIRECTOR: Skip empty files in pathMakeRelative.


Commit: 44254e04f6a6373ca59dd17f1154e20ba12d04b7
    https://github.com/scummvm/scummvm/commit/44254e04f6a6373ca59dd17f1154e20ba12d04b7
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-07-30T21:52:47+02:00

Commit Message:
DIRECTOR: Skip empty files in pathMakeRelative.

Who Killed Brett Penance has empty files that have
the same name as the archive, but without the .mmm extension.
The file archive can be opened, but is empty, so skip it.

Includes refactor of file check to `testPath`.

Changed paths:
    engines/director/util.cpp
    engines/director/util.h


diff --git a/engines/director/util.cpp b/engines/director/util.cpp
index 16f8fa291f..28835edb90 100644
--- a/engines/director/util.cpp
+++ b/engines/director/util.cpp
@@ -292,6 +292,16 @@ Common::String getPath(Common::String path, Common::String cwd) {
 	return cwd; // The path is not altered
 }
 
+bool testPath(Common::String &path) {
+	Common::File f;
+	if (f.open(path)) {
+		if (f.size())
+			return true;
+		f.close();
+	}
+	return false;
+}
+
 Common::String pathMakeRelative(Common::String path, bool recursive, bool addexts) {
 	Common::String initialPath(path);
 
@@ -309,7 +319,7 @@ Common::String pathMakeRelative(Common::String path, bool recursive, bool addext
 	// Strip the leading whitespace from the path
 	initialPath.trim();
 
-	if (f.open(initialPath))
+	if (testPath(initialPath))
 		return initialPath;
 
 	// Now try to search the file
@@ -336,7 +346,7 @@ Common::String pathMakeRelative(Common::String path, bool recursive, bool addext
 
 		debug(2, "pathMakeRelative(): s4 %s", convPath.c_str());
 
-		if (f.open(initialPath))
+		if (testPath(initialPath))
 			return initialPath;
 
 		// Now try to search the file
@@ -357,6 +367,8 @@ Common::String pathMakeRelative(Common::String path, bool recursive, bool addext
 		}
 	}
 
+	f.close();
+
 	if (!opened && recursive) {
 		// Hmmm. We couldn't find the path as is.
 		// Let's try to translate file path into 8.3 format
@@ -393,17 +405,14 @@ Common::String pathMakeRelative(Common::String path, bool recursive, bool addext
 
 				Common::String res = pathMakeRelative(newpath, false, false);
 
-				if (f.open(res))
+				if (testPath(res))
 					return res;
 			}
 		}
 
-
 		return initialPath;	// Anyway nothing good is happening
 	}
 
-	f.close();
-
 	if (opened)
 		return convPath;
 	else
diff --git a/engines/director/util.h b/engines/director/util.h
index cfd2317b2f..5a0e7c2805 100644
--- a/engines/director/util.h
+++ b/engines/director/util.h
@@ -38,6 +38,8 @@ Common::String convertPath(Common::String &path);
 
 Common::String getPath(Common::String path, Common::String cwd);
 
+bool testPath(Common::String path);
+
 Common::String pathMakeRelative(Common::String path, bool recursive = true, bool addexts = true);
 
 Common::String getFileName(Common::String path);




More information about the Scummvm-git-logs mailing list