From a549977cffae9a5f1be41d9b07d42908648e8f6d Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Sun, 22 Jul 2012 21:02:25 +0200 Subject: WINTERMUTE: Use FSNodes to parse relative paths used by the games. --- engines/wintermute/base/file/base_disk_file.cpp | 28 +++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'engines/wintermute/base/file/base_disk_file.cpp') diff --git a/engines/wintermute/base/file/base_disk_file.cpp b/engines/wintermute/base/file/base_disk_file.cpp index b4653c2c80..d1a8f02fa5 100644 --- a/engines/wintermute/base/file/base_disk_file.cpp +++ b/engines/wintermute/base/file/base_disk_file.cpp @@ -37,6 +37,8 @@ #include "common/file.h" #include "common/zlib.h" #include "common/archive.h" +#include "common/tokenizer.h" +#include "common/config-manager.h" namespace WinterMute { @@ -50,7 +52,7 @@ Common::SeekableReadStream *openDiskFile(const Common::String &filename, BaseFil char fullPath[MAX_PATH_LENGTH]; uint32 prefixSize = 0; Common::SeekableReadStream *file = NULL; - + // Try directly from SearchMan first Common::ArchiveMemberList files; SearchMan.listMatchingMembers(files, filename); @@ -60,7 +62,29 @@ Common::SeekableReadStream *openDiskFile(const Common::String &filename, BaseFil break; } } - + // The filename can be an explicit path, thus we need to chop it up, expecting the path the game + // specifies to follow the Windows-convention of folder\subfolder\file (absolute paths should not happen) + if (!file) { + if (filename.contains(':')) + error("openDiskFile::Absolute path or invalid filename used in %s", filename.c_str()); + if (filename.contains('\\')) { + Common::StringTokenizer path(filename, "\\"); + + const Common::FSNode gameDataDir(ConfMan.get("path")); + Common::FSNode curNode = gameDataDir; + while (!path.empty()) { + Common::String pathPart = path.nextToken(); + Common::FSNode nextNode(curNode.getChild(pathPart)); + if (nextNode.exists() && nextNode.isReadable()) { + curNode = nextNode; + } + if (!curNode.isDirectory()) { + file = curNode.createReadStream(); + break; + } + } + } + } if (file) { uint32 magic1, magic2; magic1 = file->readUint32LE(); -- cgit v1.2.3