| 2316 | //----------------------------------------------------------------------------- |
| 2317 | |
| 2318 | void collapsePath(char* pDstPath, U32 size, const char* pSrcPath, const char* pWorkingDirectoryHint) |
| 2319 | { |
| 2320 | // Check path against expandos. If there are multiple matches, choose the |
| 2321 | // expando that produces the shortest relative path. |
| 2322 | |
| 2323 | char pathBuffer[2048]; |
| 2324 | |
| 2325 | // Fetch expando count. |
| 2326 | const U32 expandoCount = getPathExpandoCount(); |
| 2327 | |
| 2328 | // Iterate expandos. |
| 2329 | U32 expandoRelativePathLength = U32_MAX; |
| 2330 | for (U32 expandoIndex = 0; expandoIndex < expandoCount; ++expandoIndex) |
| 2331 | { |
| 2332 | // Fetch expando value (path). |
| 2333 | StringTableEntry expandoValue = getPathExpandoValue(expandoIndex); |
| 2334 | |
| 2335 | // Skip if not the base path. |
| 2336 | if (!isBasePath(pSrcPath, expandoValue)) |
| 2337 | continue; |
| 2338 | |
| 2339 | // Fetch path relative to expando path. |
| 2340 | StringTableEntry relativePath = Platform::makeRelativePathName(pSrcPath, expandoValue); |
| 2341 | |
| 2342 | // If the relative path is simply a period |
| 2343 | if (relativePath[0] == '.') |
| 2344 | relativePath++; |
| 2345 | |
| 2346 | if (dStrlen(relativePath) > expandoRelativePathLength) |
| 2347 | { |
| 2348 | // This expando covers less of the path than any previous one found. |
| 2349 | // We will keep the previous one. |
| 2350 | continue; |
| 2351 | } |
| 2352 | |
| 2353 | // Keep track of the relative path length |
| 2354 | expandoRelativePathLength = dStrlen(relativePath); |
| 2355 | |
| 2356 | // Fetch expando key (name). |
| 2357 | StringTableEntry expandoName = getPathExpandoKey(expandoIndex); |
| 2358 | |
| 2359 | // Format against expando. |
| 2360 | dSprintf(pathBuffer, sizeof(pathBuffer), "^%s/%s", expandoName, relativePath); |
| 2361 | } |
| 2362 | |
| 2363 | // Check if we've found a suitable expando |
| 2364 | if (expandoRelativePathLength != U32_MAX) |
| 2365 | { |
| 2366 | // Strip repeat slashes. |
| 2367 | Con::stripRepeatSlashes(pDstPath, pathBuffer, size); |
| 2368 | |
| 2369 | return; |
| 2370 | } |
| 2371 | |
| 2372 | // Fetch the working directory. |
| 2373 | StringTableEntry workingDirectory = pWorkingDirectoryHint != NULL ? pWorkingDirectoryHint : Platform::getCurrentDirectory(); |
| 2374 | |
| 2375 | // Fetch path relative to current directory. |
no test coverage detected