aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/wintermute/ad/ad_game.cpp10
-rw-r--r--engines/wintermute/ad/ad_sentence.cpp7
-rw-r--r--engines/wintermute/base/base_file_manager.cpp13
-rw-r--r--engines/wintermute/base/file/base_disk_file.cpp37
-rw-r--r--engines/wintermute/base/file/base_disk_file.h1
-rw-r--r--engines/wintermute/base/file/base_resources.cpp19
-rw-r--r--engines/wintermute/base/file/base_resources.h3
7 files changed, 66 insertions, 24 deletions
diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp
index e10ec1bf6d..aa350b0e4c 100644
--- a/engines/wintermute/ad/ad_game.cpp
+++ b/engines/wintermute/ad/ad_game.cpp
@@ -1904,18 +1904,12 @@ char *AdGame::findSpeechFile(char *stringID) {
for (int i = 0; i < _speechDirs.getSize(); i++) {
sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID);
- Common::SeekableReadStream *file = _fileManager->openFile(ret); // TODO: Replace with hasFile
- if (file) {
- _fileManager->closeFile(file);
+ if (_fileManager->hasFile(ret))
return ret;
- }
sprintf(ret, "%s%s.wav", _speechDirs[i], stringID);
- file = _fileManager->openFile(ret);
- if (file) {
- _fileManager->closeFile(file);
+ if (_fileManager->hasFile(ret))
return ret;
- }
}
delete [] ret;
return NULL;
diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp
index ba59f57451..ad3a291e16 100644
--- a/engines/wintermute/ad/ad_sentence.cpp
+++ b/engines/wintermute/ad/ad_sentence.cpp
@@ -251,11 +251,8 @@ bool AdSentence::setupTalkFile(const char *soundFilename) {
AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk");
- Common::SeekableReadStream *file = _gameRef->_fileManager->openFile(talkDefFileName.c_str());
- if (file) {
- _gameRef->_fileManager->closeFile(file);
- } else return STATUS_OK; // no talk def file found
-
+ if (!_gameRef->_fileManager->hasFile(talkDefFileName))
+ return STATUS_OK; // no talk def file found
_talkDef = new AdTalkDef(_gameRef);
if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) {
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