|
12 | 12 | #include "nbl/system/CArchiveLoaderTar.h" |
13 | 13 | #include "nbl/system/CMountDirectoryArchive.h" |
14 | 14 |
|
15 | | -#include <array> |
16 | | - |
17 | 15 | using namespace nbl; |
18 | 16 | using namespace nbl::system; |
19 | 17 |
|
20 | | -namespace |
21 | | -{ |
22 | | -constexpr std::array<const char*, 4> builtinMountPoints = { "nbl/builtin", "nbl/video", "spirv", "boost" }; |
23 | | -} |
24 | | - |
25 | 18 | ISystem::ISystem(core::smart_refctd_ptr<ISystem::ICaller>&& caller) : m_dispatcher(std::move(caller)) |
26 | 19 | { |
27 | 20 | addArchiveLoader(core::make_smart_refctd_ptr<CArchiveLoaderZip>(nullptr)); |
28 | 21 | addArchiveLoader(core::make_smart_refctd_ptr<CArchiveLoaderTar>(nullptr)); |
29 | 22 |
|
| 23 | + // Builtins still live in the main archive cache for normal path resolution. |
| 24 | + // This separate bootstrap tracking is only for exact unmounting and regression tests. |
30 | 25 | #ifdef NBL_EMBED_BUILTIN_RESOURCES |
31 | | - mount(core::make_smart_refctd_ptr<nbl::builtin::CArchive>(nullptr)); |
32 | | - mount(core::make_smart_refctd_ptr<spirv::builtin::CArchive>(nullptr)); |
33 | | - mount(core::make_smart_refctd_ptr<boost::builtin::CArchive>(nullptr)); |
34 | | - mount(core::make_smart_refctd_ptr<nbl::devicegen::builtin::CArchive>(nullptr)); |
| 26 | + mountBuiltin(core::make_smart_refctd_ptr<nbl::builtin::CArchive>(nullptr)); |
| 27 | + mountBuiltin(core::make_smart_refctd_ptr<spirv::builtin::CArchive>(nullptr)); |
| 28 | + mountBuiltin(core::make_smart_refctd_ptr<boost::builtin::CArchive>(nullptr)); |
| 29 | + mountBuiltin(core::make_smart_refctd_ptr<nbl::devicegen::builtin::CArchive>(nullptr)); |
35 | 30 | #else |
36 | 31 | // TODO: absolute default entry paths? we should do something with it |
37 | | - mount(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(NBL_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "nbl/builtin"); |
38 | | - mount(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(SPIRV_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "spirv"); |
39 | | - mount(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(BOOST_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "boost"); |
40 | | - mount(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(DEVICEGEN_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "nbl/video"); |
| 32 | + mountBuiltin(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(NBL_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "nbl/builtin"); |
| 33 | + mountBuiltin(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(SPIRV_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "spirv"); |
| 34 | + mountBuiltin(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(BOOST_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "boost"); |
| 35 | + mountBuiltin(core::make_smart_refctd_ptr<nbl::system::CMountDirectoryArchive>(DEVICEGEN_BUILTIN_RESOURCES_DIRECTORY_PATH, nullptr, this), "nbl/video"); |
41 | 36 | #endif |
42 | 37 | } |
43 | 38 |
|
@@ -328,32 +323,41 @@ bool ISystem::ICaller::flushMapping(IFile* file, size_t offset, size_t size) |
328 | 323 | } |
329 | 324 |
|
330 | 325 | void ISystem::unmountBuiltins() { |
| 326 | + for (auto& mount : m_builtinMounts) |
| 327 | + unmount(mount.archive.get(), mount.pathAlias); |
| 328 | + m_builtinMounts.clear(); |
| 329 | +} |
331 | 330 |
|
332 | | - auto removeByKey = [&, this](const char* s) { |
333 | | - auto range = m_cachedArchiveFiles.findRange(s); |
334 | | - |
335 | | - std::vector<core::smart_refctd_ptr<IFileArchive>> items_to_remove = {}; //is it always just 1 item? |
336 | | - for (auto it = range.begin(); it != range.end(); ++it) |
337 | | - { |
338 | | - items_to_remove.push_back(it->second); |
339 | | - } |
340 | | - for (size_t i = 0; i < items_to_remove.size(); i++) |
341 | | - { |
342 | | - m_cachedArchiveFiles.removeObject(items_to_remove[i], s); |
343 | | - } |
344 | | - }; |
| 331 | +bool ISystem::areBuiltinsMounted() const |
| 332 | +{ |
| 333 | + return !m_builtinMounts.empty() && getMountedBuiltinArchiveCount() == m_builtinMounts.size(); |
| 334 | +} |
345 | 335 |
|
346 | | - for (const auto* mountPoint : builtinMountPoints) |
347 | | - removeByKey(mountPoint); |
| 336 | +size_t ISystem::getMountedBuiltinArchiveCount() const |
| 337 | +{ |
| 338 | + size_t retval = 0ull; |
| 339 | + for (const auto& mount : m_builtinMounts) |
| 340 | + retval += size_t(isBuiltinMounted(mount)); |
| 341 | + return retval; |
348 | 342 | } |
349 | 343 |
|
350 | | -bool ISystem::areBuiltinsMounted() const |
| 344 | +void ISystem::mountBuiltin(core::smart_refctd_ptr<IFileArchive>&& archive, const system::path& pathAlias) |
351 | 345 | { |
352 | | - for (const auto* mountPoint : builtinMountPoints) |
353 | | - if (!isDirectory(path(mountPoint))) |
354 | | - return false; |
| 346 | + auto tracked = archive; |
| 347 | + mount(std::move(archive), pathAlias); |
| 348 | + m_builtinMounts.push_back({ std::move(tracked), pathAlias }); |
| 349 | +} |
355 | 350 |
|
356 | | - return true; |
| 351 | +bool ISystem::isBuiltinMounted(const SBuiltinMount& mount) const |
| 352 | +{ |
| 353 | + const auto lookupKey = mount.pathAlias.empty() ? mount.archive->getDefaultAbsolutePath() : mount.pathAlias; |
| 354 | + const auto range = m_cachedArchiveFiles.findRange(lookupKey); |
| 355 | + for (auto it = range.begin(); it != range.end(); ++it) |
| 356 | + { |
| 357 | + if (it->second.get() == mount.archive.get()) |
| 358 | + return true; |
| 359 | + } |
| 360 | + return false; |
357 | 361 | } |
358 | 362 |
|
359 | 363 | #ifdef _NBL_PLATFORM_WINDOWS_ |
|
0 commit comments