MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / getFilePath

Function getFilePath

TheForceEngine/TFE_FileSystem/paths.cpp:333–387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331 }
332
333 bool getFilePath(const char* fileName, FilePath* outPath)
334 {
335 outPath->archive = nullptr;
336 outPath->index = INVALID_FILE;
337 outPath->path[0] = 0;
338
339 // Search for any filemappings.
340 // This is usually only used with mods and usually limited to 0-3 files.
341 const size_t mappingCount = s_fileMappings.size();
342 const FileMapping* mapping = s_fileMappings.data();
343 for (size_t i = 0; i < mappingCount; i++, mapping++)
344 {
345 // Early out if the first character doesn't match to avoid testing the entire string.
346 if (mapping->fileName[0] == tolower(fileName[0]) && strcasecmp(mapping->fileName.c_str(), fileName) == 0)
347 {
348 strcpy(outPath->path, mapping->realPath.c_str());
349 return true;
350 }
351 }
352
353 // Search in the local search paths before local archives: s_searchPaths.
354 const size_t pathCount = s_searchPaths.size();
355 const std::string* localPath = s_searchPaths.data();
356 for (size_t i = 0; i < pathCount; i++, localPath++)
357 {
358 char fullName[TFE_MAX_PATH];
359 sprintf(fullName, "%s%s", localPath->c_str(), fileName);
360
361 FileStream file;
362 if (file.exists(fullName))
363 {
364 strncpy(outPath->path, fullName, TFE_MAX_PATH);
365 return true;
366 }
367 }
368
369 // Then archives: s_localArchives.
370 const size_t archiveCount = s_localArchives.size();
371 Archive** archive = s_localArchives.data();
372 for (size_t i = 0; i < archiveCount; i++, archive++)
373 {
374 if (!(*archive)) { continue; } // Avoid crashing if an archive is null.
375
376 u32 index = (*archive)->getFileIndex(fileName);
377 if (index != INVALID_FILE)
378 {
379 outPath->archive = *archive;
380 outPath->index = index;
381 return true;
382 }
383 }
384
385 // Finally admit defeat.
386 return false;
387 }
388
389 bool insertString(char* text, const char* newFragment, const char* pattern)
390 {

Callers 15

readScriptFileTFEFunction · 0.50
loadFrameHdFunction · 0.50
getFrameFunction · 0.50
loadWaxHdFunction · 0.50
getWaxFunction · 0.50
getFunction · 0.50
getFunction · 0.50
loadSoundFileFunction · 0.50
project_loadFunction · 0.50
exportLevelFunction · 0.50
loadMidiFileFunction · 0.50
inf_loadFunction · 0.50

Calls 5

dataMethod · 0.80
c_strMethod · 0.80
sizeMethod · 0.45
existsMethod · 0.45
getFileIndexMethod · 0.45

Tested by

no test coverage detected