aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobia Tesan2016-12-26 11:55:06 +0100
committerTobia Tesan2016-12-26 12:05:41 +0100
commit72376681afad3e57ffa2134d76ad649a38c86023 (patch)
tree2703dc08691260642a8604283909cf543dce08f3
parent93394902368a0fb2c25647f0d6205f5a43282933 (diff)
downloadscummvm-rg350-72376681afad3e57ffa2134d76ad649a38c86023.tar.gz
scummvm-rg350-72376681afad3e57ffa2134d76ad649a38c86023.tar.bz2
scummvm-rg350-72376681afad3e57ffa2134d76ad649a38c86023.zip
WINTERMUTE: Try to "correctly" handle dir paths
I put scare quotes around "correctly" because I can't swear this is the intended behaviour of the original interpreter. I don't think accessing filenames that end with / in the .DCPs is even defined behaviour, so this is a best guess.
-rw-r--r--engines/wintermute/utils/path_util.cpp6
-rw-r--r--test/engines/wintermute/path_utils.h14
2 files changed, 18 insertions, 2 deletions
diff --git a/engines/wintermute/utils/path_util.cpp b/engines/wintermute/utils/path_util.cpp
index 60a07f0bf0..8518f8968f 100644
--- a/engines/wintermute/utils/path_util.cpp
+++ b/engines/wintermute/utils/path_util.cpp
@@ -71,7 +71,11 @@ bool PathUtil::hasTrailingSlash(const Common::String &path) {
Common::String PathUtil::getDirectoryName(const Common::String &path) {
Common::String newPath = unifySeparators(path);
Common::String filename = getFileName(path);
- return Common::String(path.c_str(), path.size() - filename.size());
+ if (hasTrailingSlash(newPath)) {
+ return path;
+ } else {
+ return Common::String(path.c_str(), path.size() - filename.size());
+ }
}
//////////////////////////////////////////////////////////////////////////
diff --git a/test/engines/wintermute/path_utils.h b/test/engines/wintermute/path_utils.h
index 3cacf47fd9..26f3404396 100644
--- a/test/engines/wintermute/path_utils.h
+++ b/test/engines/wintermute/path_utils.h
@@ -23,6 +23,8 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
const Common::String mixedSlashesPath2;
const Common::String unixRelativePath;
const Common::String windowsRelativePath;
+ const Common::String unixDirPath;
+ const Common::String windowsDirPath;
PathUtilTestSuite () :
unixPath("/some/file.ext"),
unixCapPath("/SOME/FILE.EXT"),
@@ -34,7 +36,9 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
mixedSlashesPath1("C:\\this/IS_REALLY\\weird.exe"),
mixedSlashesPath2("/pretty\\weird/indeed.txt"),
unixRelativePath("some/file.ext"),
- windowsRelativePath("some\\file.ext")
+ windowsRelativePath("some\\file.ext"),
+ unixDirPath("/some/dir/"),
+ windowsDirPath("C:\\some\\dir\\")
{}
void test_getdirectoryname() {
TS_ASSERT_EQUALS(
@@ -57,6 +61,14 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
Wintermute::PathUtil::getDirectoryName(emptyString),
Common::String("")
);
+ TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getDirectoryName(unixDirPath),
+ Common::String("/some/dir/")
+ );
+ TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getDirectoryName(windowsDirPath),
+ Common::String("C:\\some\\dir\\")
+ );
}
void test_getfilename() {