| 50 | TimeSpan ContentStorageManager::UnusedDataChunksLifetime = TimeSpan::FromSeconds(10); |
| 51 | |
| 52 | FlaxStorageReference ContentStorageManager::GetStorage(const StringView& path, bool loadIt) |
| 53 | { |
| 54 | Locker.Lock(); |
| 55 | |
| 56 | // Try fast lookup |
| 57 | FlaxStorage* storage; |
| 58 | if (!StorageMap.TryGet(path, storage)) |
| 59 | { |
| 60 | // Detect storage type and create object |
| 61 | const bool isPackage = path.EndsWith(StringView(PACKAGE_FILES_EXTENSION)); |
| 62 | if (isPackage) |
| 63 | { |
| 64 | auto package = New<FlaxPackage>(path); |
| 65 | Packages.Add(package); |
| 66 | storage = package; |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | auto file = New<FlaxFile>(path); |
| 71 | Files.Add(file); |
| 72 | storage = file; |
| 73 | } |
| 74 | |
| 75 | // Register storage container |
| 76 | StorageMap.Add(path, storage); |
| 77 | } |
| 78 | |
| 79 | // Build reference (before releasing the lock so ContentStorageSystem::Job won't delete it when running from async thread) |
| 80 | FlaxStorageReference result(storage); |
| 81 | |
| 82 | Locker.Unlock(); |
| 83 | |
| 84 | if (loadIt) |
| 85 | { |
| 86 | // Initialize storage container |
| 87 | storage->LockChunks(); |
| 88 | const bool loadFailed = storage->Load(); |
| 89 | storage->UnlockChunks(); |
| 90 | if (loadFailed) |
| 91 | { |
| 92 | LOG(Error, "Failed to load {0}.", path); |
| 93 | Locker.Lock(); |
| 94 | StorageMap.Remove(path); |
| 95 | if (storage->IsPackage()) |
| 96 | Packages.Remove((FlaxPackage*)storage); |
| 97 | else |
| 98 | Files.Remove((FlaxFile*)storage); |
| 99 | Locker.Unlock(); |
| 100 | result = nullptr; |
| 101 | Delete(storage); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return result; |
| 106 | } |
| 107 | |
| 108 | FlaxStorageReference ContentStorageManager::TryGetStorage(const StringView& path) |
| 109 | { |
nothing calls this directly
no test coverage detected