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:
parent
cd336a7d73
commit
2ce4b9d8e9
@ -1107,13 +1107,31 @@ int main( int argc, char **argv )
|
|||||||
int pos=images_pos+1;
|
int pos=images_pos+1;
|
||||||
for(;pos<arguments.argc() && !arguments.isOption(pos);++pos)
|
for(;pos<arguments.argc() && !arguments.isOption(pos);++pos)
|
||||||
{
|
{
|
||||||
// not an option so assume string is a filename.
|
std::string arg(arguments[pos]);
|
||||||
osg::Image *image = osgDB::readImageFile( arguments[pos]);
|
if (arg.find('*') != std::string::npos)
|
||||||
|
{
|
||||||
|
osgDB::DirectoryContents contents = osgDB::expandWildcardsInFilename(arg);
|
||||||
|
for (unsigned int i = 0; i < contents.size(); ++i)
|
||||||
|
{
|
||||||
|
osg::Image *image = osgDB::readImageFile( contents[i] );
|
||||||
|
|
||||||
if(image)
|
if(image)
|
||||||
{
|
{
|
||||||
imageList.push_back(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
arguments.remove(images_pos, pos-images_pos);
|
arguments.remove(images_pos, pos-images_pos);
|
||||||
|
|
||||||
|
@ -66,11 +66,18 @@ extern OSGDB_EXPORT std::string findFileInDirectory(const std::string& fileName,
|
|||||||
/** simple list of names to represent a directory's contents. */
|
/** simple list of names to represent a directory's contents. */
|
||||||
typedef std::vector<std::string> DirectoryContents;
|
typedef std::vector<std::string> DirectoryContents;
|
||||||
|
|
||||||
/** return the contents of a directory.
|
/** Return the contents of a directory.
|
||||||
* returns an empty array on any error.*/
|
* 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);
|
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 {
|
namespace FileOpResult {
|
||||||
enum Value
|
enum Value
|
||||||
|
@ -530,6 +530,39 @@ static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath)
|
|||||||
#endif // unix getDirectoryContexts
|
#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)
|
osgDB::FileOpResult::Value osgDB::copyFile(const std::string & source, const std::string & destination)
|
||||||
{
|
{
|
||||||
if (source.empty() || destination.empty())
|
if (source.empty() || destination.empty())
|
||||||
|
Loading…
Reference in New Issue
Block a user