diff options
author | Einar Johan Trøan Sømåen | 2012-07-22 22:27:07 +0200 |
---|---|---|
committer | Einar Johan Trøan Sømåen | 2012-07-22 22:27:07 +0200 |
commit | 3bcbd1881c9a22a594707726154c568d187e313b (patch) | |
tree | 05ee6571359b1396759316478e97b52057600a44 /engines/wintermute/base | |
parent | 6fb641111f28d02714064ae193e39e4f1e60ce35 (diff) | |
download | scummvm-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')
-rw-r--r-- | engines/wintermute/base/base_file_manager.cpp | 13 | ||||
-rw-r--r-- | engines/wintermute/base/file/base_disk_file.cpp | 37 | ||||
-rw-r--r-- | engines/wintermute/base/file/base_disk_file.h | 1 | ||||
-rw-r--r-- | engines/wintermute/base/file/base_resources.cpp | 19 | ||||
-rw-r--r-- | engines/wintermute/base/file/base_resources.h | 3 |
5 files changed, 62 insertions, 11 deletions
diff --git a/engines/wintermute/base/base_file_manager.cpp b/engines/wintermute/base/base_file_manager.cpp index 4dcc1c6948..f651835fe4 100644 --- a/engines/wintermute/base/base_file_manager.cpp +++ b/engines/wintermute/base/base_file_manager.cpp @@ -582,12 +582,13 @@ BaseFileEntry *BaseFileManager::getPackageEntry(const Common::String &filename) }
bool BaseFileManager::hasFile(const Common::String &filename) {
- //TODO: Do this in a much simpler fashion
- Common::SeekableReadStream *stream = openFile(filename, true, false);
- if (!stream) {
- return false;
- }
- delete stream;
+ if (diskFileExists(filename))
+ return true;
+ if (getPackageEntry(filename))
+ return true; // We don't bother checking if the file can actually be opened, something bigger is wrong if that is the case.
+ if (BaseResources::hasFile(filename))
+ return true;
+ return false;
return true;
}
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;
diff --git a/engines/wintermute/base/file/base_disk_file.h b/engines/wintermute/base/file/base_disk_file.h index e688a12b50..b0ba32cb84 100644 --- a/engines/wintermute/base/file/base_disk_file.h +++ b/engines/wintermute/base/file/base_disk_file.h @@ -36,6 +36,7 @@ class SeekableReadStream; namespace WinterMute {
Common::SeekableReadStream *openDiskFile(const Common::String &filename, BaseFileManager *fileManager);
+bool diskFileExists(const Common::String& filename);
} // end of namespace WinterMute
diff --git a/engines/wintermute/base/file/base_resources.cpp b/engines/wintermute/base/file/base_resources.cpp index 9b1c9fee04..f7aaf6393a 100644 --- a/engines/wintermute/base/file/base_resources.cpp +++ b/engines/wintermute/base/file/base_resources.cpp @@ -2806,15 +2806,26 @@ unsigned char systemfont[] = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
} ;
-Common::SeekableReadStream *BaseResources::getFile(const Common::String &fileName) {
- if (scumm_stricmp(fileName.c_str(), "invalid.bmp") == 0) {
+Common::SeekableReadStream *BaseResources::getFile(const Common::String &filename) {
+ if (scumm_stricmp(filename.c_str(), "invalid.bmp") == 0) {
return new Common::MemoryReadStream(invalid, sizeof(invalid), DisposeAfterUse::NO);
- } else if (scumm_stricmp(fileName.c_str(), "invalid_debug.bmp") == 0) {
+ } else if (scumm_stricmp(filename.c_str(), "invalid_debug.bmp") == 0) {
return new Common::MemoryReadStream(invaliddebug, sizeof(invalid), DisposeAfterUse::NO);
- } else if (scumm_stricmp(fileName.c_str(), "syste_font.bmp") == 0) {
+ } else if (scumm_stricmp(filename.c_str(), "syste_font.bmp") == 0) {
return new Common::MemoryReadStream(systemfont, sizeof(invalid), DisposeAfterUse::NO);
}
return NULL;
}
+bool BaseResources::hasFile(const Common::String& filename) {
+ if (scumm_stricmp(filename.c_str(), "invalid.bmp") == 0) {
+ return true;
+ } else if (scumm_stricmp(filename.c_str(), "invalid_debug.bmp") == 0) {
+ return true;
+ } else if (scumm_stricmp(filename.c_str(), "syste_font.bmp") == 0) {
+ return true;
+ }
+ return false;
+}
+
} // end of namespace WinterMute
diff --git a/engines/wintermute/base/file/base_resources.h b/engines/wintermute/base/file/base_resources.h index 6316cecd15..2959f9882f 100644 --- a/engines/wintermute/base/file/base_resources.h +++ b/engines/wintermute/base/file/base_resources.h @@ -36,7 +36,8 @@ namespace WinterMute { class BaseResources {
public:
- static Common::SeekableReadStream *getFile(const Common::String &fileName);
+ static Common::SeekableReadStream *getFile(const Common::String &filename);
+ static bool hasFile(const Common::String& filename);
};
} // end of namespace WinterMute
|