| 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 | |
| 317 | void ResourceManager::onAssetCatalogChanged(const Ref<Bundle>& bundle) { |
| 318 | _assetsManager->onAssetCatalogChanged(bundle); |
| 319 | } |
| 320 | |
| 321 | Path ResourceManager::getImageAssetsOverrideDirectory() { |
| 322 | Path path("hotreloaded_assets"); |
| 323 | std::call_once(_imageAssetOverrideDirectoryOnce, [&]() { _diskCache->remove(path); }); |
| 324 | return path; |
| 325 | } |
| 326 | |
| 327 | bool 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 | |
| 341 | bool ResourceManager::bundleHasRemoteSources(const StringBox& bundleName) { |
| 342 | return getBundle(bundleName)->hasRemoteArchive(); |
| 343 | } |
| 344 | |
| 345 | bool ResourceManager::bundleHasRemoteAssets(const StringBox& bundleName) { |
| 346 | return getBundle(bundleName)->hasRemoteAssets(); |
| 347 | } |
| 348 | |
| 349 | Ref<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 |