| 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 | { |
no test coverage detected