From 651a7845fc01fbfc7d5ab13bfed0e87c9ab8ed6e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 9 Mar 2011 11:13:12 +0000 Subject: [PATCH] From Sukender, "I fixed the writing but never thought about the reading part... Here is the fix for reading path containing %23 (= '#') characters." --- src/osgPlugins/dae/ReaderWriterDAE.cpp | 23 +++++++++++++++++++++++ src/osgPlugins/dae/ReaderWriterDAE.h | 3 ++- src/osgPlugins/dae/daeRMaterials.cpp | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/dae/ReaderWriterDAE.cpp b/src/osgPlugins/dae/ReaderWriterDAE.cpp index 9226a2f6d..c1151d664 100644 --- a/src/osgPlugins/dae/ReaderWriterDAE.cpp +++ b/src/osgPlugins/dae/ReaderWriterDAE.cpp @@ -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. diff --git a/src/osgPlugins/dae/ReaderWriterDAE.h b/src/osgPlugins/dae/ReaderWriterDAE.h index 8fab8039b..5bf4ec8f7 100644 --- a/src/osgPlugins/dae/ReaderWriterDAE.h +++ b/src/osgPlugins/dae/ReaderWriterDAE.h @@ -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; }; diff --git a/src/osgPlugins/dae/daeRMaterials.cpp b/src/osgPlugins/dae/daeRMaterials.cpp index d616fb2c1..c46c98e68 100644 --- a/src/osgPlugins/dae/daeRMaterials.cpp +++ b/src/osgPlugins/dae/daeRMaterials.cpp @@ -12,6 +12,7 @@ */ #include "daeReader.h" +#include "ReaderWriterDAE.h" #include #include @@ -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;