mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-21 19:51:49 +00:00
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:
parent
9339490236
commit
72376681af
@ -71,7 +71,11 @@ bool PathUtil::hasTrailingSlash(const Common::String &path) {
|
|||||||
Common::String PathUtil::getDirectoryName(const Common::String &path) {
|
Common::String PathUtil::getDirectoryName(const Common::String &path) {
|
||||||
Common::String newPath = unifySeparators(path);
|
Common::String newPath = unifySeparators(path);
|
||||||
Common::String filename = getFileName(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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -23,6 +23,8 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
|
|||||||
const Common::String mixedSlashesPath2;
|
const Common::String mixedSlashesPath2;
|
||||||
const Common::String unixRelativePath;
|
const Common::String unixRelativePath;
|
||||||
const Common::String windowsRelativePath;
|
const Common::String windowsRelativePath;
|
||||||
|
const Common::String unixDirPath;
|
||||||
|
const Common::String windowsDirPath;
|
||||||
PathUtilTestSuite () :
|
PathUtilTestSuite () :
|
||||||
unixPath("/some/file.ext"),
|
unixPath("/some/file.ext"),
|
||||||
unixCapPath("/SOME/FILE.EXT"),
|
unixCapPath("/SOME/FILE.EXT"),
|
||||||
@ -34,7 +36,9 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
|
|||||||
mixedSlashesPath1("C:\\this/IS_REALLY\\weird.exe"),
|
mixedSlashesPath1("C:\\this/IS_REALLY\\weird.exe"),
|
||||||
mixedSlashesPath2("/pretty\\weird/indeed.txt"),
|
mixedSlashesPath2("/pretty\\weird/indeed.txt"),
|
||||||
unixRelativePath("some/file.ext"),
|
unixRelativePath("some/file.ext"),
|
||||||
windowsRelativePath("some\\file.ext")
|
windowsRelativePath("some\\file.ext"),
|
||||||
|
unixDirPath("/some/dir/"),
|
||||||
|
windowsDirPath("C:\\some\\dir\\")
|
||||||
{}
|
{}
|
||||||
void test_getdirectoryname() {
|
void test_getdirectoryname() {
|
||||||
TS_ASSERT_EQUALS(
|
TS_ASSERT_EQUALS(
|
||||||
@ -57,6 +61,14 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
|
|||||||
Wintermute::PathUtil::getDirectoryName(emptyString),
|
Wintermute::PathUtil::getDirectoryName(emptyString),
|
||||||
Common::String("")
|
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() {
|
void test_getfilename() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user