aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/resource.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2008-04-19 14:31:10 +0000
committerJohannes Schickel2008-04-19 14:31:10 +0000
commit7e12a50bed6cb18d6240d30eee6fb5a5a0aa7130 (patch)
treeafd1e5dbbcf63d0b78dcc92e9c3b943e8e7f3bdb /engines/kyra/resource.cpp
parent49cf8237f0d6188fa5c061b38e69d18b75eccc7c (diff)
downloadscummvm-rg350-7e12a50bed6cb18d6240d30eee6fb5a5a0aa7130.tar.gz
scummvm-rg350-7e12a50bed6cb18d6240d30eee6fb5a5a0aa7130.tar.bz2
scummvm-rg350-7e12a50bed6cb18d6240d30eee6fb5a5a0aa7130.zip
- some minor renaming in TIM code
- added exists function to Resource - started to add checks via exists to assure that important files are present svn-id: r31572
Diffstat (limited to 'engines/kyra/resource.cpp')
-rw-r--r--engines/kyra/resource.cpp53
1 files changed, 36 insertions, 17 deletions
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp
index e76d553372..c3cecf1a22 100644
--- a/engines/kyra/resource.cpp
+++ b/engines/kyra/resource.cpp
@@ -277,13 +277,29 @@ uint8 *Resource::fileData(const char *file, uint32 *size) {
return buffer;
}
+bool Resource::exists(const char *file, bool errorOutOnFail) {
+ if (Common::File::exists(file))
+ return true;
+ else if (isAccessable(file))
+ return true;
+ else if (errorOutOnFail)
+ error("File '%s' can't be found", file);
+ return false;
+}
+
uint32 Resource::getFileSize(const char *file) {
- if (!isAccessable(file))
- return 0;
+ if (Common::File::exists(file)) {
+ Common::File f;
+ if (f.open(file))
+ return f.size();
+ } else {
+ if (!isAccessable(file))
+ return 0;
- ResFileMap::const_iterator iter = _map.find(file);
- if (iter != _map.end())
- return iter->_value.size;
+ ResFileMap::const_iterator iter = _map.find(file);
+ if (iter != _map.end())
+ return iter->_value.size;
+ }
return 0;
}
@@ -299,18 +315,22 @@ bool Resource::loadFileToBuf(const char *file, void *buf, uint32 maxSize) {
}
Common::SeekableReadStream *Resource::getFileStream(const Common::String &file) {
- if (!isAccessable(file))
- return 0;
-
- ResFileMap::const_iterator iter = _map.find(file);
- if (iter == _map.end())
- return 0;
-
- Common::File *stream = new Common::File();
- if (stream->open(file)) {
+ if (Common::File::exists(file)) {
+ Common::File *stream = new Common::File();
+ if (!stream->open(file)) {
+ delete stream;
+ stream = 0;
+ error("Couldn't open file '%s'", file.c_str());
+ }
return stream;
} else {
- delete stream;
+ if (!isAccessable(file))
+ return 0;
+
+ ResFileMap::const_iterator iter = _map.find(file);
+ if (iter == _map.end())
+ return 0;
+
if (!iter->_value.parent.empty()) {
Common::SeekableReadStream *parent = getFileStream(iter->_value.parent);
assert(parent);
@@ -321,8 +341,7 @@ Common::SeekableReadStream *Resource::getFileStream(const Common::String &file)
return loader->loadFileFromArchive(file, parent, iter->_value);
} else {
- warning("Couldn't open file '%s'", file.c_str());
- return 0;
+ error("Couldn't open file '%s'", file.c_str());
}
}