diff options
Diffstat (limited to 'common/file.cpp')
-rw-r--r-- | common/file.cpp | 95 |
1 files changed, 37 insertions, 58 deletions
diff --git a/common/file.cpp b/common/file.cpp index cf396a32cd..ed432ce565 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -31,39 +31,30 @@ namespace Common { -static Common::SearchSet *s_searchSet = 0; - - void File::addDefaultDirectory(const String &directory) { - FilesystemNode dir(directory); + FSNode dir(directory); addDefaultDirectoryRecursive(dir, 1); } void File::addDefaultDirectoryRecursive(const String &directory, int level) { - FilesystemNode dir(directory); + FSNode dir(directory); addDefaultDirectoryRecursive(dir, level); } -void File::addDefaultDirectory(const FilesystemNode &directory) { +void File::addDefaultDirectory(const FSNode &directory) { addDefaultDirectoryRecursive(directory, 1); } -void File::addDefaultDirectoryRecursive(const FilesystemNode &dir, int level) { +void File::addDefaultDirectoryRecursive(const FSNode &dir, int level) { if (level <= 0 || !dir.exists() || !dir.isDirectory()) return; - if (!s_searchSet) { - s_searchSet = new Common::SearchSet(); - g_system->addSysArchivesToSearchSet(*s_searchSet); - } - Common::ArchivePtr dataArchive(new Common::FSDirectory(dir, level)); - s_searchSet->add(dir.getPath(), dataArchive, 1); + SearchMan.add(dir.getPath(), dataArchive); } void File::resetDefaultDirectories() { - delete s_searchSet; - s_searchSet = 0; + SearchMan.clear(); } File::File() @@ -74,78 +65,66 @@ File::~File() { close(); } - bool File::open(const String &filename) { + return open(filename, SearchMan); +} + +bool File::open(const String &filename, Archive &archive) { assert(!filename.empty()); assert(!_handle); - _name.clear(); clearIOFailed(); - if (s_searchSet && s_searchSet->hasFile(filename)) { + SeekableReadStream *stream = 0; + if (archive.hasFile(filename)) { debug(3, "Opening hashed: %s", filename.c_str()); - _handle = s_searchSet->openFile(filename); - } else if (s_searchSet && s_searchSet->hasFile(filename + ".")) { + stream = archive.openFile(filename); + } else if (archive.hasFile(filename + ".")) { // WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails" // sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot) debug(3, "Opening hashed: %s.", filename.c_str()); - _handle = s_searchSet->openFile(filename); - } else { - // Last resort: try the current directory - FilesystemNode file(filename); - if (file.exists() && !file.isDirectory()) - _handle = file.openForReading(); + stream = archive.openFile(filename + "."); } - if (_handle == NULL) - debug(2, "File %s not opened", filename.c_str()); - else - _name = filename; - - return _handle != NULL; + return open(stream, filename); } -bool File::open(const FilesystemNode &node) { +bool File::open(const FSNode &node) { + assert(!_handle); if (!node.exists()) { - warning("File::open: FilesystemNode does not exist"); + warning("File::open: '%s' does not exist", node.getPath().c_str()); return false; } else if (node.isDirectory()) { - warning("File::open: FilesystemNode is a directory"); + warning("File::open: '%s' is a directory", node.getPath().c_str()); return false; } - String filename(node.getName()); - - if (_handle) { - error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str()); - } + SeekableReadStream *stream = node.openForReading(); + return open(stream, node.getPath()); +} +bool File::open(SeekableReadStream *stream, const Common::String &name) { + assert(!_handle); clearIOFailed(); - _name.clear(); - - _handle = node.openForReading(); - - if (_handle == NULL) - debug(2, "File %s not found", filename.c_str()); - else - _name = filename; + if (stream) { + _handle = stream; + _name = name; + } else { + debug(2, "File::open: opening '%s' failed", name.c_str()); + } return _handle != NULL; } + bool File::exists(const String &filename) { - if (s_searchSet && s_searchSet->hasFile(filename)) { + if (SearchMan.hasFile(filename)) { return true; - } else if (s_searchSet && s_searchSet->hasFile(filename + ".")) { + } else if (SearchMan.hasFile(filename + ".")) { // WORKAROUND: Bug #1458388: "SIMON1: Game Detection fails" // sometimes instead of "GAMEPC" we get "GAMEPC." (note trailing dot) return true; - } else { - // Last resort: try the current directory - FilesystemNode file(filename); - if (file.exists() && !file.isDirectory()) - return true; } return false; @@ -217,15 +196,15 @@ bool DumpFile::open(const String &filename) { assert(!filename.empty()); assert(!_handle); - FilesystemNode node(filename); + FSNode node(filename); return open(node); } -bool DumpFile::open(const FilesystemNode &node) { +bool DumpFile::open(const FSNode &node) { assert(!_handle); if (node.isDirectory()) { - warning("DumpFile::open: FilesystemNode is a directory"); + warning("DumpFile::open: FSNode is a directory"); return false; } |