#include <string>
#include <vector>
+#include "gromacs/utility/directoryenumerator.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/file.h"
#include "gromacs/utility/path.h"
const char *const envName = (impl_.get() ? impl_->envName_ : NULL);
const bool bEnvIsSet = (impl_.get() ? impl_->bEnvIsSet_ : false);
std::string message(
- formatString("Library file %s not found", options.filename_));
+ formatString("Library file '%s' not found", options.filename_));
if (options.bCurrentDir_)
{
message.append(" in current dir nor");
return std::string();
}
+std::vector<DataFileInfo>
+DataFileFinder::enumerateFiles(const DataFileOptions &options) const
+{
+ // TODO: Consider if not being able to list one of the directories should
+ // really be a fatal error. Or alternatively, check somewhere else that
+ // paths in GMXLIB are valid.
+ std::vector<DataFileInfo> result;
+ std::vector<std::string>::const_iterator i;
+ if (options.bCurrentDir_)
+ {
+ std::vector<std::string> files
+ = DirectoryEnumerator::enumerateFilesWithExtension(
+ ".", options.filename_, false);
+ for (i = files.begin(); i != files.end(); ++i)
+ {
+ result.push_back(DataFileInfo(".", *i, false));
+ }
+ }
+ if (impl_.get())
+ {
+ std::vector<std::string>::const_iterator j;
+ for (j = impl_->searchPath_.begin(); j != impl_->searchPath_.end(); ++j)
+ {
+ std::vector<std::string> files
+ = DirectoryEnumerator::enumerateFilesWithExtension(
+ j->c_str(), options.filename_, false);
+ for (i = files.begin(); i != files.end(); ++i)
+ {
+ result.push_back(DataFileInfo(*j, *i, false));
+ }
+ }
+ }
+ const char *const defaultPath = getProgramContext().defaultLibraryDataPath();
+ if (defaultPath != NULL && defaultPath[0] != '\0')
+ {
+ std::vector<std::string> files
+ = DirectoryEnumerator::enumerateFilesWithExtension(
+ defaultPath, options.filename_, false);
+ for (i = files.begin(); i != files.end(); ++i)
+ {
+ result.push_back(DataFileInfo(defaultPath, *i, true));
+ }
+ }
+ if (result.empty() && options.bThrow_)
+ {
+ // TODO: Print the search path as is done in findFile().
+ std::string message(
+ formatString("Could not find any files ending on '%s' in the "
+ "current directory or the GROMACS library search path",
+ options.filename_));
+ GMX_THROW(FileIOError(message));
+ }
+ return result;
+}
+
} // namespace gmx