----------------------------------------------------------------------------- TODO: wow really shouldn't be adding everything to the string table, use the string class!
| 440 | //----------------------------------------------------------------------------- |
| 441 | // TODO: wow really shouldn't be adding everything to the string table, use the string class! |
| 442 | StringTableEntry Platform::makeRelativePathName(const char *path, const char *to) |
| 443 | { |
| 444 | // Make sure 'to' is a proper absolute path terminated with a forward slash. |
| 445 | |
| 446 | char buffer[ 2048 ]; |
| 447 | if( !to ) |
| 448 | { |
| 449 | dSprintf( buffer, sizeof( buffer ), "%s/", Platform::getMainDotCsDir() ); |
| 450 | to = buffer; |
| 451 | } |
| 452 | else if( !Platform::isFullPath( to ) ) |
| 453 | { |
| 454 | dSprintf( buffer, sizeof( buffer ), "%s/%s/", Platform::getMainDotCsDir(), to ); |
| 455 | makeCleanPathInPlace( buffer ); |
| 456 | to = buffer; |
| 457 | } |
| 458 | else if( to[ dStrlen( to ) - 1 ] != '/' ) |
| 459 | { |
| 460 | U32 length = getMin( (U32)dStrlen( to ), sizeof( buffer ) - 2 ); |
| 461 | dMemcpy( buffer, to, length ); |
| 462 | buffer[ length ] = '/'; |
| 463 | buffer[ length + 1 ] = '\0'; |
| 464 | to = buffer; |
| 465 | } |
| 466 | |
| 467 | // If 'path' isn't absolute, make it now. Let's us use a single |
| 468 | // absolute/absolute merge path from here on. |
| 469 | |
| 470 | char buffer2[ 1024 ]; |
| 471 | if( !Platform::isFullPath( path ) ) |
| 472 | { |
| 473 | dSprintf( buffer2, sizeof( buffer2 ), "%s/%s", Platform::getMainDotCsDir(), path ); |
| 474 | makeCleanPathInPlace( buffer2 ); |
| 475 | path = buffer2; |
| 476 | } |
| 477 | |
| 478 | // First, find the common prefix and see where 'path' branches off from 'to'. |
| 479 | |
| 480 | const char *pathPtr, *toPtr, *branch = path; |
| 481 | for(pathPtr = path, toPtr = to;*pathPtr && *toPtr && dTolower(*pathPtr) == dTolower(*toPtr);++pathPtr, ++toPtr) |
| 482 | { |
| 483 | if(*pathPtr == '/') |
| 484 | branch = pathPtr; |
| 485 | } |
| 486 | |
| 487 | // If there's no common part, the two paths are on different drives and |
| 488 | // there's nothing we can do. |
| 489 | |
| 490 | if( pathPtr == path ) |
| 491 | return StringTable->insert( path ); |
| 492 | |
| 493 | // If 'path' and 'to' are identical (minus trailing slash or so), we can just return './'. |
| 494 | |
| 495 | else if((*pathPtr == 0 || (*pathPtr == '/' && *(pathPtr + 1) == 0)) && |
| 496 | (*toPtr == 0 || (*toPtr == '/' && *(toPtr + 1) == 0))) |
| 497 | { |
| 498 | char* bufPtr = buffer; |
| 499 | *bufPtr ++ = '.'; |