[Scummvm-cvs-logs] SF.net SVN: scummvm: [29227] scummvm/trunk/common/file.cpp
david_corrales at users.sourceforge.net
david_corrales at users.sourceforge.net
Tue Oct 16 22:03:23 CEST 2007
Revision: 29227
http://scummvm.svn.sourceforge.net/scummvm/?rev=29227&view=rev
Author: david_corrales
Date: 2007-10-16 13:03:23 -0700 (Tue, 16 Oct 2007)
Log Message:
-----------
Make the exists() method take into account default directories. This makes the method more robust, since previously it checked absolute paths only.
Modified Paths:
--------------
scummvm/trunk/common/file.cpp
Modified: scummvm/trunk/common/file.cpp
===================================================================
--- scummvm/trunk/common/file.cpp 2007-10-15 20:20:50 UTC (rev 29226)
+++ scummvm/trunk/common/file.cpp 2007-10-16 20:03:23 UTC (rev 29227)
@@ -447,43 +447,37 @@
}
bool File::exists(const String &filename) {
+ FilesystemNode* file;
+ String fname = filename;
+
// First try to find the file via a FilesystemNode (in case an absolute
- // path was passed). But we only use this to filter out directories.
- FilesystemNode file(filename);
+ // path was passed). This is only used to filter out directories.
+ file = new FilesystemNode(fname);
+ if (file->exists())
+ return !file->isDirectory();
- // FIXME: Since (as stated in the comment above) the FilesystemNode
- // creation just works for absolute paths and we use this to tell if
- // a file exists in any of the setup paths, we cannot use
- // return (!file.isDirectory() && file.exists());
- //
- // I.e.:
- // FilesystemNode("foofile"); would fail for most (even all?)
- // implementations where the file 'foofile' does not exist in the CWD,
- // so we can not rely on FilesystemNode::exists, which would return false.
- if (file.exists())
- return !file.isDirectory();
+ // See if the file is already mapped
+ if (_filesMap && _filesMap->contains(fname)) {
+ fname = (*_filesMap)[fname];
+ file = new FilesystemNode(fname);
+
+ if (file->exists())
+ return !file->isDirectory();
+ }
- //***DEPRECATED COMMENTS BELOW, LEFT FOR DISCUSSION***
- // Next, try to locate the file by *opening* it in read mode. This has
- // multiple effects:
- // 1) It takes _filesMap and _defaultDirectories into consideration -> good
- // 2) It returns true if and only if File::open is possible on the file -> good
- // 3) If this method is misused, it could lead to an fopen call on a directory
- // -> bad!
- // 4) It also checks whether we can read the file. This is not 100%
- // desirable; after all, even when we can't read it, the file is present.
- // Since this method is often used to check whether a file should be
- // re-created, that's not nice.
- //
- // TODO/FIXME: We should clarify the semantics of this method, and then
- // maybe should introduce several new methods:
- // fileExistsAndReadable
- // fileExists
- // fileExistsAtPath
- // dirExists
- // dirExistsAtPath
- // or maybe only 1-2 methods which take some params :-).
+ // Try all default directories
+ if (_defaultDirectories) {
+ StringIntMap::const_iterator i(_defaultDirectories->begin());
+ for (; i != _defaultDirectories->end(); ++i) {
+ fname = i->_key+fname;
+ file = new FilesystemNode(fname);
+
+ if(file->exists())
+ return !file->isDirectory();
+ }
+ }
+ //Try opening the file inside the local directory as a last resort
File tmp;
return tmp.open(filename, kFileReadMode);
}
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