1
+ #include " nbl/system/IFileArchive.h"
2
+
3
+ #include " nbl/system/IFile.h"
4
+
5
+ namespace nbl ::system {
6
+
7
+
8
+
9
+ class CMountDirectoryArchive : public IFileArchive
10
+ {
11
+ ISystem* m_system;
12
+
13
+ public:
14
+ inline CMountDirectoryArchive (path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, ISystem* system) :
15
+ IFileArchive(std::move(_defaultAbsolutePath), std::move(logger))
16
+ {
17
+ m_system = system;
18
+ }
19
+
20
+ core::smart_refctd_ptr<IFile> getFile (const path& pathRelativeToArchive, const std::string_view& password) override
21
+ {
22
+ {
23
+ // std::unique_lock(itemMutex); already inside `getItemFromPath`
24
+ if (!getItemFromPath (pathRelativeToArchive))
25
+ return nullptr ;
26
+ }
27
+ system::ISystem::future_t <core::smart_refctd_ptr<system::IFile>> future;
28
+ m_system->createFile (future, m_defaultAbsolutePath / pathRelativeToArchive, system::IFile::ECF_READ);
29
+ if (auto file = future.acquire ())
30
+ return *file;
31
+ }
32
+
33
+ core::SRange<const IFileArchive::SListEntry> listAssets (const path& asset_path) const override
34
+ {
35
+ populateItemList (asset_path);
36
+ return IFileArchive::listAssets (asset_path);
37
+ }
38
+ virtual core::SRange<const SListEntry> listAssets () const override {
39
+ populateItemList (path ());
40
+ return IFileArchive::listAssets ();
41
+ }
42
+
43
+ void populateItemList (const path& p) const {
44
+ std::unique_lock lock (itemMutex);
45
+ auto items = m_system->listItemsInDirectory (m_defaultAbsolutePath/p);
46
+ m_items.clear ();
47
+
48
+ for (auto item : items)
49
+ {
50
+ if (item.has_extension ())
51
+ {
52
+ auto relpath = item.lexically_relative (m_defaultAbsolutePath);
53
+ auto entry = SListEntry{ relpath, 0xdeadbeefu , 0xdeadbeefu , 0xdeadbeefu , EAT_NONE };
54
+ m_items.push_back (entry);
55
+ }
56
+ }
57
+ lock.unlock ();
58
+ }
59
+ };
60
+
61
+ } // namespace nbl::system
0 commit comments