From Sukender, "I fixed the writing but never thought about the reading part...

Here is the fix for reading path containing %23 (= '#') characters."
This commit is contained in:
Robert Osfield
2011-03-09 11:13:12 +00:00
parent 5447e70b68
commit 651a7845fc
3 changed files with 27 additions and 2 deletions

View File

@@ -197,6 +197,17 @@ static void replace(std::string & str, const char from, const std::string & to)
}
}
static void replace(std::string & str, const std::string & from, const std::string & to)
{
// Replace for all occurences
std::size_t lenFrom = from.size();
std::size_t lenTo = to.size();
for(std::string::size_type pos=str.find(from); pos!=std::string::npos; pos = str.find(from, pos+lenTo))
{
str.replace(pos, lenFrom, to);
}
}
std::string ReaderWriterDAE::ConvertFilePathToColladaCompatibleURI(const std::string& FilePath)
{
#ifdef OSG_USE_UTF8_FILENAME
@@ -232,6 +243,18 @@ std::string ReaderWriterDAE::ConvertFilePathToColladaCompatibleURI(const std::st
return path;
}
std::string ReaderWriterDAE::ConvertColladaCompatibleURIToFilePath(const std::string& uri)
{
// Reciprocal of ConvertFilePathToColladaCompatibleURI()
#ifdef OSG_USE_UTF8_FILENAME
std::string path( cdom::uriToNativePath( uri ) );
#else
std::string path( osgDB::convertStringFromCurrentCodePageToUTF8( cdom::uriToNativePath(uri) ) );
#endif
replace(path, "%23", "#");
return path;
}
///////////////////////////////////////////////////////////////////////////
// Add ourself to the Registry to instantiate the reader/writer.

View File

@@ -37,7 +37,8 @@ public:
WriteResult writeNode(const osg::Node&, const std::string&, const Options*) const;
static std::string ConvertFilePathToColladaCompatibleURI(const std::string& FilePath);
static std::string ConvertColladaCompatibleURIToFilePath(const std::string& uri);
private:
mutable OpenThreads::ReentrantMutex _serializerMutex;
};

View File

@@ -12,6 +12,7 @@
*/
#include "daeReader.h"
#include "ReaderWriterDAE.h"
#include <dae.h>
#include <dae/daeSIDResolver.h>
@@ -884,7 +885,7 @@ std::string daeReader::processImagePath(const domImage* pDomImage) const
{
std::string path = pDomImage->getInit_from()->getValue().pathDir() +
pDomImage->getInit_from()->getValue().pathFile();
path = cdom::uriToNativePath(path);
path = ReaderWriterDAE::ConvertColladaCompatibleURIToFilePath(path);
if (path.empty())
{
OSG_WARN << "Unable to get path from URI." << std::endl;