MCPcopy Create free account
hub / github.com/Snapchat/Valdi / getBundle

Method getBundle

valdi/src/valdi/runtime/Resources/ResourceManager.cpp:307–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305 bestIndex.value(),
306 allFiles.error());
307 return;
308 }
309
310 for (const auto& asset : allFiles.value()) {
311 auto bytes = BytesView(result.value().getDecompressedContent().getSource(), asset.data, asset.dataLength);
312 self->doInsertImageAssetInBundle(bundle, asset.filePath, bytes);
313 }
314 });
315}
316
317void ResourceManager::onAssetCatalogChanged(const Ref<Bundle>& bundle) {
318 _assetsManager->onAssetCatalogChanged(bundle);
319}
320
321Path ResourceManager::getImageAssetsOverrideDirectory() {
322 Path path("hotreloaded_assets");
323 std::call_once(_imageAssetOverrideDirectoryOnce, [&]() { _diskCache->remove(path); });
324 return path;
325}
326
327bool ResourceManager::isBundleLoaded(const StringBox& bundleName) {
328 Ref<Bundle> bundle;
329 {
330 std::lock_guard<Mutex> guard(_mutex);
331 const auto& it = _bundleByName.find(bundleName);
332 if (it == _bundleByName.end()) {
333 return false;
334 }
335 bundle = it->second;
336 }
337 // The Bundle mutex is held for the whole archive decompression while the bundle initializes.
338 return !bundle->hasRemoteArchiveNeedingLoad();
339}
340
341bool ResourceManager::bundleHasRemoteSources(const StringBox& bundleName) {
342 return getBundle(bundleName)->hasRemoteArchive();
343}
344
345bool ResourceManager::bundleHasRemoteAssets(const StringBox& bundleName) {
346 return getBundle(bundleName)->hasRemoteAssets();
347}
348
349Ref<Bundle> ResourceManager::getBundle(const StringBox& bundleName) {
350 std::unique_lock<Mutex> lock(_mutex);
351 const auto& it = _bundleByName.find(bundleName);
352 if (it != _bundleByName.end()) {
353 return it->second;
354 }
355
356 VALDI_TRACE_META("Valdi.loadBundle", bundleName);
357 snap::utils::time::StopWatch sw;
358 sw.start();
359
360 auto bundleInitializer = registerBundle(bundleName);
361 auto inlineAssetsEnabled = _inlineAssetsEnabled;
362
363 // Snapshot the settings while we still hold _mutex. getArchiveForModule runs below while the
364 // BundleInitializer holds the Bundle's mutex; it must not take _mutex itself, or it would invert

Callers 15

warmUpBundlesMethod · 0.95
hotReloadMethod · 0.80
TEST_PFunction · 0.80
TESTFunction · 0.80
getAssetMethod · 0.80
getModuleEntryMethod · 0.80
updateResourcesMethod · 0.80
operator()Method · 0.80
initializeBundleMethod · 0.80
onAssetCatalogChangedMethod · 0.80

Calls 11

containsEntryMethod · 0.80
endMethod · 0.65
startMethod · 0.65
errorMethod · 0.65
valueMethod · 0.65
findMethod · 0.45
emptyMethod · 0.45
unlockMethod · 0.45
getEntryMethod · 0.45
elapsedMethod · 0.45

Tested by 3

hotReloadMethod · 0.64
TEST_PFunction · 0.64
TESTFunction · 0.64