bool TranslationManager::openTranslationsFile(const FSNode &node, File &inFile, int depth) { if (!node.exists() || !node.isReadable() || !node.isDirectory()) return false; // Check if we can find the file in this directory // Since File::open(FSNode) makes all the needed tests, it is not really // necessary to make them here. But it avoid printing warnings. FSNode fileNode = node.getChild("translations.dat"); if (fileNode.exists() && fileNode.isReadable() && !fileNode.isDirectory()) { if (inFile.open(fileNode)) { if (checkHeader(inFile)) return true; inFile.close(); } } // Check if we exceeded the given recursion depth if (depth - 1 == -1) return false; // Otherwise look for it in sub-directories FSList fileList; if (!node.getChildren(fileList, FSNode::kListDirectoriesOnly)) return false; for (FSList::iterator i = fileList.begin(); i != fileList.end(); ++i) { if (openTranslationsFile(*i, inFile, depth == -1 ? - 1 : depth - 1)) return true; } // Not found in this directory or its sub-directories return false; }
bool FSDirectory::hasFile(const String &name) const { if (name.empty() || !_node.isDirectory()) return false; FSNode *node = lookupCache(_fileCache, name); return node && node->exists(); }
bool File::open(const FSNode &node) { assert(!_handle); if (!node.exists()) { warning("File::open: '%s' does not exist", node.getPath().c_str()); return false; } else if (node.isDirectory()) { warning("File::open: '%s' is a directory", node.getPath().c_str()); return false; } SeekableReadStream *stream = node.createReadStream(); return open(stream, node.getPath()); }
const ArchiveMemberPtr FSDirectory::getMember(const String &name) const { if (name.empty() || !_node.isDirectory()) return ArchiveMemberPtr(); FSNode *node = lookupCache(_fileCache, name); if (!node || !node->exists()) { warning("FSDirectory::getMember: '%s' does not exist", name.c_str()); return ArchiveMemberPtr(); } else if (node->isDirectory()) { warning("FSDirectory::getMember: '%s' is a directory", name.c_str()); return ArchiveMemberPtr(); } return ArchiveMemberPtr(new FSNode(*node)); }
void SearchSet::addDirectory(const String &name, const FSNode &dir, int priority, int depth, bool flat) { if (!dir.exists() || !dir.isDirectory()) return; add(name, new FSDirectory(dir, depth, flat), priority); }