aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/file/base_disk_file.cpp
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-07-22 22:27:07 +0200
committerEinar Johan Trøan Sømåen2012-07-22 22:27:07 +0200
commit3bcbd1881c9a22a594707726154c568d187e313b (patch)
tree05ee6571359b1396759316478e97b52057600a44 /engines/wintermute/base/file/base_disk_file.cpp
parent6fb641111f28d02714064ae193e39e4f1e60ce35 (diff)
downloadscummvm-rg350-3bcbd1881c9a22a594707726154c568d187e313b.tar.gz
scummvm-rg350-3bcbd1881c9a22a594707726154c568d187e313b.tar.bz2
scummvm-rg350-3bcbd1881c9a22a594707726154c568d187e313b.zip
WINTERMUTE: Avoid opening files when checking hasFile()
Diffstat (limited to 'engines/wintermute/base/file/base_disk_file.cpp')
-rw-r--r--engines/wintermute/base/file/base_disk_file.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/engines/wintermute/base/file/base_disk_file.cpp b/engines/wintermute/base/file/base_disk_file.cpp
index d1a8f02fa5..c20fd9f342 100644
--- a/engines/wintermute/base/file/base_disk_file.cpp
+++ b/engines/wintermute/base/file/base_disk_file.cpp
@@ -48,6 +48,43 @@ void correctSlashes(char *fileName) {
}
}
+bool diskFileExists(const Common::String& filename) {
+ Common::SeekableReadStream *file = NULL;
+ // Try directly from SearchMan first
+ Common::ArchiveMemberList files;
+ SearchMan.listMatchingMembers(files, filename);
+
+ for (Common::ArchiveMemberList::iterator it = files.begin(); it != files.end(); it++) {
+ if ((*it)->getName() == filename) {
+ return true;
+ }
+ }
+ // 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 (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()) {
+ if (curNode.exists() && curNode.isReadable())
+ return true;
+ else
+ return false;
+ }
+ }
+ }
+ return false;
+}
+
Common::SeekableReadStream *openDiskFile(const Common::String &filename, BaseFileManager *fileManager) {
char fullPath[MAX_PATH_LENGTH];
uint32 prefixSize = 0;