MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / collapsePath

Function collapsePath

Engine/source/console/console.cpp:2237–2306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2235//-----------------------------------------------------------------------------
2236
2237void collapsePath(char* pDstPath, U32 size, const char* pSrcPath, const char* pWorkingDirectoryHint)
2238{
2239 // Check path against expandos. If there are multiple matches, choose the
2240 // expando that produces the shortest relative path.
2241
2242 char pathBuffer[2048];
2243
2244 // Fetch expando count.
2245 const U32 expandoCount = getPathExpandoCount();
2246
2247 // Iterate expandos.
2248 U32 expandoRelativePathLength = U32_MAX;
2249 for (U32 expandoIndex = 0; expandoIndex < expandoCount; ++expandoIndex)
2250 {
2251 // Fetch expando value (path).
2252 StringTableEntry expandoValue = getPathExpandoValue(expandoIndex);
2253
2254 // Skip if not the base path.
2255 if (!isBasePath(pSrcPath, expandoValue))
2256 continue;
2257
2258 // Fetch path relative to expando path.
2259 StringTableEntry relativePath = Platform::makeRelativePathName(pSrcPath, expandoValue);
2260
2261 // If the relative path is simply a period
2262 if (relativePath[0] == '.')
2263 relativePath++;
2264
2265 if (dStrlen(relativePath) > expandoRelativePathLength)
2266 {
2267 // This expando covers less of the path than any previous one found.
2268 // We will keep the previous one.
2269 continue;
2270 }
2271
2272 // Keep track of the relative path length
2273 expandoRelativePathLength = dStrlen(relativePath);
2274
2275 // Fetch expando key (name).
2276 StringTableEntry expandoName = getPathExpandoKey(expandoIndex);
2277
2278 // Format against expando.
2279 dSprintf(pathBuffer, sizeof(pathBuffer), "^%s/%s", expandoName, relativePath);
2280 }
2281
2282 // Check if we've found a suitable expando
2283 if (expandoRelativePathLength != U32_MAX)
2284 {
2285 // Strip repeat slashes.
2286 Con::stripRepeatSlashes(pDstPath, pathBuffer, size);
2287
2288 return;
2289 }
2290
2291 // Fetch the working directory.
2292 StringTableEntry workingDirectory = pWorkingDirectoryHint != NULL ? pWorkingDirectoryHint : Platform::getCurrentDirectory();
2293
2294 // Fetch path relative to current directory.

Callers 1

collapseAssetFilePathMethod · 0.85

Calls 7

getPathExpandoCountFunction · 0.85
getPathExpandoValueFunction · 0.85
isBasePathFunction · 0.85
getPathExpandoKeyFunction · 0.85
dSprintfFunction · 0.85
stripRepeatSlashesFunction · 0.85
dStrlenFunction · 0.50

Tested by

no test coverage detected