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.
This commit is contained in:
Tobia Tesan 2016-12-26 11:55:06 +01:00
parent 9339490236
commit 72376681af
2 changed files with 18 additions and 2 deletions

View File

@ -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());
}
}
//////////////////////////////////////////////////////////////////////////

View File

@ -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() {