| 424 | } |
| 425 | |
| 426 | BeLibEntry* BeLibManager::AddFile(const StringImpl& filePath, void* data, int size) |
| 427 | { |
| 428 | BP_ZONE("BeLibManager::AddFile"); |
| 429 | |
| 430 | String fileDir = GetFileDir(filePath); |
| 431 | String fileName = GetFileName(filePath); |
| 432 | |
| 433 | String fixedFileDir = FixPathAndCase(fileDir); |
| 434 | |
| 435 | AutoCrit autoCrit(mCritSect); |
| 436 | |
| 437 | BeLibFile* libFile = NULL; |
| 438 | |
| 439 | // if ((data == NULL) && (!mLibFiles.ContainsKey(fixedFileDir))) |
| 440 | // return NULL; |
| 441 | |
| 442 | BeLibFile** libFilePtr = NULL; |
| 443 | if (!mLibFiles.TryAdd(fixedFileDir, NULL, &libFilePtr)) |
| 444 | { |
| 445 | libFile = *libFilePtr; |
| 446 | } |
| 447 | else |
| 448 | { |
| 449 | libFile = new BeLibFile(); |
| 450 | *libFilePtr = libFile; |
| 451 | |
| 452 | String libPath = GetLibFilePath(filePath); |
| 453 | libFile->Init(libPath, true); |
| 454 | } |
| 455 | |
| 456 | if (libFile->mFailed) |
| 457 | return NULL; |
| 458 | |
| 459 | BeLibEntry* oldEntry = NULL; |
| 460 | if (libFile->mOldEntries.TryGetValue(fileName, &oldEntry)) |
| 461 | { |
| 462 | if (data == NULL) |
| 463 | { |
| 464 | oldEntry->mReferenced = true; |
| 465 | return oldEntry; |
| 466 | } |
| 467 | |
| 468 | delete oldEntry; |
| 469 | libFile->mOldEntries.Remove(fileName); |
| 470 | } |
| 471 | else |
| 472 | { |
| 473 | if (data == NULL) |
| 474 | return NULL; |
| 475 | } |
| 476 | |
| 477 | BeLibEntry* libEntry = NULL; |
| 478 | BeLibEntry** libEntryPtr = NULL; |
| 479 | libFile->mEntries.TryAdd(fileName, NULL, &libEntryPtr); |
| 480 | if (*libEntryPtr != NULL) |
| 481 | { |
| 482 | // It's possible that we rebuild a type (generic, probably), decide we don't have any refs so we delete the type, |
| 483 | // but then we specialize methods and then have to recreate it. Thus two entries here. |