| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | #include <osgDB/FileUtils> |
|---|
| 13 | #include <osgDB/FileNameUtils> |
|---|
| 14 | #include <osg/Version> |
|---|
| 15 | |
|---|
| 16 | #include <osgDB/PluginQuery> |
|---|
| 17 | |
|---|
| 18 | using namespace osgDB; |
|---|
| 19 | |
|---|
| 20 | FileNameList osgDB::listAllAvailablePlugins() |
|---|
| 21 | { |
|---|
| 22 | FileNameList pluginFiles; |
|---|
| 23 | std::string validExtension = ADDQUOTES(OSG_PLUGIN_EXTENSION); |
|---|
| 24 | |
|---|
| 25 | std::string pluginDirectoryName = std::string("osgPlugins-")+std::string(osgGetVersion()); |
|---|
| 26 | std::string fullPath = osgDB::findLibraryFile(pluginDirectoryName); |
|---|
| 27 | if (!fullPath.empty()) |
|---|
| 28 | { |
|---|
| 29 | osgDB::DirectoryContents contents = getDirectoryContents(fullPath); |
|---|
| 30 | for(DirectoryContents::iterator itr = contents.begin(); |
|---|
| 31 | itr != contents.end(); |
|---|
| 32 | ++itr) |
|---|
| 33 | { |
|---|
| 34 | std::string::size_type pos = itr->find("osgdb_"); |
|---|
| 35 | if (pos==std::string::npos) |
|---|
| 36 | { |
|---|
| 37 | continue; |
|---|
| 38 | } |
|---|
| 39 | std::string ext = getFileExtensionIncludingDot(*itr); |
|---|
| 40 | if (ext != validExtension) |
|---|
| 41 | { |
|---|
| 42 | continue; |
|---|
| 43 | } |
|---|
| 44 | pluginFiles.push_back(fullPath + std::string("/")+*itr); |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | return pluginFiles; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | bool osgDB::queryPlugin(const std::string& fileName, ReaderWriterInfoList& infoList) |
|---|
| 53 | { |
|---|
| 54 | typedef std::set<const ReaderWriter*> ReaderWriterSet; |
|---|
| 55 | ReaderWriterSet previouslyLoadedReaderWriters; |
|---|
| 56 | |
|---|
| 57 | const Registry::ReaderWriterList& rwList = osgDB::Registry::instance()->getReaderWriterList(); |
|---|
| 58 | for(Registry::ReaderWriterList::const_iterator itr = rwList.begin(); |
|---|
| 59 | itr != rwList.end(); |
|---|
| 60 | ++itr) |
|---|
| 61 | { |
|---|
| 62 | const ReaderWriter* rw = itr->get(); |
|---|
| 63 | previouslyLoadedReaderWriters.insert(rw); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | if (osgDB::Registry::instance()->loadLibrary(fileName)) |
|---|
| 67 | { |
|---|
| 68 | const Registry::ReaderWriterList& rwList = osgDB::Registry::instance()->getReaderWriterList(); |
|---|
| 69 | for(Registry::ReaderWriterList::const_iterator itr = rwList.begin(); |
|---|
| 70 | itr != rwList.end(); |
|---|
| 71 | ++itr) |
|---|
| 72 | { |
|---|
| 73 | const ReaderWriter* rw = itr->get(); |
|---|
| 74 | |
|---|
| 75 | if (previouslyLoadedReaderWriters.count(rw)==0) |
|---|
| 76 | { |
|---|
| 77 | osg::ref_ptr<ReaderWriterInfo> rwi = new ReaderWriterInfo; |
|---|
| 78 | rwi->plugin = fileName; |
|---|
| 79 | rwi->description = rw->className(); |
|---|
| 80 | rwi->protocols = rw->supportedProtocols(); |
|---|
| 81 | rwi->extensions = rw->supportedExtensions(); |
|---|
| 82 | rwi->options = rw->supportedOptions(); |
|---|
| 83 | rwi->features = rw->supportedFeatures(); |
|---|
| 84 | |
|---|
| 85 | infoList.push_back(rwi.get()); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | osgDB::Registry::instance()->closeLibrary(fileName); |
|---|
| 90 | return true; |
|---|
| 91 | } |
|---|
| 92 | else |
|---|
| 93 | { |
|---|
| 94 | return false; |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | static std::string padwithspaces(const std::string& str, unsigned int padLength) |
|---|
| 99 | { |
|---|
| 100 | std::string newStr(str); |
|---|
| 101 | while(newStr.length()<padLength) newStr.push_back(' '); |
|---|
| 102 | return newStr; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | bool osgDB::outputPluginDetails(std::ostream& out, const std::string& fileName) |
|---|
| 106 | { |
|---|
| 107 | osgDB::ReaderWriterInfoList infoList; |
|---|
| 108 | if (osgDB::queryPlugin(fileName, infoList)) |
|---|
| 109 | { |
|---|
| 110 | out<<"Plugin "<<fileName<<std::endl; |
|---|
| 111 | out<<"{"<<std::endl; |
|---|
| 112 | |
|---|
| 113 | for(osgDB::ReaderWriterInfoList::iterator rwi_itr = infoList.begin(); |
|---|
| 114 | rwi_itr != infoList.end(); |
|---|
| 115 | ++rwi_itr) |
|---|
| 116 | { |
|---|
| 117 | osgDB::ReaderWriterInfo& info = *(*rwi_itr); |
|---|
| 118 | out<<" ReaderWriter : "<<info.description<<std::endl; |
|---|
| 119 | out<<" {"<<std::endl; |
|---|
| 120 | out<<" features : "; |
|---|
| 121 | osgDB::ReaderWriter::FeatureList fl = ReaderWriter::featureAsString(info.features); |
|---|
| 122 | osgDB::ReaderWriter::FeatureList::iterator fl_itr; |
|---|
| 123 | for(fl_itr = fl.begin(); |
|---|
| 124 | fl_itr != fl.end(); |
|---|
| 125 | ++fl_itr) |
|---|
| 126 | { |
|---|
| 127 | out << *fl_itr << " "; |
|---|
| 128 | } |
|---|
| 129 | out << std::endl; |
|---|
| 130 | |
|---|
| 131 | unsigned int longestOptionLength = 0; |
|---|
| 132 | osgDB::ReaderWriter::FormatDescriptionMap::iterator fdm_itr; |
|---|
| 133 | for(fdm_itr = info.protocols.begin(); |
|---|
| 134 | fdm_itr != info.protocols.end(); |
|---|
| 135 | ++fdm_itr) |
|---|
| 136 | { |
|---|
| 137 | if (fdm_itr->first.length()>longestOptionLength) longestOptionLength = fdm_itr->first.length(); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | for(fdm_itr = info.extensions.begin(); |
|---|
| 141 | fdm_itr != info.extensions.end(); |
|---|
| 142 | ++fdm_itr) |
|---|
| 143 | { |
|---|
| 144 | if (fdm_itr->first.length()>longestOptionLength) longestOptionLength = fdm_itr->first.length(); |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | for(fdm_itr = info.options.begin(); |
|---|
| 148 | fdm_itr != info.options.end(); |
|---|
| 149 | ++fdm_itr) |
|---|
| 150 | { |
|---|
| 151 | if (fdm_itr->first.length()>longestOptionLength) longestOptionLength = fdm_itr->first.length(); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | unsigned int padLength = longestOptionLength+4; |
|---|
| 155 | |
|---|
| 156 | for(fdm_itr = info.protocols.begin(); |
|---|
| 157 | fdm_itr != info.protocols.end(); |
|---|
| 158 | ++fdm_itr) |
|---|
| 159 | { |
|---|
| 160 | out<<" protocol : "<<padwithspaces(fdm_itr->first, padLength)<<fdm_itr->second<<std::endl; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | for(fdm_itr = info.extensions.begin(); |
|---|
| 164 | fdm_itr != info.extensions.end(); |
|---|
| 165 | ++fdm_itr) |
|---|
| 166 | { |
|---|
| 167 | out<<" extensions : ."<<padwithspaces(fdm_itr->first, padLength-1)<<fdm_itr->second<<std::endl; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | for(fdm_itr = info.options.begin(); |
|---|
| 171 | fdm_itr != info.options.end(); |
|---|
| 172 | ++fdm_itr) |
|---|
| 173 | { |
|---|
| 174 | out<<" options : "<<padwithspaces(fdm_itr->first, padLength)<<fdm_itr->second<<std::endl; |
|---|
| 175 | } |
|---|
| 176 | out<<" }"<<std::endl; |
|---|
| 177 | } |
|---|
| 178 | out<<"}"<<std::endl<<std::endl; |
|---|
| 179 | return true; |
|---|
| 180 | } |
|---|
| 181 | else |
|---|
| 182 | { |
|---|
| 183 | out<<"Plugin "<<fileName<<" not found."<<std::endl; |
|---|
| 184 | return false; |
|---|
| 185 | } |
|---|
| 186 | } |
|---|