Skip to content

Commit 4243db2

Browse files
finalize what IFileArchive will look like
1 parent f9d4ec9 commit 4243db2

File tree

3 files changed

+55
-117
lines changed

3 files changed

+55
-117
lines changed

include/nbl/system/CArchiveLoaderTar.h

Lines changed: 0 additions & 91 deletions
This file was deleted.

include/nbl/system/IFileArchive.h

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class IFileArchive : public core::IReferenceCounted
2525
enum E_ALLOCATOR_TYPE
2626
{
2727
EAT_NONE = 0,
28-
EAT_NULL,
29-
EAT_VIRTUAL_ALLOC,
30-
EAT_MALLOC
28+
EAT_NULL, // read directly from archive's underlying mapped file
29+
EAT_VIRTUAL_ALLOC, // decompress to RAM (with sparse paging)
30+
EAT_MALLOC // decompress to RAM
3131
};
3232
//! An entry in a list of items, can be a folder or a file.
3333
struct SListEntry
@@ -38,13 +38,11 @@ class IFileArchive : public core::IReferenceCounted
3838
//! The size of the file in bytes
3939
size_t size;
4040

41-
//! The ID of the file in an archive
42-
/** This is used to link the FileList entry to extra info held about this
43-
file in an archive, which can hold things like data offset and CRC. */
44-
uint32_t ID;
45-
4641
//! FileOffset inside an archive
47-
uint32_t offset;
42+
size_t offset;
43+
44+
//! The ID of the file in an archive, it maps it to a memory pool entry for CFileView
45+
uint32_t ID;
4846

4947
// `EAT_NONE` for directories
5048
E_ALLOCATOR_TYPE allocatorType;
@@ -77,28 +75,17 @@ class IFileArchive : public core::IReferenceCounted
7775
protected:
7876
IFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger) :
7977
m_defaultAbsolutePath(std::move(_defaultAbsolutePath)), m_logger(std::move(logger)) {}
80-
/*
81-
virtual void addItem(const system::path& fullPath, uint32_t offset, uint32_t size, E_ALLOCATOR_TYPE allocatorType, uint32_t id = 0)
82-
{
83-
SFileListEntry entry;
84-
entry.ID = id ? id : m_items.size();
85-
entry.offset = offset;
86-
entry.size = size;
87-
entry.name = fullPath;
88-
entry.allocatorType = allocatorType;
89-
entry.fullName = entry.name;
90-
91-
core::deletePathFromFilename(entry.name);
9278

93-
m_items.insert(std::lower_bound(m_items.begin(), m_items.end(), entry), entry);
94-
}
95-
*/
96-
inline uint32_t getIndexFromPath(const system::path& pathRelativeToArchive) const
79+
inline const SListEntry* getItemFromPath(const system::path& pathRelativeToArchive) const
9780
{
9881
const IFileArchive::SListEntry itemToFind = { pathRelativeToArchive };
99-
return std::distance(m_items.begin(),std::lower_bound(m_items.begin(),m_items.end(),itemToFind));
82+
const auto found = std::lower_bound(m_items.begin(),m_items.end(),itemToFind);
83+
if (found!=m_items.end() || found->pathRelativeToArchive!=pathRelativeToArchive)
84+
return nullptr;
85+
return &(*found);
10086
}
10187

88+
std::mutex itemMutex; // TODO: update to readers writer lock
10289
path m_defaultAbsolutePath;
10390
// files and directories
10491
core::vector<SListEntry> m_items;

src/nbl/system/CArchiveLoaderTar.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef _NBL_SYSTEM_C_ARCHIVE_LOADER_TAR_H_INCLUDED_
2+
#define _NBL_SYSTEM_C_ARCHIVE_LOADER_TAR_H_INCLUDED_
3+
4+
5+
#include "nbl/system/CFileArchive.h"
6+
7+
8+
namespace nbl::system
9+
{
10+
11+
class CArchiveLoaderTar final : public IArchiveLoader
12+
{
13+
public:
14+
class CArchive : public CFileArchive
15+
{
16+
public:
17+
CArchive(core::smart_refctd_ptr<IFile>&& _file, system::logger_opt_smart_ptr&& logger, core::vector<SListEntry>&& _items) :
18+
CFileArchive(path(_file->getFileName()),std::move(logger),std::move(_items)), m_file(std::move(_file)) {}
19+
20+
//
21+
protected:
22+
core::smart_refctd_ptr<IFile> m_file;
23+
};
24+
25+
CArchiveLoaderTar(system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(logger)) {}
26+
virtual bool isALoadableFileFormat(IFile* file) const override
27+
{
28+
return !!createArchive_impl(core::smart_refctd_ptr<IFile>(file),"");
29+
}
30+
31+
const char** getAssociatedFileExtensions() const override
32+
{
33+
static const char* ext[]{ "tar", nullptr };
34+
return ext;
35+
}
36+
37+
private:
38+
core::smart_refctd_ptr<IFileArchive> createArchive_impl(core::smart_refctd_ptr<system::IFile>&& file, const std::string_view& password) const override;
39+
};
40+
41+
}
42+
#endif

0 commit comments

Comments
 (0)