Пример #1
0
void DirectoryArchive::forEachFile (VisitorFunc visitor, const std::string& root)
{
	std::vector<Directory*> dirs;
	UnixPath path(m_root);
	path.push(root);
	dirs.push_back(directory_open(path));

	while (!dirs.empty() && directory_good(dirs.back())) {
		const char *name = directory_read_and_increment(dirs.back());

		if (name == 0) {
			directory_close(dirs.back());
			dirs.pop_back();
			path.pop();
		} else if (!string_equal(name, ".") && !string_equal(name, "..")) {
			path.push_filename(name);

			bool is_directory = file_is_directory(path);

			if (!is_directory)
				visitor.file(os::makeRelative(path, m_root));

			path.pop();

			if (is_directory) {
				path.push(name);

				if (!visitor.directory(os::makeRelative(path, m_root), dirs.size()))
					dirs.push_back(directory_open(path));
				else
					path.pop();
			}
		}
	}
}
Пример #2
0
void DirectoryArchive::forEachFile(VisitorFunc visitor, const std::string& root) {
	// Initialise the search's starting point
	fs::path start(_root + root);

	if (!fs::exists(start)) {
		return;
	}

	// For cutting off the base path
	std::size_t rootLen = _root.length();

	typedef fs::recursive_directory_iterator DirIter;
	for (fs::recursive_directory_iterator it(start); it != fs::recursive_directory_iterator(); ++it)
	{
		// Get the candidate
		const fs::path& candidate = *it;
        std::string candidateStr = os::string_from_path(candidate);

		if (fs::is_directory(candidate))
		{
			// Check if we should traverse further
			if (visitor.directory(candidateStr.substr(rootLen), it.level()+1))
			{
				// Visitor returned true, prevent going deeper into it
				it.no_push();
			}
		}
		else
		{
			// File
			visitor.file(candidateStr.substr(rootLen));
		}
	}
}
Пример #3
0
  void forEachFile(VisitorFunc visitor, const char* root)
  {
    if(root[0] == '\0')
    {
      if(visitor.directory("textures/", 1))
        return;
    }
    else if(strcmp(root, "textures/") != 0)
    {
      return;
    }

    for(files_t::iterator i = m_files.begin(); i != m_files.end(); ++i)
      visitor.file(i->first.c_str());
  }