[Scummvm-cvs-logs] SF.net SVN: scummvm: [31478] scummvm/trunk/engines/kyra
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Fri Apr 11 00:18:47 CEST 2008
Revision: 31478
http://scummvm.svn.sourceforge.net/scummvm/?rev=31478&view=rev
Author: lordhoto
Date: 2008-04-10 15:18:47 -0700 (Thu, 10 Apr 2008)
Log Message:
-----------
Improved searchpath support. (Should again detect everything Common::File is able to load).
Modified Paths:
--------------
scummvm/trunk/engines/kyra/resource.cpp
scummvm/trunk/engines/kyra/resource.h
Modified: scummvm/trunk/engines/kyra/resource.cpp
===================================================================
--- scummvm/trunk/engines/kyra/resource.cpp 2008-04-10 21:58:59 UTC (rev 31477)
+++ scummvm/trunk/engines/kyra/resource.cpp 2008-04-10 22:18:47 UTC (rev 31478)
@@ -125,11 +125,11 @@
}
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 @@
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 @@
}
}
-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 @@
return buffer;
}
-uint32 Resource::getFileSize(const char *file) const {
+uint32 Resource::getFileSize(const char *file) {
if (!isAccessable(file))
return 0;
@@ -356,7 +293,7 @@
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 @@
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 @@
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))
Modified: scummvm/trunk/engines/kyra/resource.h
===================================================================
--- scummvm/trunk/engines/kyra/resource.h 2008-04-10 21:58:59 UTC (rev 31477)
+++ scummvm/trunk/engines/kyra/resource.h 2008-04-10 22:18:47 UTC (rev 31478)
@@ -92,24 +92,23 @@
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();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list