[3031725] FileSystemFilter destroys "://" in paths. Addresss this issue. FileSystemFilter now acts with more caution, first tries to open the file given the input path.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@801 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2010-08-23 18:52:53 +00:00
parent 9b6b99842d
commit 9d70caef0a
1 changed files with 35 additions and 12 deletions

View File

@ -119,15 +119,29 @@ public:
/** Open a new file with a given path. */ /** Open a new file with a given path. */
IOStream* Open( const char* pFile, const char* pMode = "rb") IOStream* Open( const char* pFile, const char* pMode = "rb")
{ {
ai_assert(pFile);
ai_assert(pMode);
// First try the unchanged path
IOStream* s = wrapped->Open(pFile,pMode);
if (!s) {
std::string tmp = pFile; std::string tmp = pFile;
// Currently this IOSystem is also used to open THE ONE FILE. // Try to convert between absolute and relative paths
if (tmp != src_file) {
BuildPath(tmp); BuildPath(tmp);
s = wrapped->Open(tmp,pMode);
if (!s) {
// Finally, look for typical issues with paths
// and try to correct them. This is our last
// resort.
Cleanup(tmp); Cleanup(tmp);
s = wrapped->Open(tmp,pMode);
}
} }
return wrapped->Open(tmp,pMode); return s;
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -158,7 +172,7 @@ private:
return; return;
} }
// Determine whether this is a relative path. // Determine whether this is a relative path (Windows-specific - most assets are packaged on Windows).
if (in[1] != ':') { if (in[1] != ':') {
// append base path and try // append base path and try
@ -187,9 +201,18 @@ private:
const char sep = getOsSeparator(); const char sep = getOsSeparator();
for (it = in.begin(); it != in.end(); ++it) { for (it = in.begin(); it != in.end(); ++it) {
// Exclude :// and \\, which remain untouched.
// https://sourceforge.net/tracker/?func=detail&aid=3031725&group_id=226462&atid=1067632
if ( !strncmp(&*it, "://", 3 )) {
it += 3;
continue;
}
if (it == in.begin() && !strncmp(&*it, "\\\\", 2)) {
it += 2;
continue;
}
// Both Windows and Linux accept both separators, but to avoid conflicts // Cleanup path delimiters
// or mixed seperators in a single path we're cleaning up.
if (*it == '/' || (*it) == '\\') { if (*it == '/' || (*it) == '\\') {
*it = sep; *it = sep;
@ -202,7 +225,7 @@ private:
} }
else if (*it == '%' && in.end() - it > 2) { else if (*it == '%' && in.end() - it > 2) {
// Hex sequence, common _artifact_ in URIs // Hex sequence in URIs
uint32_t tmp; uint32_t tmp;
if( 0xffffffff != (tmp = HexOctetToDecimal(&*it))) { if( 0xffffffff != (tmp = HexOctetToDecimal(&*it))) {
*it = (char)tmp; *it = (char)tmp;