MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / GetStorage

Method GetStorage

Source/Engine/Content/Storage/ContentStorageManager.cpp:52–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50TimeSpan ContentStorageManager::UnusedDataChunksLifetime = TimeSpan::FromSeconds(10);
51
52FlaxStorageReference 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
108FlaxStorageReference ContentStorageManager::TryGetStorage(const StringView& path)
109{

Callers

nothing calls this directly

Calls 13

DeleteFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
LockChunksMethod · 0.80
IsPackageMethod · 0.80
StringViewClass · 0.50
TryGetMethod · 0.45
EndsWithMethod · 0.45
AddMethod · 0.45
LoadMethod · 0.45
RemoveMethod · 0.45
EnsureCapacityMethod · 0.45

Tested by

no test coverage detected