aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra
diff options
context:
space:
mode:
authorJohannes Schickel2008-04-10 22:18:47 +0000
committerJohannes Schickel2008-04-10 22:18:47 +0000
commit6711a494a228792138af1e8534a37d1c75d4f1f4 (patch)
treee768073dacc0f5d090870b05f6c1eaf8be2cb973 /engines/kyra
parent58b78bae07b208874d62db6d6c35a22ae07aa950 (diff)
downloadscummvm-rg350-6711a494a228792138af1e8534a37d1c75d4f1f4.tar.gz
scummvm-rg350-6711a494a228792138af1e8534a37d1c75d4f1f4.tar.bz2
scummvm-rg350-6711a494a228792138af1e8534a37d1c75d4f1f4.zip
Improved searchpath support. (Should again detect everything Common::File is able to load).
svn-id: r31478
Diffstat (limited to 'engines/kyra')
-rw-r--r--engines/kyra/resource.cpp101
-rw-r--r--engines/kyra/resource.h13
2 files changed, 36 insertions, 78 deletions
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp
index fa1da6a814..dd9f459bc9 100644
--- a/engines/kyra/resource.cpp
+++ b/engines/kyra/resource.cpp
@@ -125,11 +125,11 @@ bool Resource::reset() {
}
bool Resource::loadPakFile(const Common::String &filename) {
- ResFileMap::iterator iter = _map.find(filename);
- if (iter == _map.end())
+ if (!isAccessable(filename))
return false;
- if (iter->_value.preload) {
+ ResFileMap::iterator iter = _map.find(filename);
+ if (iter != _map.end() && iter->_value.preload) {
iter->_value.mounted = true;
return true;
}
@@ -140,9 +140,6 @@ bool Resource::loadPakFile(const Common::String &filename) {
return false;
}
- if (!isAccessable(filename))
- return false;
-
Common::SeekableReadStream *stream = getFileStream(filename);
if (!stream) {
error("archive file '%s' not found", filename.c_str());
@@ -250,77 +247,17 @@ void Resource::unloadPakFile(const Common::String &filename) {
}
}
-bool Resource::isInPakList(const Common::String &filename) const {
+bool Resource::isInPakList(const Common::String &filename) {
return isAccessable(filename);
}
void Resource::unloadAllPakFiles() {
// remove all entries
_map.clear();
-
- addSearchPath(ConfMan.get("path"));
- addSearchPath(ConfMan.get("extrapath"));
-
- Common::File temp;
-
- ResFileMap::iterator iter = _map.find(StaticResource::staticDataFilename());
- if (iter == _map.end()) {
- if (temp.open(StaticResource::staticDataFilename())) {
- ResFileEntry entry;
- entry.parent = "";
- entry.size = temp.size();
- entry.mounted = true;
- entry.preload = false;
- entry.prot = false;
- entry.type = ResFileEntry::kAutoDetect;
- entry.offset = 0;
- _map[StaticResource::staticDataFilename()] = entry;
- temp.close();
- }
- }
-
detectFileTypes();
}
-bool Resource::addSearchPath(const Common::String &path) {
- if (path.empty())
- return false;
-
- FilesystemNode dir(path);
-
- if (!dir.exists() || !dir.isDirectory()) {
- warning("invalid data path '%s'", dir.getPath().c_str());
- return false;
- }
-
- FSList fslist;
- if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) {
- warning("can't list files inside path '%s'", dir.getPath().c_str());
- return false;
- }
-
- Common::File temp;
-
- for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
- ResFileEntry entry;
- entry.parent = "";
- if (!temp.open(file->getPath()))
- error("couldn't open file '%s'", file->getName().c_str());
- entry.size = temp.size();
- entry.offset = 0;
- entry.mounted = false;
- entry.preload = false;
- entry.prot = false;
- entry.type = ResFileEntry::kAutoDetect;
- _map[file->getName()] = entry;
- temp.close();
- }
-
- detectFileTypes();
- return true;
-}
-
-uint8 *Resource::fileData(const char *file, uint32 *size) const {
+uint8 *Resource::fileData(const char *file, uint32 *size) {
Common::SeekableReadStream *stream = getFileStream(file);
if (!stream)
return 0;
@@ -335,7 +272,7 @@ uint8 *Resource::fileData(const char *file, uint32 *size) const {
return buffer;
}
-uint32 Resource::getFileSize(const char *file) const {
+uint32 Resource::getFileSize(const char *file) {
if (!isAccessable(file))
return 0;
@@ -356,7 +293,7 @@ bool Resource::loadFileToBuf(const char *file, void *buf, uint32 maxSize) {
return true;
}
-Common::SeekableReadStream *Resource::getFileStream(const Common::String &file) const {
+Common::SeekableReadStream *Resource::getFileStream(const Common::String &file) {
if (!isAccessable(file))
return 0;
@@ -385,7 +322,9 @@ Common::SeekableReadStream *Resource::getFileStream(const Common::String &file)
return 0;
}
-bool Resource::isAccessable(const Common::String &file) const {
+bool Resource::isAccessable(const Common::String &file) {
+ checkFile(file);
+
ResFileMap::const_iterator iter = _map.find(file);
while (iter != _map.end()) {
if (!iter->_value.parent.empty()) {
@@ -405,6 +344,26 @@ bool Resource::isAccessable(const Common::String &file) const {
return false;
}
+void Resource::checkFile(const Common::String &file) {
+ if (_map.find(file) == _map.end() && Common::File::exists(file)) {
+ Common::File temp;
+ if (temp.open(file)) {
+ ResFileEntry entry;
+ entry.parent = "";
+ entry.size = temp.size();
+ entry.mounted = file.compareToIgnoreCase(StaticResource::staticDataFilename());
+ entry.preload = false;
+ entry.prot = false;
+ entry.type = ResFileEntry::kAutoDetect;
+ entry.offset = 0;
+ _map[file] = entry;
+ temp.close();
+
+ detectFileTypes();
+ }
+ }
+}
+
void Resource::detectFileTypes() {
for (ResFileMap::iterator i = _map.begin(); i != _map.end(); ++i) {
if (!isAccessable(i->_key))
diff --git a/engines/kyra/resource.h b/engines/kyra/resource.h
index 3a0782e22e..3d50b0c8a1 100644
--- a/engines/kyra/resource.h
+++ b/engines/kyra/resource.h
@@ -92,24 +92,23 @@ public:
bool reset();
- bool addSearchPath(const Common::String &path);
-
bool loadPakFile(const Common::String &filename);
void unloadPakFile(const Common::String &filename);
- bool isInPakList(const Common::String &filename) const;
+ bool isInPakList(const Common::String &filename);
bool loadFileList(const Common::String &filedata);
bool loadFileList(const char * const *filelist, uint32 numFiles);
// This unloads *all* pakfiles, even kyra.dat and protected ones
void unloadAllPakFiles();
- uint32 getFileSize(const char *file) const;
- uint8* fileData(const char *file, uint32 *size) const;
- Common::SeekableReadStream *getFileStream(const Common::String &file) const;
+ uint32 getFileSize(const char *file);
+ uint8* fileData(const char *file, uint32 *size);
+ Common::SeekableReadStream *getFileStream(const Common::String &file);
bool loadFileToBuf(const char *file, void *buf, uint32 maxSize);
protected:
- bool isAccessable(const Common::String &file) const;
+ void checkFile(const Common::String &file);
+ bool isAccessable(const Common::String &file);
void detectFileTypes();