From Jean-Sebastien Guay, osgDB functions to expand wildcards - required to aid windows consule usage as this doesn't not automatically expand * usage.

This commit is contained in:
Robert Osfield 2010-11-01 11:06:12 +00:00
parent cd336a7d73
commit 2ce4b9d8e9
3 changed files with 65 additions and 7 deletions

View File

@ -1107,11 +1107,29 @@ int main( int argc, char **argv )
int pos=images_pos+1;
for(;pos<arguments.argc() && !arguments.isOption(pos);++pos)
{
// not an option so assume string is a filename.
osg::Image *image = osgDB::readImageFile( arguments[pos]);
if(image)
std::string arg(arguments[pos]);
if (arg.find('*') != std::string::npos)
{
imageList.push_back(image);
osgDB::DirectoryContents contents = osgDB::expandWildcardsInFilename(arg);
for (unsigned int i = 0; i < contents.size(); ++i)
{
osg::Image *image = osgDB::readImageFile( contents[i] );
if(image)
{
imageList.push_back(image);
}
}
}
else
{
// not an option so assume string is a filename.
osg::Image *image = osgDB::readImageFile( arguments[pos] );
if(image)
{
imageList.push_back(image);
}
}
}

View File

@ -66,11 +66,18 @@ extern OSGDB_EXPORT std::string findFileInDirectory(const std::string& fileName,
/** simple list of names to represent a directory's contents. */
typedef std::vector<std::string> DirectoryContents;
/** return the contents of a directory.
* returns an empty array on any error.*/
/** Return the contents of a directory.
* Return value will contain filenames only, not absolute paths.
* Returns an empty array on any error.*/
extern OSGDB_EXPORT DirectoryContents getDirectoryContents(const std::string& dirName);
/** Return the list of filenames that match the given filename with wildcards.
* Will only expand '*', and will not expand wildcards in directory, only in
* filename part of the given filename.
* Return value will contain path+filename so that if ever the above
* limitation (expanding wildcards in directory) is fixed, client code will
* still work unchanged. */
extern OSGDB_EXPORT DirectoryContents expandWildcardsInFilename(const std::string& filename);
namespace FileOpResult {
enum Value

View File

@ -530,6 +530,39 @@ static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath)
#endif // unix getDirectoryContexts
osgDB::DirectoryContents osgDB::expandWildcardsInFilename(const std::string& filename)
{
osgDB::DirectoryContents contents;
std::string dir = osgDB::getFilePath(filename);
std::string filenameOnly = filename.substr(dir.length(), std::string::npos);
std::string left = filenameOnly.substr(0, filenameOnly.find('*'));
std::string right = filenameOnly.substr(filenameOnly.find('*')+1, std::string::npos);
if (dir.empty())
dir = osgDB::getCurrentWorkingDirectory();
osgDB::DirectoryContents dirContents = osgDB::getDirectoryContents(dir);
for (unsigned int i = 0; i < dirContents.size(); ++i)
{
std::string filenameInDir = dirContents[i];
if (filenameInDir == "." ||
filenameInDir == "..")
{
continue;
}
if ((filenameInDir.find(left) == 0 || left.empty()) &&
(filenameInDir.find(right) == filenameInDir.length() - right.length() || right.empty()))
{
contents.push_back( dir + osgDB::getNativePathSeparator() + filenameInDir );
}
}
return contents;
}
osgDB::FileOpResult::Value osgDB::copyFile(const std::string & source, const std::string & destination)
{
if (source.empty() || destination.empty())